src/java.security.jgss/share/classes/sun/security/krb5/internal/KRBError.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58510 23a06a5eeddd
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
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
 */
58510
23a06a5eeddd 8231368: Suppress warnings on non-serializable non-transient instance fields in java.security.jgss
darcy
parents: 57487
diff changeset
    82
// The instance fields not statically typed as Serializable are ASN.1
23a06a5eeddd 8231368: Suppress warnings on non-serializable non-transient instance fields in java.security.jgss
darcy
parents: 57487
diff changeset
    83
// encoded and written by the writeObject method.
23a06a5eeddd 8231368: Suppress warnings on non-serializable non-transient instance fields in java.security.jgss
darcy
parents: 57487
diff changeset
    84
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class KRBError implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static final long serialVersionUID = 3643809337475284503L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private int pvno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private int msgType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private KerberosTime cTime; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private Integer cuSec; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private KerberosTime sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private Integer suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private int errorCode;
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
    95
    private Realm crealm; //optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private PrincipalName cname; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private PrincipalName sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private String eText; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private byte[] eData; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private Checksum eCksum; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   102
    private PAData[] pa;    // PA-DATA in eData
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private void readObject(ObjectInputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            init(new DerValue((byte[])is.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new IOException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private void writeObject(ObjectOutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            os.writeObject(asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new IOException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public KRBError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    APOptions new_apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    KerberosTime new_cTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    Integer new_cuSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    KerberosTime new_sTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    Integer new_suSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    int new_errorCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    byte[] new_eData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        errorCode = new_errorCode;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 55258
diff changeset
   144
        crealm = new_cname != null ? new_cname.getRealm() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public KRBError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    APOptions new_apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    KerberosTime new_cTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    Integer new_cuSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    KerberosTime new_sTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    Integer new_suSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    int new_errorCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    byte[] new_eData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    Checksum new_eCksum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        errorCode = new_errorCode;
57487
643978a35f6e 8227437: S4U2proxy cannot continue because server's TGT cannot be found
mbalao
parents: 55258
diff changeset
   173
        crealm = new_cname != null ? new_cname.getRealm() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        eCksum = new_eCksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public KRBError(byte[] data) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        init(new DerValue(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public KRBError(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        init(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        showDebug();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Attention:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * According to RFC 4120, e-data field in a KRB-ERROR message is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * a METHOD-DATA when errorCode is KDC_ERR_PREAUTH_REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * and application-specific otherwise (The RFC suggests using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * TYPED-DATA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Hence, the ideal procedure to parse e-data should look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * if (errorCode is KDC_ERR_PREAUTH_REQUIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *    parse as METHOD-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *    try parsing as TYPED-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Unfortunately, we know that some implementations also use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * METHOD-DATA format for errorcode KDC_ERR_PREAUTH_FAILED, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * do not use the TYPED-DATA for other errorcodes (say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * KDC_ERR_CLIENT_REVOKED).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    // parse the edata field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private void parseEData(byte[] data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // We need to parse eData as METHOD-DATA for both errorcodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (errorCode == Krb5.KDC_ERR_PREAUTH_REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                || errorCode == Krb5.KDC_ERR_PREAUTH_FAILED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // RFC 4120 does not guarantee that eData is METHOD-DATA when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // errorCode is KDC_ERR_PREAUTH_FAILED. Therefore, the parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // may fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                parsePAData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    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
   235
                            new sun.security.util.HexDumpEncoder().encodeBuffer(data));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                IOException ioe = new IOException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        "Unable to parse eData field of KRB-ERROR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                ioe.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                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
   245
                        new sun.security.util.HexDumpEncoder().encodeBuffer(data));
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Try parsing the data as a sequence of PA-DATA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param data the data block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private void parsePAData(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        DerValue derPA = new DerValue(data);
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   257
        List<PAData> paList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        while (derPA.data.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // read the PA-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            DerValue tmp = derPA.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            PAData pa_data = new PAData(tmp);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   262
            paList.add(pa_data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (DEBUG) {
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 9035
diff changeset
   264
                System.out.println(pa_data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   267
        pa = paList.toArray(new PAData[paList.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   270
    public final Realm getClientRealm() {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   271
        return crealm;
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   272
    }
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   273
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public final KerberosTime getServerTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public final KerberosTime getClientTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public final Integer getServerMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public final Integer getClientMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public final int getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    // access pre-auth info
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   295
    public final PAData[] getPA() {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   296
        return pa;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public final String getErrorString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Initializes a KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param encoding a DER-encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @exception KrbApErrException if the value read from the DER-encoded data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *  stream does not match the pre-defined value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @exception RealmException if an error occurs while parsing a Realm object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private void init(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        DerValue der, subDer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (((encoding.getTag() & (byte)0x1F) != (byte)0x1E)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                || (encoding.isApplication() != true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                || (encoding.isConstructed() != true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        der = encoding.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (der.getTag() != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            pvno = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (pvno != Krb5.PVNO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            msgType = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (msgType != Krb5.KRB_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        cTime = KerberosTime.parse(der.getData(), (byte)0x02, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if ((der.getData().peekByte() & 0x1F) == 0x03) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            subDer = der.getData().getDerValue();
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 14342
diff changeset
   347
            cuSec = subDer.getData().getBigInteger().intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        else cuSec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        sTime = KerberosTime.parse(der.getData(), (byte)0x04, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        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
   353
            suSec = subDer.getData().getBigInteger().intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x06) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            errorCode = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   361
        crealm = Realm.parse(der.getData(), (byte)0x07, true);
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   362
        cname = PrincipalName.parse(der.getData(), (byte)0x08, true, crealm);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   363
        Realm realm = Realm.parse(der.getData(), (byte)0x09, false);
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   364
        sname = PrincipalName.parse(der.getData(), (byte)0x0A, false, realm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        eText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        eData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        eCksum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if ((der.getData().peekByte() & 0x1F) == 0x0B) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                subDer = der.getData().getDerValue();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   371
                eText = new KerberosString(subDer.getData().getDerValue())
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   372
                        .toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if ((der.getData().peekByte() & 0x1F) == 0x0C) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                eData = subDer.getData().getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            eCksum = Checksum.parse(der.getData(), (byte)0x0D, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (der.getData().available() >0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * For debug use only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private void showDebug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            System.out.println(">>>KRBError:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (cTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                System.out.println("\t cTime is " + cTime.toDate().toString() + " " + cTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                System.out.println("\t cuSec is " + cuSec.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            System.out.println("\t sTime is " + sTime.toDate().toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                               () + " " + sTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            System.out.println("\t suSec is " + suSec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            System.out.println("\t error code is " + errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            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
   405
            if (crealm != null) {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   406
                System.out.println("\t crealm is " + crealm.toString());
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   407
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                System.out.println("\t cname is " + cname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (sname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                System.out.println("\t sname is " + sname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                System.out.println("\t eData provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                System.out.println("\t checksum provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            System.out.println("\t msgType is " + msgType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Encodes an KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @return the byte array of encoded KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public byte[] asn1Encode() throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        DerOutputStream temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        temp.putInteger(BigInteger.valueOf(pvno));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        temp.putInteger(BigInteger.valueOf(msgType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (cTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            temp.putInteger(BigInteger.valueOf(cuSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        temp.putInteger(BigInteger.valueOf(suSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        temp.putInteger(BigInteger.valueOf(errorCode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   457
        if (crealm != null) {
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   458
            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
   459
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), cname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 10432
diff changeset
   464
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), sname.getRealm().asn1Encode());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (eText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            temp = new DerOutputStream();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   469
            temp.putDerValue(new KerberosString(eText).toDerValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            temp.putOctetString(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0C), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0D), eCksum.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        temp.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1E), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return bytes.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    @Override public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (!(obj instanceof KRBError)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        KRBError other = (KRBError)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return  pvno == other.pvno &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                msgType == other.msgType &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                isEqual(cTime, other.cTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                isEqual(cuSec, other.cuSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                isEqual(sTime, other.sTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                isEqual(suSec, other.suSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                errorCode == other.errorCode &&
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   505
                isEqual(crealm, other.crealm) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                isEqual(cname, other.cname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                isEqual(sname, other.sname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                isEqual(eText, other.eText) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                java.util.Arrays.equals(eData, other.eData) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                isEqual(eCksum, other.eCksum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    private static boolean isEqual(Object a, Object b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return (a == null)?(b == null):(a.equals(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    @Override public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        result = 37 * result + pvno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        result = 37 * result + msgType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (cTime != null) result = 37 * result + cTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (cuSec != null) result = 37 * result + cuSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (sTime != null) result = 37 * result + sTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if (suSec != null) result = 37 * result + suSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        result = 37 * result + errorCode;
55258
d65d3c37232c 8215032: Support Kerberos cross-realm referrals (RFC 6806)
mbalao
parents: 47216
diff changeset
   526
        if (crealm != null) result = 37 * result + crealm.hashCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (cname != null) result = 37 * result + cname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (sname != null) result = 37 * result + sname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        if (eText != null) result = 37 * result + eText.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        result = 37 * result + Arrays.hashCode(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (eCksum != null) result = 37 * result + eCksum.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
}