src/java.security.jgss/share/classes/sun/security/krb5/internal/PAForUserEnc.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 32003 jdk/src/java.security.jgss/share/classes/sun/security/krb5/internal/PAForUserEnc.java@acb12269398a
child 59024 b046ba510bbc
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     1
/*
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    36
/**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    37
 * Implements the ASN.1 PA-FOR-USER type.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    38
 *
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    39
 * <pre>{@code
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    40
 * padata-type  ::= PA-FOR-USER
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    41
 *                  -- value 129
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    42
 * padata-value ::= EncryptedData
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    43
 *                  -- PA-FOR-USER-ENC
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    44
 * PA-FOR-USER-ENC ::= SEQUENCE {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    45
 *     userName[0] PrincipalName,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    46
 *     userRealm[1] Realm,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    47
 *     cksum[2] Checksum,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    48
 *     auth-package[3] KerberosString
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    49
 * }
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    50
 * }</pre>
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    51
 *
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    52
 * <p>
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    53
 * This definition reflects MS-SFU.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    54
 */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    55
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    56
public class PAForUserEnc {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    57
    final public PrincipalName name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    58
    final private EncryptionKey key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    59
    final public static String AUTH_PACKAGE = "Kerberos";
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    60
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    61
    public PAForUserEnc(PrincipalName name, EncryptionKey key) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    62
        this.name = name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    63
        this.key = key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    64
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    65
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    66
    /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    67
     * Constructs a PA-FOR-USER object from a DER encoding.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    68
     * @param encoding the input object
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    69
     * @param key the key to verify the checksum inside encoding
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    70
     * @throws KrbException if the verification fails.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    71
     * Note: this method is now only used by test KDC, therefore
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    72
     * the verification is ignored (at the moment).
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    73
     */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    74
    public PAForUserEnc(DerValue encoding, EncryptionKey key)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    75
            throws Asn1Exception, KrbException, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    76
        DerValue der = null;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    77
        this.key = key;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    78
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    79
        if (encoding.getTag() != DerValue.tag_Sequence) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    80
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    81
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    82
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    83
        // Realm after name? Quite abnormal.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    84
        PrincipalName tmpName = null;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    85
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    86
        if ((der.getTag() & 0x1F) == 0x00) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    87
            try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    88
                tmpName = new PrincipalName(der.getData().getDerValue(),
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    89
                    new Realm("PLACEHOLDER"));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    90
            } catch (RealmException re) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    91
                // Impossible
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    92
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    93
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    94
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    95
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    96
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    97
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    98
        if ((der.getTag() & 0x1F) == 0x01) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
    99
            try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   100
                Realm realm = new Realm(der.getData().getDerValue());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   101
                name = new PrincipalName(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   102
                        tmpName.getNameType(), tmpName.getNameStrings(), realm);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   103
            } catch (RealmException re) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   104
                throw new IOException(re);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   105
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   106
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   107
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   108
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   109
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   110
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   111
        if ((der.getTag() & 0x1F) == 0x02) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   112
            // Deal with the checksum
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   113
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   114
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   115
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   116
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   117
        der = encoding.getData().getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   118
        if ((der.getTag() & 0x1F) == 0x03) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   119
            String authPackage = new KerberosString(der.getData().getDerValue()).toString();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   120
            if (!authPackage.equalsIgnoreCase(AUTH_PACKAGE)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   121
                throw new IOException("Incorrect auth-package");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   122
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   123
        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   124
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   125
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   126
        if (encoding.getData().available() > 0)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   127
            throw new Asn1Exception(Krb5.ASN1_BAD_ID);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   128
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   129
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   130
    public byte[] asn1Encode() throws Asn1Exception, IOException {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   131
        DerOutputStream bytes = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   132
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), name.asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   133
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), name.getRealm().asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   134
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   135
        try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   136
            Checksum cks = new Checksum(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   137
                    Checksum.CKSUMTYPE_HMAC_MD5_ARCFOUR,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   138
                    getS4UByteArray(),
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   139
                    key,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   140
                    KeyUsage.KU_PA_FOR_USER_ENC_CKSUM);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   141
            bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x02), cks.asn1Encode());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   142
        } catch (KrbException ke) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   143
            throw new IOException(ke);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   144
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   145
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   146
        DerOutputStream temp = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   147
        temp.putDerValue(new KerberosString(AUTH_PACKAGE).toDerValue());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   148
        bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x03), temp);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   149
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   150
        temp = new DerOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   151
        temp.write(DerValue.tag_Sequence, bytes);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   152
        return temp.toByteArray();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   153
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   154
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   155
    /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   156
     * Returns S4UByteArray, the block to calculate checksum inside a
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   157
     * PA-FOR-USER-ENC data structure. It includes:
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   158
     * 1. userName.name-type encoded as a 4-byte integer in little endian
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   159
     *    byte order
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   160
     * 2. all string values in the sequence of strings contained in the
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   161
     *    userName.name-string field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   162
     * 3. the string value of the userRealm field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   163
     * 4. the string value of auth-package field
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   164
     */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   165
    public byte[] getS4UByteArray() {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   166
        try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   167
            ByteArrayOutputStream ba = new ByteArrayOutputStream();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   168
            ba.write(new byte[4]);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   169
            for (String s: name.getNameStrings()) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   170
                ba.write(s.getBytes("UTF-8"));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   171
            }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   172
            ba.write(name.getRealm().toString().getBytes("UTF-8"));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   173
            ba.write(AUTH_PACKAGE.getBytes("UTF-8"));
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   174
            byte[] output = ba.toByteArray();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   175
            int pnType = name.getNameType();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   176
            output[0] = (byte)(pnType & 0xff);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   177
            output[1] = (byte)((pnType>>8) & 0xff);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   178
            output[2] = (byte)((pnType>>16) & 0xff);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   179
            output[3] = (byte)((pnType>>24) & 0xff);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   180
            return output;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   181
        } catch (IOException ioe) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   182
            // not possible
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   183
            throw new AssertionError("Cannot write ByteArrayOutputStream", ioe);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   184
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   185
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   186
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   187
    public String toString() {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   188
        return "PA-FOR-USER: " + name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   189
    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents:
diff changeset
   190
}