src/java.security.jgss/share/classes/sun/security/krb5/internal/KDCRep.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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.security.krb5.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.*;
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 KDC-REP type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    41
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * KDC-REP         ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *         pvno            [0] INTEGER (5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *         msg-type        [1] INTEGER (11 -- AS -- | 13 -- TGS --),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *         padata          [2] SEQUENCE OF PA-DATA OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *                                   -- NOTE: not empty --,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *         crealm          [3] Realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *         cname           [4] PrincipalName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *         ticket          [5] Ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *         enc-part        [6] EncryptedData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *                                   -- EncASRepPart or EncTGSRepPart,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *                                   -- as appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * }
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    54
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * This definition reflects the Network Working Group RFC 4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * specification available at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * http://www.ietf.org/rfc/rfc4120.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    62
public class KDCRep {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    64
    public PrincipalName cname;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    65
    public Ticket ticket;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    66
    public EncryptedData encPart;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    67
    public EncKDCRepPart encKDCRepPart; //not part of ASN.1 encoding
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    68
    private int pvno;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    69
    private int msgType;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5506
diff changeset
    70
    public PAData[] pAData = null; //optional
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    71
    private boolean DEBUG = Krb5.DEBUG;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    73
    public KDCRep(
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    74
            PAData[] new_pAData,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    75
            PrincipalName new_cname,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    76
            Ticket new_ticket,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    77
            EncryptedData new_encPart,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    78
            int req_type) throws IOException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    79
        pvno = Krb5.PVNO;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    80
        msgType = req_type;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    81
        if (new_pAData != null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    82
            pAData = new PAData[new_pAData.length];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    83
            for (int i = 0; i < new_pAData.length; i++) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    84
                if (new_pAData[i] == null) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    85
                    throw new IOException("Cannot create a KDCRep");
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    86
                } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    87
                    pAData[i] = (PAData) new_pAData[i].clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    89
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    91
        cname = new_cname;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    92
        ticket = new_ticket;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    93
        encPart = new_encPart;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    94
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    96
    public KDCRep() {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    97
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
    99
    public KDCRep(byte[] data, int req_type) throws Asn1Exception,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   100
            KrbApErrException, RealmException, IOException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   101
        init(new DerValue(data), req_type);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   102
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   103
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   104
    public KDCRep(DerValue encoding, int req_type) throws Asn1Exception,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   105
            RealmException, KrbApErrException, IOException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   106
        init(encoding, req_type);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   107
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // Not used? Don't know what keyusage to use here %%%
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   111
    public void decrypt(EncryptionKey key) throws Asn1Exception,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   112
            IOException, KrbException, RealmException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   113
        encKDCRepPart = new EncKDCRepPart(encPart.decrypt(key), msgType);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   114
    }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   115
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   116
    /**
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   117
     * Initializes an KDCRep object.
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
     * @param encoding a single DER-encoded value.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   120
     * @param req_type reply message type.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   121
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   122
     * @exception IOException if an I/O error occurs while reading encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   123
     * @exception RealmException if an error occurs while constructing
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   124
     * a Realm object from DER-encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   125
     * @exception KrbApErrException if the value read from the DER-encoded
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   126
     * data stream does not match the pre-defined value.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   127
     *
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   128
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   129
    protected void init(DerValue encoding, int req_type)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throws Asn1Exception, RealmException, IOException,
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   131
            KrbApErrException {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   132
        DerValue der, subDer;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   133
        if ((encoding.getTag() & 0x1F) != req_type) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   134
            if (DEBUG) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   135
                System.out.println(">>> KDCRep: init() " +
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   136
                        "encoding tag is " +
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   137
                        encoding.getTag() +
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   138
                        " req type is " + req_type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   140
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   141
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   142
        der = encoding.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   143
        if (der.getTag() != DerValue.tag_Sequence) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   144
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   145
        }
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   146
        subDer = der.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   147
        if ((subDer.getTag() & 0x1F) == 0x00) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   148
            pvno = subDer.getData().getBigInteger().intValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   149
            if (pvno != Krb5.PVNO) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   150
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   152
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   153
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
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
        subDer = der.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   156
        if ((subDer.getTag() & 0x1F) == 0x01) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   157
            msgType = subDer.getData().getBigInteger().intValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   158
            if (msgType != req_type) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   159
                throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
73
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
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
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().peekByte() & 0x1F) == 0x02) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   165
            subDer = der.getData().getDerValue();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   166
            DerValue[] padata = subDer.getData().getSequence(1);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   167
            pAData = new PAData[padata.length];
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   168
            for (int i = 0; i < padata.length; i++) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   169
                pAData[i] = new PAData(padata[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   171
        } else {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   172
            pAData = null;
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   173
        }
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7183
diff changeset
   174
        Realm crealm = Realm.parse(der.getData(), (byte) 0x03, false);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7183
diff changeset
   175
        cname = PrincipalName.parse(der.getData(), (byte) 0x04, false, crealm);
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   176
        ticket = Ticket.parse(der.getData(), (byte) 0x05, false);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   177
        encPart = EncryptedData.parse(der.getData(), (byte) 0x06, false);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   178
        if (der.getData().available() > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   179
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   181
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   183
    /**
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   184
     * Encodes this object to a byte array.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   185
     * @return byte array of encoded APReq object.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   186
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   187
     * @exception IOException if an I/O error occurs while reading encoded data.
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   188
     *
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   189
     */
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   190
    public byte[] asn1Encode() throws Asn1Exception, IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   192
        DerOutputStream bytes = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   193
        DerOutputStream temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   194
        temp.putInteger(BigInteger.valueOf(pvno));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   195
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   196
                true, (byte) 0x00), temp);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   197
        temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   198
        temp.putInteger(BigInteger.valueOf(msgType));
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   199
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   200
                true, (byte) 0x01), temp);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   201
        if (pAData != null && pAData.length > 0) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   202
            DerOutputStream padata_stream = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   203
            for (int i = 0; i < pAData.length; i++) {
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   204
                padata_stream.write(pAData[i].asn1Encode());
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   205
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            temp = new DerOutputStream();
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   207
            temp.write(DerValue.tag_SequenceOf, padata_stream);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   208
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   209
                    true, (byte) 0x02), temp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   211
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 7183
diff changeset
   212
                true, (byte) 0x03), cname.getRealm().asn1Encode());
73
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   213
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   214
                true, (byte) 0x04), cname.asn1Encode());
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   215
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   216
                true, (byte) 0x05), ticket.asn1Encode());
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   217
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT,
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   218
                true, (byte) 0x06), encPart.asn1Encode());
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   219
        temp = new DerOutputStream();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   220
        temp.write(DerValue.tag_Sequence, bytes);
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   221
        return temp.toByteArray();
cf334423502b 6641312: Fix krb5 codes indentation problems
weijun
parents: 2
diff changeset
   222
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
}