Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAEncTSEnc.java
41161 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25*26* (C) Copyright IBM Corp. 1999 All Rights Reserved.27* Copyright 1997 The Open Group Research Institute. All rights reserved.28*/2930package sun.security.krb5.internal;3132import sun.security.util.*;33import sun.security.krb5.Asn1Exception;34import java.io.IOException;35import java.math.BigInteger;3637/**38* Implements the ASN.1 PAEncTSEnc type.39*40* <pre>{@code41* PA-ENC-TS-ENC ::= SEQUENCE {42* patimestamp [0] KerberosTime -- client's time --,43* pausec [1] Microseconds OPTIONAL44* }45* }</pre>46*47* <p>48* This definition reflects the Network Working Group RFC 412049* specification available at50* <a href="http://www.ietf.org/rfc/rfc4120.txt">51* http://www.ietf.org/rfc/rfc4120.txt</a>.52*/5354public class PAEncTSEnc {55public KerberosTime pATimeStamp;56public Integer pAUSec; //optional5758public PAEncTSEnc(59KerberosTime new_pATimeStamp,60Integer new_pAUSec61) {62pATimeStamp = new_pATimeStamp;63pAUSec = new_pAUSec;64}6566public PAEncTSEnc() {67KerberosTime now = KerberosTime.now();68pATimeStamp = now;69pAUSec = now.getMicroSeconds();70}7172/**73* Constructs a PAEncTSEnc object.74* @param encoding a Der-encoded data.75* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.76* @exception IOException if an I/O error occurs while reading encoded data.77*/78public PAEncTSEnc(DerValue encoding) throws Asn1Exception, IOException {79DerValue der;80if (encoding.getTag() != DerValue.tag_Sequence) {81throw new Asn1Exception(Krb5.ASN1_BAD_ID);82}83pATimeStamp = KerberosTime.parse(encoding.getData(), (byte)0x00, false);84if (encoding.getData().available() > 0) {85der = encoding.getData().getDerValue();86if ((der.getTag() & 0x1F) == 0x01) {87pAUSec = der.getData().getBigInteger().intValue();88}89else throw new Asn1Exception(Krb5.ASN1_BAD_ID);90}91if (encoding.getData().available() > 0)92throw new Asn1Exception(Krb5.ASN1_BAD_ID);93}949596/**97* Encodes a PAEncTSEnc object.98* @return the byte array of encoded PAEncTSEnc object.99* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.100* @exception IOException if an I/O error occurs while reading encoded data.101*/102public byte[] asn1Encode() throws Asn1Exception, IOException {103DerOutputStream bytes = new DerOutputStream();104DerOutputStream temp = new DerOutputStream();105bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), pATimeStamp.asn1Encode());106if (pAUSec != null) {107temp = new DerOutputStream();108temp.putInteger(BigInteger.valueOf(pAUSec.intValue()));109bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);110}111temp = new DerOutputStream();112temp.write(DerValue.tag_Sequence, bytes);113return temp.toByteArray();114}115}116117118