src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java
author mbalao
Wed, 17 Jul 2019 12:26:56 -0300
changeset 57487 643978a35f6e
parent 55258 d65d3c37232c
child 58510 23a06a5eeddd
permissions -rw-r--r--
8227437: S4U2proxy cannot continue because server's TGT cannot be found Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    23
 * questions.
2
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  (C) Copyright IBM Corp. 1999 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  Copyright 1997 The Open Group Research Institute.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.PrincipalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.Checksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.krb5.Asn1Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.krb5.Realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.krb5.RealmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.math.BigInteger;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
    44
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Arrays;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
    46
import java.util.List;
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
    47
import sun.security.krb5.internal.util.KerberosString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Implements the ASN.1 KRBError type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    51
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * KRB-ERROR       ::= [APPLICATION 30] SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *         pvno            [0] INTEGER (5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *         msg-type        [1] INTEGER (30),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *         ctime           [2] KerberosTime OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *         cusec           [3] Microseconds OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *         stime           [4] KerberosTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *         susec           [5] Microseconds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *         error-code      [6] Int32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *         crealm          [7] Realm OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *         cname           [8] PrincipalName OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *         realm           [9] Realm -- service realm --,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *         sname           [10] PrincipalName -- service name --,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *         e-text          [11] KerberosString OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *         e-data          [12] OCTET STRING OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * METHOD-DATA     ::= SEQUENCE OF PA-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * TYPED-DATA      ::= SEQUENCE SIZE (1..MAX) OF SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *         data-type       [0] Int32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *         data-value      [1] OCTET STRING OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * }
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    74
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * This definition reflects the Network Working Group RFC 4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * specification available at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * http://www.ietf.org/rfc/rfc4120.txt</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
public class KRBError implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static final long serialVersionUID = 3643809337475284503L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private int pvno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private int msgType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private KerberosTime cTime; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private Integer cuSec; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private KerberosTime sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private Integer suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private int errorCode;
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
    93
    private Realm crealm; //optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private PrincipalName cname; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private PrincipalName sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private String eText; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private byte[] eData; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Checksum eCksum; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   100
    private PAData[] pa;    // PA-DATA in eData
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private void readObject(ObjectInputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            init(new DerValue((byte[])is.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new IOException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private void writeObject(ObjectOutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            os.writeObject(asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new IOException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public KRBError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    APOptions new_apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    KerberosTime new_cTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    Integer new_cuSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    KerberosTime new_sTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    Integer new_suSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    int new_errorCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    byte[] new_eData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        errorCode = new_errorCode;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 55258
diff changeset
   142
        crealm = new_cname != null ? new_cname.getRealm() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public KRBError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    APOptions new_apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    KerberosTime new_cTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    Integer new_cuSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    KerberosTime new_sTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    Integer new_suSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    int new_errorCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    byte[] new_eData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    Checksum new_eCksum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        errorCode = new_errorCode;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 55258
diff changeset
   171
        crealm = new_cname != null ? new_cname.getRealm() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        eCksum = new_eCksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public KRBError(byte[] data) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        init(new DerValue(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public KRBError(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        init(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        showDebug();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Attention:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * According to RFC 4120, e-data field in a KRB-ERROR message is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * a METHOD-DATA when errorCode is KDC_ERR_PREAUTH_REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * and application-specific otherwise (The RFC suggests using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * TYPED-DATA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Hence, the ideal procedure to parse e-data should look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * if (errorCode is KDC_ERR_PREAUTH_REQUIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *    parse as METHOD-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *    try parsing as TYPED-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Unfortunately, we know that some implementations also use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * METHOD-DATA format for errorcode KDC_ERR_PREAUTH_FAILED, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * do not use the TYPED-DATA for other errorcodes (say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * KDC_ERR_CLIENT_REVOKED).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    // parse the edata field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private void parseEData(byte[] data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // We need to parse eData as METHOD-DATA for both errorcodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (errorCode == Krb5.KDC_ERR_PREAUTH_REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                || errorCode == Krb5.KDC_ERR_PREAUTH_FAILED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // RFC 4120 does not guarantee that eData is METHOD-DATA when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // errorCode is KDC_ERR_PREAUTH_FAILED. Therefore, the parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // may fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                parsePAData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    System.out.println("Unable to parse eData field of KRB-ERROR:\n" +
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 32003
diff changeset
   233
                            new sun.security.util.HexDumpEncoder().encodeBuffer(data));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                IOException ioe = new IOException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        "Unable to parse eData field of KRB-ERROR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                ioe.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                System.out.println("Unknown eData field of KRB-ERROR:\n" +
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 32003
diff changeset
   243
                        new sun.security.util.HexDumpEncoder().encodeBuffer(data));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Try parsing the data as a sequence of PA-DATA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param data the data block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private void parsePAData(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        DerValue derPA = new DerValue(data);
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   255
        List<PAData> paList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        while (derPA.data.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // read the PA-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            DerValue tmp = derPA.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            PAData pa_data = new PAData(tmp);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   260
            paList.add(pa_data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (DEBUG) {
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 9035
diff changeset
   262
                System.out.println(pa_data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   265
        pa = paList.toArray(new PAData[paList.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   268
    public final Realm getClientRealm() {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   269
        return crealm;
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   270
    }
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   271
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public final KerberosTime getServerTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public final KerberosTime getClientTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public final Integer getServerMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public final Integer getClientMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public final int getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    // access pre-auth info
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   293
    public final PAData[] getPA() {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   294
        return pa;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public final String getErrorString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Initializes a KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param encoding a DER-encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @exception KrbApErrException if the value read from the DER-encoded data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *  stream does not match the pre-defined value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @exception RealmException if an error occurs while parsing a Realm object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private void init(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        DerValue der, subDer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (((encoding.getTag() & (byte)0x1F) != (byte)0x1E)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                || (encoding.isApplication() != true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                || (encoding.isConstructed() != true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        der = encoding.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (der.getTag() != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            pvno = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if (pvno != Krb5.PVNO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            msgType = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (msgType != Krb5.KRB_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        cTime = KerberosTime.parse(der.getData(), (byte)0x02, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if ((der.getData().peekByte() & 0x1F) == 0x03) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            subDer = der.getData().getDerValue();
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   345
            cuSec = subDer.getData().getBigInteger().intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        else cuSec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        sTime = KerberosTime.parse(der.getData(), (byte)0x04, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x05) {
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   351
            suSec = subDer.getData().getBigInteger().intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x06) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            errorCode = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   359
        crealm = Realm.parse(der.getData(), (byte)0x07, true);
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   360
        cname = PrincipalName.parse(der.getData(), (byte)0x08, true, crealm);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   361
        Realm realm = Realm.parse(der.getData(), (byte)0x09, false);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   362
        sname = PrincipalName.parse(der.getData(), (byte)0x0A, false, realm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        eText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        eData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        eCksum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if ((der.getData().peekByte() & 0x1F) == 0x0B) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                subDer = der.getData().getDerValue();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   369
                eText = new KerberosString(subDer.getData().getDerValue())
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   370
                        .toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if ((der.getData().peekByte() & 0x1F) == 0x0C) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                eData = subDer.getData().getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            eCksum = Checksum.parse(der.getData(), (byte)0x0D, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (der.getData().available() >0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * For debug use only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    private void showDebug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            System.out.println(">>>KRBError:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (cTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                System.out.println("\t cTime is " + cTime.toDate().toString() + " " + cTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                System.out.println("\t cuSec is " + cuSec.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            System.out.println("\t sTime is " + sTime.toDate().toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                               () + " " + sTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            System.out.println("\t suSec is " + suSec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            System.out.println("\t error code is " + errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            System.out.println("\t error Message is " + Krb5.getErrorMessage(errorCode));
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   403
            if (crealm != null) {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   404
                System.out.println("\t crealm is " + crealm.toString());
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   405
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                System.out.println("\t cname is " + cname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (sname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                System.out.println("\t sname is " + sname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                System.out.println("\t eData provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                System.out.println("\t checksum provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            System.out.println("\t msgType is " + msgType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Encodes an KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return the byte array of encoded KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public byte[] asn1Encode() throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        DerOutputStream temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        temp.putInteger(BigInteger.valueOf(pvno));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        temp.putInteger(BigInteger.valueOf(msgType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (cTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            temp.putInteger(BigInteger.valueOf(cuSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        temp.putInteger(BigInteger.valueOf(suSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        temp.putInteger(BigInteger.valueOf(errorCode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   455
        if (crealm != null) {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   456
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), crealm.asn1Encode());
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   457
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), cname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   462
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.getRealm().asn1Encode());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (eText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            temp = new DerOutputStream();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   467
            temp.putDerValue(new KerberosString(eText).toDerValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            temp.putOctetString(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0C), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0D), eCksum.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        temp.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1E), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return bytes.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    @Override public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (!(obj instanceof KRBError)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        KRBError other = (KRBError)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return  pvno == other.pvno &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                msgType == other.msgType &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                isEqual(cTime, other.cTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                isEqual(cuSec, other.cuSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                isEqual(sTime, other.sTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                isEqual(suSec, other.suSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                errorCode == other.errorCode &&
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   503
                isEqual(crealm, other.crealm) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                isEqual(cname, other.cname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                isEqual(sname, other.sname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                isEqual(eText, other.eText) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                java.util.Arrays.equals(eData, other.eData) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                isEqual(eCksum, other.eCksum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    private static boolean isEqual(Object a, Object b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return (a == null)?(b == null):(a.equals(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    @Override public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        result = 37 * result + pvno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        result = 37 * result + msgType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (cTime != null) result = 37 * result + cTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (cuSec != null) result = 37 * result + cuSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (sTime != null) result = 37 * result + sTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (suSec != null) result = 37 * result + suSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        result = 37 * result + errorCode;
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   524
        if (crealm != null) result = 37 * result + crealm.hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (cname != null) result = 37 * result + cname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (sname != null) result = 37 * result + sname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (eText != null) result = 37 * result + eText.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        result = 37 * result + Arrays.hashCode(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        if (eCksum != null) result = 37 * result + eCksum.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
}