src/java.security.jgss/share/classes/sun/security/krb5/internal/ETypeInfo2.java
author mbalao
Wed, 05 Jun 2019 01:42:11 -0300
changeset 55258 d65d3c37232c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215032: Support Kerberos cross-realm referrals (RFC 6806) Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
     2
 * Copyright (c) 2005, 2009, 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
package sun.security.krb5.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.security.krb5.Asn1Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
    31
import sun.security.krb5.internal.util.KerberosString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Implements the ASN.1 ETYPE-INFO-ENTRY type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * ETYPE-INFO2-ENTRY    ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *          etype       [0] Int32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *          salt        [1] KerberosString OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *          s2kparams   [2] OCTET STRING OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Seema Malkani
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class ETypeInfo2 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private int etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private String saltStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private byte[] s2kparams = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final byte TAG_TYPE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static final byte TAG_VALUE1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final byte TAG_VALUE2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private ETypeInfo2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
    58
    public ETypeInfo2(int etype, String salt, byte[] s2kparams) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.etype = etype;
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
    60
        this.saltStr = salt;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (s2kparams != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            this.s2kparams = s2kparams.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        ETypeInfo2 etypeInfo2 = new ETypeInfo2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        etypeInfo2.etype = etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        etypeInfo2.saltStr = saltStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (s2kparams != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            etypeInfo2.s2kparams = new byte[s2kparams.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            System.arraycopy(s2kparams, 0, etypeInfo2.s2kparams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                0, s2kparams.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return etypeInfo2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructs a ETypeInfo2 object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param encoding a DER-encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception Asn1Exception if an error occurs while decoding an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *            ASN1 encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public ETypeInfo2(DerValue encoding) throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        DerValue der = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (encoding.getTag() != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // etype
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        der = encoding.getData().getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if ((der.getTag() & 0x1F) == 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            this.etype = der.getData().getBigInteger().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // salt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (encoding.getData().available() > 0) {
75
dedcbd82b6e9 6648972: KDCReq.init always read padata
weijun
parents: 2
diff changeset
   102
            if ((encoding.getData().peekByte() & 0x1F) == 0x01) {
dedcbd82b6e9 6648972: KDCReq.init always read padata
weijun
parents: 2
diff changeset
   103
                der = encoding.getData().getDerValue();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
   104
                this.saltStr = new KerberosString(
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
   105
                        der.getData().getDerValue()).toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // s2kparams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (encoding.getData().available() > 0) {
75
dedcbd82b6e9 6648972: KDCReq.init always read padata
weijun
parents: 2
diff changeset
   111
            if ((encoding.getData().peekByte() & 0x1F) == 0x02) {
dedcbd82b6e9 6648972: KDCReq.init always read padata
weijun
parents: 2
diff changeset
   112
                der = encoding.getData().getDerValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                this.s2kparams = der.getData().getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (encoding.getData().available() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
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
     * Encodes this object to an OutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return byte array of the encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @exception Asn1Exception on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public byte[] asn1Encode() throws Asn1Exception, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        DerOutputStream temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        temp.putInteger(etype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                        TAG_TYPE), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (saltStr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            temp = new DerOutputStream();
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
   139
            temp.putDerValue(new KerberosString(saltStr).toDerValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                        TAG_VALUE1), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (s2kparams != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            temp.putOctetString(s2kparams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                        TAG_VALUE2), temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        temp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        temp.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return temp.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    // accessor methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public int getEType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
   160
    public String getSalt() {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 715
diff changeset
   161
        return saltStr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public byte[] getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return ((s2kparams == null) ? null : s2kparams.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}