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