jdk/src/share/classes/sun/security/krb5/internal/KRBError.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7977 f47f211cd627
child 10432 ef33e56c55a9
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7977
diff changeset
     2
 * Copyright (c) 2000, 2011, 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 Realm crealm; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private PrincipalName cname; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private Realm realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private PrincipalName sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private String eText; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private byte[] eData; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private Checksum eCksum; //optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   101
    private PAData[] pa;    // PA-DATA in eData
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   102
    private int pa_eType;   // The 1st etype appeared in salt-related PAData
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
                    Realm new_crealm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    Realm new_realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    byte[] new_eData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        errorCode = new_errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        crealm =  new_crealm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        realm = new_realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public KRBError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    APOptions new_apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    KerberosTime new_cTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    Integer new_cuSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    KerberosTime new_sTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    Integer new_suSec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    int new_errorCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    Realm new_crealm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    PrincipalName new_cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    Realm new_realm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    PrincipalName new_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    String new_eText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    byte[] new_eData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    Checksum new_eCksum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                        ) throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        pvno = Krb5.PVNO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        msgType = Krb5.KRB_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        cTime = new_cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        cuSec = new_cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        sTime = new_sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        suSec = new_suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        errorCode = new_errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        crealm =  new_crealm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        cname = new_cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        realm = new_realm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        sname = new_sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        eText = new_eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        eData = new_eData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        eCksum = new_eCksum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
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(byte[] data) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        init(new DerValue(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public KRBError(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        init(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        showDebug();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        parseEData(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Attention:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * According to RFC 4120, e-data field in a KRB-ERROR message is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * a METHOD-DATA when errorCode is KDC_ERR_PREAUTH_REQUIRED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * and application-specific otherwise (The RFC suggests using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * TYPED-DATA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Hence, the ideal procedure to parse e-data should look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * if (errorCode is KDC_ERR_PREAUTH_REQUIRED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *    parse as METHOD-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *    try parsing as TYPED-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Unfortunately, we know that some implementations also use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * METHOD-DATA format for errorcode KDC_ERR_PREAUTH_FAILED, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * do not use the TYPED-DATA for other errorcodes (say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * KDC_ERR_CLIENT_REVOKED).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // parse the edata field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    private void parseEData(byte[] data) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // We need to parse eData as METHOD-DATA for both errorcodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (errorCode == Krb5.KDC_ERR_PREAUTH_REQUIRED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                || errorCode == Krb5.KDC_ERR_PREAUTH_FAILED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                // RFC 4120 does not guarantee that eData is METHOD-DATA when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                // errorCode is KDC_ERR_PREAUTH_FAILED. Therefore, the parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                // may fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                parsePAData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    System.out.println("Unable to parse eData field of KRB-ERROR:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                            new sun.misc.HexDumpEncoder().encodeBuffer(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                IOException ioe = new IOException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        "Unable to parse eData field of KRB-ERROR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                ioe.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                System.out.println("Unknown eData field of KRB-ERROR:\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        new sun.misc.HexDumpEncoder().encodeBuffer(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Try parsing the data as a sequence of PA-DATA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param data the data block
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private void parsePAData(byte[] data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            throws IOException, Asn1Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        DerValue derPA = new DerValue(data);
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   263
        List<PAData> paList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        while (derPA.data.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // read the PA-DATA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            DerValue tmp = derPA.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            PAData pa_data = new PAData(tmp);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   268
            paList.add(pa_data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            int pa_type = pa_data.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            byte[] pa_value = pa_data.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                System.out.println(">>>Pre-Authentication Data:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                System.out.println("\t PA-DATA type = " + pa_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            switch(pa_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                case Krb5.PA_ENC_TIMESTAMP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        System.out.println("\t PA-ENC-TIMESTAMP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                case Krb5.PA_ETYPE_INFO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if (pa_value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        DerValue der = new DerValue(pa_value);
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   285
                        while (der.data.available() > 0) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   286
                            DerValue value = der.data.getDerValue();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   287
                            ETypeInfo info = new ETypeInfo(value);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   288
                            if (pa_eType == 0) pa_eType = info.getEType();
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   289
                            if (DEBUG) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   290
                                System.out.println("\t PA-ETYPE-INFO etype = " + info.getEType());
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   291
                                System.out.println("\t PA-ETYPE-INFO salt = " + info.getSalt());
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   292
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                case Krb5.PA_ETYPE_INFO2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    if (pa_value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        DerValue der = new DerValue(pa_value);
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   299
                        while (der.data.available() > 0) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   300
                            DerValue value = der.data.getDerValue();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   301
                            ETypeInfo2 info2 = new ETypeInfo2(value);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   302
                            if (pa_eType == 0) pa_eType = info2.getEType();
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   303
                            if (DEBUG) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   304
                                System.out.println("\t PA-ETYPE-INFO2 etype = " + info2.getEType());
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   305
                                System.out.println("\t PA-ETYPE-INFO2 salt = " + info2.getSalt());
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5506
diff changeset
   306
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    // Unknown Pre-auth type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   315
        pa = paList.toArray(new PAData[paList.size()]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public final KerberosTime getServerTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return sTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public final KerberosTime getClientTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return cTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public final Integer getServerMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return suSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public final Integer getClientMicroSeconds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return cuSec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public final int getErrorCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    // access pre-auth info
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   339
    public final PAData[] getPA() {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   340
        return pa;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   343
    public final int getEType() {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 5802
diff changeset
   344
        return pa_eType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public final String getErrorString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Initializes a KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param encoding a DER-encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @exception KrbApErrException if the value read from the DER-encoded data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *  stream does not match the pre-defined value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @exception RealmException if an error occurs while parsing a Realm object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    private void init(DerValue encoding) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            RealmException, KrbApErrException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        DerValue der, subDer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (((encoding.getTag() & (byte)0x1F) != (byte)0x1E)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                || (encoding.isApplication() != true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                || (encoding.isConstructed() != true)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        der = encoding.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (der.getTag() != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            pvno = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (pvno != Krb5.PVNO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x01) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            msgType = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            if (msgType != Krb5.KRB_ERROR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        cTime = KerberosTime.parse(der.getData(), (byte)0x02, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if ((der.getData().peekByte() & 0x1F) == 0x03) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            cuSec = new Integer(subDer.getData().getBigInteger().intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        else cuSec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        sTime = KerberosTime.parse(der.getData(), (byte)0x04, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x05) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            suSec = new Integer (subDer.getData().getBigInteger().intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if ((subDer.getTag() & (byte)0x1F) == (byte)0x06) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            errorCode = subDer.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        else  throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        crealm = Realm.parse(der.getData(), (byte)0x07, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        cname = PrincipalName.parse(der.getData(), (byte)0x08, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        realm = Realm.parse(der.getData(), (byte)0x09, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        sname = PrincipalName.parse(der.getData(), (byte)0x0A, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        eText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        eData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        eCksum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            if ((der.getData().peekByte() & 0x1F) == 0x0B) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                subDer = der.getData().getDerValue();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   419
                eText = new KerberosString(subDer.getData().getDerValue())
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   420
                        .toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if ((der.getData().peekByte() & 0x1F) == 0x0C) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                subDer = der.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                eData = subDer.getData().getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (der.getData().available() >0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            eCksum = Checksum.parse(der.getData(), (byte)0x0D, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (der.getData().available() >0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * For debug use only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private void showDebug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            System.out.println(">>>KRBError:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (cTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                System.out.println("\t cTime is " + cTime.toDate().toString() + " " + cTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                System.out.println("\t cuSec is " + cuSec.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            System.out.println("\t sTime is " + sTime.toDate().toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                               () + " " + sTime.toDate().getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            System.out.println("\t suSec is " + suSec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            System.out.println("\t error code is " + errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            System.out.println("\t error Message is " + Krb5.getErrorMessage(errorCode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (crealm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                System.out.println("\t crealm is " + crealm.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                System.out.println("\t cname is " + cname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (realm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                System.out.println("\t realm is " + realm.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (sname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                System.out.println("\t sname is " + sname.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                System.out.println("\t eData provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                System.out.println("\t checksum provided.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            System.out.println("\t msgType is " + msgType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Encodes an KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @return the byte array of encoded KRBError object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public byte[] asn1Encode() throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        DerOutputStream temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        temp.putInteger(BigInteger.valueOf(pvno));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        temp.putInteger(BigInteger.valueOf(msgType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (cTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (cuSec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            temp.putInteger(BigInteger.valueOf(cuSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x04), sTime.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        temp.putInteger(BigInteger.valueOf(suSec.intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x05), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        temp.putInteger(BigInteger.valueOf(errorCode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x06), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (crealm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x07), crealm.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x08), cname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x09), realm.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0A), sname.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (eText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            temp = new DerOutputStream();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   520
            temp.putDerValue(new KerberosString(eText).toDerValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0B), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (eData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            temp.putOctetString(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0C), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (eCksum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x0D), eCksum.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        temp.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        bytes.write(DerValue.createTag(DerValue.TAG_APPLICATION, true, (byte)0x1E), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        return bytes.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    @Override public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (!(obj instanceof KRBError)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        KRBError other = (KRBError)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return  pvno == other.pvno &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                msgType == other.msgType &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                isEqual(cTime, other.cTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                isEqual(cuSec, other.cuSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                isEqual(sTime, other.sTime) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                isEqual(suSec, other.suSec) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                errorCode == other.errorCode &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                isEqual(crealm, other.crealm) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                isEqual(cname, other.cname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                isEqual(realm, other.realm) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                isEqual(sname, other.sname) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                isEqual(eText, other.eText) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                java.util.Arrays.equals(eData, other.eData) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                isEqual(eCksum, other.eCksum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    private static boolean isEqual(Object a, Object b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return (a == null)?(b == null):(a.equals(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    @Override public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        result = 37 * result + pvno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        result = 37 * result + msgType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (cTime != null) result = 37 * result + cTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (cuSec != null) result = 37 * result + cuSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if (sTime != null) result = 37 * result + sTime.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (suSec != null) result = 37 * result + suSec.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        result = 37 * result + errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        if (crealm != null) result = 37 * result + crealm.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (cname != null) result = 37 * result + cname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (realm != null) result = 37 * result + realm.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (sname != null) result = 37 * result + sname.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (eText != null) result = 37 * result + eText.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        result = 37 * result + Arrays.hashCode(eData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (eCksum != null) result = 37 * result + eCksum.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
}