src/java.security.jgss/share/classes/sun/security/krb5/internal/Authenticator.java
author mbalao
Wed, 05 Jun 2019 01:42:11 -0300
changeset 55258 d65d3c37232c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215032: Support Kerberos cross-realm referrals (RFC 6806) Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 73
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 73
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 73
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 73
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 73
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.krb5.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.math.BigInteger;
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    37
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Implements the ASN.1 Authenticator type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 31538
diff changeset
    41
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Authenticator   ::= [APPLICATION 2] SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *         authenticator-vno       [0] INTEGER (5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *         crealm                  [1] Realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *         cname                   [2] PrincipalName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *         cksum                   [3] Checksum OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *         cusec                   [4] Microseconds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *         ctime                   [5] KerberosTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *         subkey                  [6] EncryptionKey OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *         seq-number              [7] UInt32 OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *         authorization-data      [8] AuthorizationData OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * }
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 31538
diff changeset
    53
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This definition reflects the Network Working Group RFC 4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * specification available at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * http://www.ietf.org/rfc/rfc4120.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class Authenticator {
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public int authenticator_vno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public PrincipalName cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    Checksum cksum; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public int cusec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public KerberosTime ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    EncryptionKey subKey; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    Integer seqNumber; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public AuthorizationData authorizationData; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    72
    public Authenticator(
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    73
            PrincipalName new_cname,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    74
            Checksum new_cksum,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    75
            int new_cusec,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    76
            KerberosTime new_ctime,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    77
            EncryptionKey new_subKey,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    78
            Integer new_seqNumber,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    79
            AuthorizationData new_authorizationData) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    80
        authenticator_vno = Krb5.AUTHNETICATOR_VNO;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    81
        cname = new_cname;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    82
        cksum = new_cksum;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    83
        cusec = new_cusec;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    84
        ctime = new_ctime;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    85
        subKey = new_subKey;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    86
        seqNumber = new_seqNumber;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    87
        authorizationData = new_authorizationData;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    88
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    90
    public Authenticator(byte[] data)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    91
            throws Asn1Exception, IOException, KrbApErrException, RealmException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    92
        init(new DerValue(data));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    93
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    95
    public Authenticator(DerValue encoding)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    96
            throws Asn1Exception, IOException, KrbApErrException, RealmException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    97
        init(encoding);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    98
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   100
    /**
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   101
     * Initializes an Authenticator object.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   102
     * @param encoding a single DER-encoded value.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   103
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   104
     * @exception IOException if an I/O error occurs while reading encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   105
     * @exception KrbApErrException if the value read from the DER-encoded data
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   106
     *  stream does not match the pre-defined value.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   107
     * @exception RealmException if an error occurs while parsing a Realm object.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   108
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   109
    private void init(DerValue encoding)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   110
            throws Asn1Exception, IOException, KrbApErrException, RealmException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   111
        DerValue der, subDer;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   112
        //may not be the correct error code for a tag
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   113
        //mismatch on an encrypted structure
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   114
        if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x02)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   115
                || (encoding.isApplication() != true)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   116
                || (encoding.isConstructed() != true)) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   117
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   118
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   119
        der = encoding.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   120
        if (der.getTag() != DerValue.tag_Sequence) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   121
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   122
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   123
        subDer = der.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   124
        if ((subDer.getTag() & (byte) 0x1F) != (byte) 0x00) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   126
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        authenticator_vno = subDer.getData().getBigInteger().intValue();
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   128
        if (authenticator_vno != 5) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   130
        }
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7977
diff changeset
   131
        Realm crealm = Realm.parse(der.getData(), (byte) 0x01, false);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7977
diff changeset
   132
        cname = PrincipalName.parse(der.getData(), (byte) 0x02, false, crealm);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   133
        cksum = Checksum.parse(der.getData(), (byte) 0x03, true);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   134
        subDer = der.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   135
        if ((subDer.getTag() & (byte) 0x1F) == 0x04) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   136
            cusec = subDer.getData().getBigInteger().intValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   137
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   138
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   139
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   140
        ctime = KerberosTime.parse(der.getData(), (byte) 0x05, false);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   141
        if (der.getData().available() > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   142
            subKey = EncryptionKey.parse(der.getData(), (byte) 0x06, true);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   143
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   144
            subKey = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   145
            seqNumber = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   146
            authorizationData = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   147
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   148
        if (der.getData().available() > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   149
            if ((der.getData().peekByte() & 0x1F) == 0x07) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                subDer = der.getData().getDerValue();
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   151
                if ((subDer.getTag() & (byte) 0x1F) == (byte) 0x07) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 13247
diff changeset
   152
                    seqNumber = subDer.getData().getBigInteger().intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   154
            }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   155
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   156
            seqNumber = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   157
            authorizationData = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   159
        if (der.getData().available() > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   160
            authorizationData = AuthorizationData.parse(der.getData(), (byte) 0x08, true);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   161
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   162
            authorizationData = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   163
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   164
        if (der.getData().available() > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   165
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   166
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   167
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   169
    /**
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   170
     * Encodes an Authenticator object.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   171
     * @return byte array of encoded Authenticator object.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   172
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   173
     * @exception IOException if an I/O error occurs while reading encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   174
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   175
    public byte[] asn1Encode() throws Asn1Exception, IOException {
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 5506
diff changeset
   176
        Vector<DerValue> v = new Vector<>();
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   177
        DerOutputStream temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   178
        temp.putInteger(BigInteger.valueOf(authenticator_vno));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   179
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp.toByteArray()));
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7977
diff changeset
   180
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), cname.getRealm().asn1Encode()));
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   181
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x02), cname.asn1Encode()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   182
        if (cksum != null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   183
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x03), cksum.asn1Encode()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   185
        temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   186
        temp.putInteger(BigInteger.valueOf(cusec));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   187
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x04), temp.toByteArray()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   188
        v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x05), ctime.asn1Encode()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   189
        if (subKey != null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   190
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x06), subKey.asn1Encode()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   191
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   192
        if (seqNumber != null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   193
            temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   194
            // encode as an unsigned integer (UInt32)
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   195
            temp.putInteger(BigInteger.valueOf(seqNumber.longValue()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   196
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x07), temp.toByteArray()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   197
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   198
        if (authorizationData != null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   199
            v.addElement(new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x08), authorizationData.asn1Encode()));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   200
        }
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 25859
diff changeset
   201
        DerValue[] der = new DerValue[v.size()];
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   202
        v.copyInto(der);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   203
        temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   204
        temp.putSequence(der);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   205
        DerOutputStream out = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   206
        out.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte) 0x02), temp);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   207
        return out.toByteArray();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   208
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public final Checksum getChecksum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return cksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public final Integer getSeqNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return seqNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public final EncryptionKey getSubKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return subKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}