src/java.security.jgss/share/classes/sun/security/krb5/internal/PAForUserEnc.java
author igerasim
Tue, 12 Nov 2019 01:36:17 -0800
changeset 59024 b046ba510bbc
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233884: Avoid looking up standard charsets in security libraries Reviewed-by: coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     1
/*
59024
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     4
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    10
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    15
 * accompanied this code).
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    16
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    20
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    23
 * questions.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    24
 */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    25
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    26
package sun.security.krb5.internal;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    27
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    28
import java.io.ByteArrayOutputStream;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    29
import java.io.IOException;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    30
import sun.security.krb5.*;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    31
import sun.security.krb5.internal.crypto.KeyUsage;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    32
import sun.security.krb5.internal.util.KerberosString;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    33
import sun.security.util.DerOutputStream;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    34
import sun.security.util.DerValue;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    35
59024
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
    36
import static java.nio.charset.StandardCharsets.UTF_8;
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
    37
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    38
/**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    39
 * Implements the ASN.1 PA-FOR-USER type.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    40
 *
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    41
 * <pre>{@code
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    42
 * padata-type  ::= PA-FOR-USER
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    43
 *                  -- value 129
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    44
 * padata-value ::= EncryptedData
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    45
 *                  -- PA-FOR-USER-ENC
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    46
 * PA-FOR-USER-ENC ::= SEQUENCE {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    47
 *     userName[0] PrincipalName,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    48
 *     userRealm[1] Realm,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    49
 *     cksum[2] Checksum,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    50
 *     auth-package[3] KerberosString
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    51
 * }
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    52
 * }</pre>
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    53
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    54
 * <p>
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    55
 * This definition reflects MS-SFU.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    56
 */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    57
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    58
public class PAForUserEnc {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    59
    final public PrincipalName name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    60
    final private EncryptionKey key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    61
    final public static String AUTH_PACKAGE = "Kerberos";
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    62
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    63
    public PAForUserEnc(PrincipalName name, EncryptionKey key) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    64
        this.name = name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    65
        this.key = key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    66
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    67
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    68
    /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    69
     * Constructs a PA-FOR-USER object from a DER encoding.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    70
     * @param encoding the input object
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    71
     * @param key the key to verify the checksum inside encoding
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    72
     * @throws KrbException if the verification fails.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    73
     * Note: this method is now only used by test KDC, therefore
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    74
     * the verification is ignored (at the moment).
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    75
     */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    76
    public PAForUserEnc(DerValue encoding, EncryptionKey key)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    77
            throws Asn1Exception, KrbException, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    78
        DerValue der = null;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    79
        this.key = key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    80
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    81
        if (encoding.getTag() != DerValue.tag_Sequence) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    82
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    83
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    84
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    85
        // Realm after name? Quite abnormal.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    86
        PrincipalName tmpName = null;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    87
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    88
        if ((der.getTag() & 0x1F) == 0x00) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    89
            try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    90
                tmpName = new PrincipalName(der.getData().getDerValue(),
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    91
                    new Realm("PLACEHOLDER"));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    92
            } catch (RealmException re) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    93
                // Impossible
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    94
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    95
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    96
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    97
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    98
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    99
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   100
        if ((der.getTag() & 0x1F) == 0x01) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   101
            try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   102
                Realm realm = new Realm(der.getData().getDerValue());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   103
                name = new PrincipalName(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   104
                        tmpName.getNameType(), tmpName.getNameStrings(), realm);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   105
            } catch (RealmException re) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   106
                throw new IOException(re);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   107
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   108
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   109
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   110
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   111
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   112
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   113
        if ((der.getTag() & 0x1F) == 0x02) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   114
            // Deal with the checksum
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   115
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   116
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   117
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   118
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   119
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   120
        if ((der.getTag() & 0x1F) == 0x03) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   121
            String authPackage = new KerberosString(der.getData().getDerValue()).toString();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   122
            if (!authPackage.equalsIgnoreCase(AUTH_PACKAGE)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   123
                throw new IOException("Incorrect auth-package");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   124
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   125
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   126
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   127
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   128
        if (encoding.getData().available() > 0)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   129
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   130
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   131
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   132
    public byte[] asn1Encode() throws Asn1Exception, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   133
        DerOutputStream bytes = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   134
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), name.asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   135
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), name.getRealm().asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   136
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   137
        try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   138
            Checksum cks = new Checksum(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   139
                    Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   140
                    getS4UByteArray(),
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   141
                    key,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   142
                    KeyUsage.KU_PA_FOR_USER_ENC_CKSUM);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   143
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cks.asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   144
        } catch (KrbException ke) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   145
            throw new IOException(ke);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   146
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   147
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   148
        DerOutputStream temp = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   149
        temp.putDerValue(new KerberosString(AUTH_PACKAGE).toDerValue());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   150
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   151
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   152
        temp = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   153
        temp.write(DerValue.tag_Sequence, bytes);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   154
        return temp.toByteArray();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   155
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   156
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   157
    /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   158
     * Returns S4UByteArray, the block to calculate checksum inside a
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   159
     * PA-FOR-USER-ENC data structure. It includes:
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   160
     * 1. userName.name-type encoded as a 4-byte integer in little endian
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   161
     *    byte order
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   162
     * 2. all string values in the sequence of strings contained in the
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   163
     *    userName.name-string field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   164
     * 3. the string value of the userRealm field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   165
     * 4. the string value of auth-package field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   166
     */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   167
    public byte[] getS4UByteArray() {
59024
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   168
        ByteArrayOutputStream ba = new ByteArrayOutputStream();
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   169
        ba.writeBytes(new byte[4]);
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   170
        for (String s: name.getNameStrings()) {
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   171
            ba.writeBytes(s.getBytes(UTF_8));
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   172
        }
59024
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   173
        ba.writeBytes(name.getRealm().toString().getBytes(UTF_8));
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   174
        ba.writeBytes(AUTH_PACKAGE.getBytes(UTF_8));
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   175
        byte[] output = ba.toByteArray();
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   176
        int pnType = name.getNameType();
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   177
        output[0] = (byte)(pnType & 0xff);
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   178
        output[1] = (byte)((pnType>>8) & 0xff);
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   179
        output[2] = (byte)((pnType>>16) & 0xff);
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   180
        output[3] = (byte)((pnType>>24) & 0xff);
b046ba510bbc 8233884: Avoid looking up standard charsets in security libraries
igerasim
parents: 47216
diff changeset
   181
        return output;
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   182
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   183
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   184
    public String toString() {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   185
        return "PA-FOR-USER: " + name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   186
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   187
}