jdk/src/share/classes/sun/security/krb5/KrbApReq.java
author weijun
Wed, 07 Nov 2012 14:13:01 +0800
changeset 14413 e954df027393
parent 14342 8435a30053c1
child 15006 10d6aacdd67f
permissions -rw-r--r--
6355584: Introduce constrained Kerberos delegation Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 13247
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4168
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: 4168
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: 4168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4168
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.krb5.internal.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.krb5.internal.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.internal.rcache.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
9240
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
    40
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class encapsulates a KRB-AP-REQ that a client sends to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * server for authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class KrbApReq {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private byte[] obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private KerberosTime ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private int cusec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private Authenticator authenticator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private Credentials creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private APReq apReqMessg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static CacheTable table = new CacheTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Contructs a AP-REQ message to send to the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param tgsCred the <code>Credentials</code> to be used to construct the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *          AP Request  protocol message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param mutualRequired Whether mutual authentication is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param useSubkey Whether the subkey is to be used to protect this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *        specific application session. If this is not set then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *        session key from the ticket will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     // Not Used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public KrbApReq(Credentials tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                    boolean mutualRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    boolean useSubKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    boolean useSeqNumber) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    KrbCryptoException, KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this(tgsCred, mutualRequired, useSubKey, useSeqNumber, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Contructs a AP-REQ message to send to the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param tgsCred the <code>Credentials</code> to be used to construct the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *          AP Request  protocol message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param mutualRequired Whether mutual authentication is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param useSubkey Whether the subkey is to be used to protect this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *        specific application session. If this is not set then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *        session key from the ticket will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param checksum checksum of the the application data that accompanies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *        the KRB_AP_REQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     // Used in InitSecContextToken
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public KrbApReq(Credentials tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    boolean mutualRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    boolean useSubKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    boolean useSeqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    Checksum cksum) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    KrbCryptoException, KrbException, IOException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        APOptions apOptions = (mutualRequired?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                               new APOptions(Krb5.AP_OPTS_MUTUAL_REQUIRED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                               new APOptions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.out.println(">>> KrbApReq: APOptions are " + apOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        EncryptionKey subKey = (useSubKey?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                new EncryptionKey(tgsCred.getSessionKey()):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        SeqNumber seqNum = new LocalSeqNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        init(apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
             cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
             subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             seqNum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
             null,   // AuthorizationData authzData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            KeyUsage.KU_AP_REQ_AUTHENTICATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Contructs a AP-REQ message from the bytes received from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param message The message received from the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param keys <code>EncrtyptionKey</code>s to decrypt the message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *       key selected will depend on etype used to encrypte data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     // Used in InitSecContextToken (for AP_REQ and not TGS REQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public KrbApReq(byte[] message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    EncryptionKey[] keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    InetAddress initiator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        obuf = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        authenticate(keys, initiator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Contructs a AP-REQ message from the bytes received from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param value The <code>DerValue</code> that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *              DER enoded AP-REQ protocol message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param keys <code>EncrtyptionKey</code>s to decrypt the message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public KrbApReq(DerValue value, EncryptionKey[] key, InetAddress initiator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        obuf = value.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            decode(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        authenticate(keys, initiator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    KrbApReq(APOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
             Credentials tgs_creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
             Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
             EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
             SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
             AuthorizationData authorizationData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        init(options, tgs_creds, cksum, subKey, seqNumber, authorizationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     /** used by KrbTgsReq **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    KrbApReq(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
             Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
             EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
             PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             KerberosTime ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        AuthorizationData authorizationData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
               KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   191
        init(apOptions, ticket, key, cname,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             cksum, ctime, subKey, seqNumber, authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            KeyUsage.KU_PA_TGS_REQ_AUTHENTICATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private void init(APOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                      Credentials tgs_creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                      Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                      EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                      SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                      AuthorizationData authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        ctime = new KerberosTime(KerberosTime.NOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        init(options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
             tgs_creds.ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             tgs_creds.key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
             tgs_creds.client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
             cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
             ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
             subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
             authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private void init(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                      Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                      EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                      PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                      Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                      KerberosTime ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                      EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                      SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                      AuthorizationData authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
               KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   232
        createMessage(apOptions, ticket, key, cname,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                      cksum, ctime, subKey, seqNumber, authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        obuf = apReqMessg.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    void decode() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        DerValue encoding = new DerValue(obuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        decode(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    void decode(DerValue encoding) throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        apReqMessg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            apReqMessg = new APReq(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } catch (Asn1Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            apReqMessg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            KRBError err = new KRBError(encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            String errStr = err.getErrorString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            String eText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (errStr.charAt(errStr.length() - 1) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                eText = errStr.substring(0, errStr.length() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                eText = errStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            KrbException ke = new KrbException(err.getErrorCode(), eText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            ke.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw ke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private void authenticate(EncryptionKey[] keys, InetAddress initiator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        int encPartKeyType = apReqMessg.ticket.encPart.getEType();
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3483
diff changeset
   266
        Integer kvno = apReqMessg.ticket.encPart.getKeyVersionNumber();
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3483
diff changeset
   267
        EncryptionKey dkey = EncryptionKey.findKey(encPartKeyType, kvno, keys);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (dkey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            throw new KrbException(Krb5.API_INVALID_ARG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                "Cannot find key of appropriate type to decrypt AP REP - " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                   EType.toString(encPartKeyType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        byte[] bytes = apReqMessg.ticket.encPart.decrypt(dkey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            KeyUsage.KU_TICKET);
5975
076cd013e5e4 6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents: 5506
diff changeset
   277
        byte[] temp = apReqMessg.ticket.encPart.reset(bytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        EncTicketPart enc_ticketPart = new EncTicketPart(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        checkPermittedEType(enc_ticketPart.key.getEType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        byte[] bytes2 = apReqMessg.authenticator.decrypt(enc_ticketPart.key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            KeyUsage.KU_AP_REQ_AUTHENTICATOR);
5975
076cd013e5e4 6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents: 5506
diff changeset
   284
        byte[] temp2 = apReqMessg.authenticator.reset(bytes2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        authenticator = new Authenticator(temp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        ctime = authenticator.ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        cusec = authenticator.cusec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        authenticator.ctime.setMicroSeconds(authenticator.cusec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14342
diff changeset
   290
        if (!authenticator.cname.equals(enc_ticketPart.cname)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADMATCH);
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14342
diff changeset
   292
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        KerberosTime currTime = new KerberosTime(KerberosTime.NOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (!authenticator.ctime.inClockSkew(currTime))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // start to check if it is a replay attack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        AuthTime time =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            new AuthTime(authenticator.ctime.getTime(), authenticator.cusec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        String client = authenticator.cname.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (table.get(time, authenticator.cname.toString()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            table.put(client, time, currTime.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (initiator != null) {
9240
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   309
            // sender host address
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   310
            HostAddress sender = new HostAddress(initiator);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   311
            if (enc_ticketPart.caddr != null
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   312
                    && !enc_ticketPart.caddr.inList(sender)) {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   313
                if (DEBUG) {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   314
                    System.out.println(">>> KrbApReq: initiator is "
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   315
                            + sender.getInetAddress()
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   316
                            + ", but caddr is "
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   317
                            + Arrays.toString(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   318
                                enc_ticketPart.caddr.getInetAddresses()));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   319
                }
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   320
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADADDR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // XXX check for repeated authenticator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // if found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        //    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        //    save authenticator to check for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        KerberosTime now = new KerberosTime(KerberosTime.NOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if ((enc_ticketPart.starttime != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             enc_ticketPart.starttime.greaterThanWRTClockSkew(now)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            enc_ticketPart.flags.get(Krb5.TKT_OPTS_INVALID))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            throw new KrbApErrException(Krb5.KRB_AP_ERR_TKT_NYV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // if the current time is later than end time by more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // than the allowable clock skew, throws ticket expired exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (enc_ticketPart.endtime != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            now.greaterThanWRTClockSkew(enc_ticketPart.endtime)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            throw new KrbApErrException(Krb5.KRB_AP_ERR_TKT_EXPIRED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        creds = new Credentials(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                apReqMessg.ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                authenticator.cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                apReqMessg.ticket.sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                enc_ticketPart.key,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   349
                                enc_ticketPart.flags,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                enc_ticketPart.authtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                enc_ticketPart.starttime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                enc_ticketPart.endtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                enc_ticketPart.renewTill,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   354
                                enc_ticketPart.caddr,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   355
                                enc_ticketPart.authorizationData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            System.out.println(">>> KrbApReq: authenticate succeed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the credentials that are contained in the ticket that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * is part of this this AP-REP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public Credentials getCreds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    KerberosTime getCtime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (ctime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return authenticator.ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    int cusec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        return cusec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    APOptions getAPOptions() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (apReqMessg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return apReqMessg.apOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns true if mutual authentication is required and hence an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * AP-REP will need to be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @throws KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public boolean getMutualAuthRequired() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (apReqMessg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            return apReqMessg.apOptions.get(Krb5.AP_OPTS_MUTUAL_REQUIRED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    boolean useSessionKey() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (apReqMessg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return apReqMessg.apOptions.get(Krb5.AP_OPTS_USE_SESSION_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Returns the optional subkey stored in the Authenticator for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * this message. Returns null if none is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public EncryptionKey getSubKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        // XXX Can authenticator be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return authenticator.getSubKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Returns the optional sequence number stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Authenticator for this message. Returns null if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public Integer getSeqNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // XXX Can authenticator be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return authenticator.getSeqNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Returns the optional Checksum stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Authenticator for this message. Returns null if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public Checksum getChecksum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return authenticator.getChecksum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns the ASN.1 encoding that should be sent to the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public byte[] getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Returns the principal name of the client that generated this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public PrincipalName getClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return creds.getClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    private void createMessage(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                               Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                               EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                               PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                               Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                               KerberosTime ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                               EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                               SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                               AuthorizationData authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
               KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        Integer seqno = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (seqNumber != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            seqno = new Integer(seqNumber.current());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        authenticator =
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   471
            new Authenticator(cname,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                              cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                              ctime.getMicroSeconds(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                              ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                              subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                              seqno,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                              authorizationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        byte[] temp = authenticator.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        EncryptedData encAuthenticator =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            new EncryptedData(key, temp, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        apReqMessg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            new APReq(apOptions, ticket, encAuthenticator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     // Check that key is one of the permitted types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     private static void checkPermittedEType(int target) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        int[] etypes = EType.getDefaults("permitted_enctypes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (etypes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            throw new KrbException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                "No supported encryption types listed in permitted_enctypes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (!EType.isSupported(target, etypes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            throw new KrbException(EType.toString(target) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                " encryption type not in permitted_enctypes list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
}