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