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