src/java.security.jgss/share/classes/sun/security/krb5/KrbApReq.java
author mbalao
Wed, 05 Jun 2019 01:42:11 -0300
changeset 55258 d65d3c37232c
parent 47216 71c04702a3d5
child 57487 643978a35f6e
permissions -rw-r--r--
8215032: Support Kerberos cross-realm referrals (RFC 6806) Reviewed-by: weijun
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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
    64
     * Constructs an AP-REQ message to send to the peer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param tgsCred the <code>Credentials</code> to be used to construct the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *          AP Request  protocol message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param mutualRequired Whether mutual authentication is required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param useSubkey Whether the subkey is to be used to protect this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *        specific application session. If this is not set then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *        session key from the ticket will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     // Not Used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public KrbApReq(Credentials tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    boolean mutualRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    boolean useSubKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    boolean useSeqNumber) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    KrbCryptoException, KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this(tgsCred, mutualRequired, useSubKey, useSeqNumber, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
    88
     * Constructs an AP-REQ message to send to the peer.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param tgsCred the <code>Credentials</code> to be used to construct the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *          AP Request  protocol message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param mutualRequired Whether mutual authentication is required
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
    92
     * @param useSubKey Whether the subkey is to be used to protect this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *        specific application session. If this is not set then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *        session key from the ticket will be used.
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
    95
     * @param cksum checksum of the application data that accompanies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *        the KRB_AP_REQ.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     // Used in InitSecContextToken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public KrbApReq(Credentials tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    boolean mutualRequired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    boolean useSubKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    boolean useSeqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    Checksum cksum) throws Asn1Exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    KrbCryptoException, KrbException, IOException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        APOptions apOptions = (mutualRequired?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                               new APOptions(Krb5.AP_OPTS_MUTUAL_REQUIRED):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                               new APOptions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (DEBUG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            System.out.println(">>> KrbApReq: APOptions are " + apOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        EncryptionKey subKey = (useSubKey?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                new EncryptionKey(tgsCred.getSessionKey()):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        SeqNumber seqNum = new LocalSeqNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        init(apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
             tgsCred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
             cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
             subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
             seqNum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
             null,   // AuthorizationData authzData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            KeyUsage.KU_AP_REQ_AUTHENTICATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   132
     * Constructs an AP-REQ message from the bytes received from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param message The message received from the peer
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   135
     * @param cred <code>KrbAcceptCredential</code> containing keys to decrypt
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   136
     *    the message; key selected will depend on etype used to encrypt data
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     // Used in InitSecContextToken (for AP_REQ and not TGS REQ)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public KrbApReq(byte[] message,
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   143
                    Krb5AcceptCredential cred,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    InetAddress initiator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        obuf = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            decode();
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   149
        authenticate(cred, initiator);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   153
     * Constructs an AP-REQ message from the bytes received from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param value The <code>DerValue</code> that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *              DER enoded AP-REQ protocol message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param keys <code>EncrtyptionKey</code>s to decrypt the message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @throws KrbException for any Kerberos protocol specific error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @throws IOException for any IO related errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *          (e.g. socket operations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public KrbApReq(DerValue value, EncryptionKey[] key, InetAddress initiator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        obuf = value.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            decode(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        authenticate(keys, initiator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    KrbApReq(APOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
             Credentials tgs_creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
             Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
             EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
             SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
             AuthorizationData authorizationData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        init(options, tgs_creds, cksum, subKey, seqNumber, authorizationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     /** used by KrbTgsReq **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    KrbApReq(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
             Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             KerberosTime ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
             SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        AuthorizationData authorizationData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
               KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   196
        init(apOptions, ticket, key, cname,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
             cksum, ctime, subKey, seqNumber, authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            KeyUsage.KU_PA_TGS_REQ_AUTHENTICATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private void init(APOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                      Credentials tgs_creds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                      Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                      EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                      SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                      AuthorizationData authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
16905
0419f45c7761 8011124: Make KerberosTime immutable
weijun
parents: 15006
diff changeset
   211
        ctime = KerberosTime.now();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        init(options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
             tgs_creds.ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             tgs_creds.key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
             tgs_creds.client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
             seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private void init(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                      Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                      EncryptionKey key,
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
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   237
        createMessage(apOptions, ticket, key, cname,
2
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
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   268
    private void authenticate(Krb5AcceptCredential cred, InetAddress initiator)
2
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();
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   272
        EncryptionKey[] keys = cred.getKrb5EncryptionKeys(apReqMessg.ticket.sname);
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3483
diff changeset
   273
        EncryptionKey dkey = EncryptionKey.findKey(encPartKeyType, kvno, keys);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (dkey == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            throw new KrbException(Krb5.API_INVALID_ARG,
23346
c1437bb64131 8037262: typo in error message in KrbAsReq.authenticate()
weijun
parents: 23010
diff changeset
   277
                "Cannot find key of appropriate type to decrypt AP-REQ - " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                   EType.toString(encPartKeyType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        byte[] bytes = apReqMessg.ticket.encPart.decrypt(dkey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            KeyUsage.KU_TICKET);
5975
076cd013e5e4 6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents: 5506
diff changeset
   283
        byte[] temp = apReqMessg.ticket.encPart.reset(bytes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        EncTicketPart enc_ticketPart = new EncTicketPart(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        checkPermittedEType(enc_ticketPart.key.getEType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        byte[] bytes2 = apReqMessg.authenticator.decrypt(enc_ticketPart.key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            KeyUsage.KU_AP_REQ_AUTHENTICATOR);
5975
076cd013e5e4 6946669: SSL/Krb5 should not call EncryptedData.reset(data, false)
weijun
parents: 5506
diff changeset
   290
        byte[] temp2 = apReqMessg.authenticator.reset(bytes2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        authenticator = new Authenticator(temp2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ctime = authenticator.ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        cusec = authenticator.cusec;
16905
0419f45c7761 8011124: Make KerberosTime immutable
weijun
parents: 15006
diff changeset
   294
        authenticator.ctime =
0419f45c7761 8011124: Make KerberosTime immutable
weijun
parents: 15006
diff changeset
   295
                authenticator.ctime.withMicroSeconds(authenticator.cusec);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14342
diff changeset
   297
        if (!authenticator.cname.equals(enc_ticketPart.cname)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            throw new KrbApErrException(Krb5.KRB_AP_ERR_BADMATCH);
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 14342
diff changeset
   299
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
16905
0419f45c7761 8011124: Make KerberosTime immutable
weijun
parents: 15006
diff changeset
   301
        if (!authenticator.ctime.inClockSkew())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            throw new KrbApErrException(Krb5.KRB_AP_ERR_SKEW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 28774
diff changeset
   304
        String alg = AuthTimeWithHash.DEFAULT_HASH_ALG;
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   305
        byte[] hash;
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   306
        try {
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 28774
diff changeset
   307
            hash = MessageDigest.getInstance(AuthTimeWithHash.realAlg(alg))
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   308
                    .digest(apReqMessg.authenticator.cipher);
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   309
        } catch (NoSuchAlgorithmException ex) {
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 28774
diff changeset
   310
            throw new AssertionError("Impossible " + alg);
28774
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   311
        }
052832e70254 8071643: sun.security.krb5.KrbApReq.authenticate() is not thread safe
weijun
parents: 28059
diff changeset
   312
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   313
        char[] h = new char[hash.length * 2];
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   314
        for (int i=0; i<hash.length; i++) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   315
            h[2*i] = hexConst[(hash[i]&0xff)>>4];
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   316
            h[2*i+1] = hexConst[hash[i]&0xf];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   318
        AuthTimeWithHash time = new AuthTimeWithHash(
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   319
                authenticator.cname.toString(),
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   320
                apReqMessg.ticket.sname.toString(),
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   321
                authenticator.ctime.getSeconds(),
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   322
                authenticator.cusec,
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 28774
diff changeset
   323
                alg,
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   324
                new String(h));
092411ced388 8001326: Improve Kerberos caching
weijun
parents: 18168
diff changeset
   325
        rcache.checkAndStore(KerberosTime.now(), time);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (initiator != null) {
9240
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   328
            // sender host address
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   329
            HostAddress sender = new HostAddress(initiator);
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   330
            if (enc_ticketPart.caddr != null
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   331
                    && !enc_ticketPart.caddr.inList(sender)) {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   332
                if (DEBUG) {
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   333
                    System.out.println(">>> KrbApReq: initiator is "
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   334
                            + sender.getInetAddress()
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   335
                            + ", but caddr is "
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   336
                            + Arrays.toString(
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   337
                                enc_ticketPart.caddr.getInetAddresses()));
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   338
                }
56e01f64958e 7032354: no-addresses should not be used on acceptor side
weijun
parents: 5975
diff changeset
   339
                throw new KrbApErrException(Krb5.KRB_AP_ERR_BADADDR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // XXX check for repeated authenticator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // if found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        //    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        //    save authenticator to check for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
16905
0419f45c7761 8011124: Make KerberosTime immutable
weijun
parents: 15006
diff changeset
   349
        KerberosTime now = KerberosTime.now();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if ((enc_ticketPart.starttime != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
             enc_ticketPart.starttime.greaterThanWRTClockSkew(now)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            enc_ticketPart.flags.get(Krb5.TKT_OPTS_INVALID))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            throw new KrbApErrException(Krb5.KRB_AP_ERR_TKT_NYV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // if the current time is later than end time by more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // than the allowable clock skew, throws ticket expired exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (enc_ticketPart.endtime != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            now.greaterThanWRTClockSkew(enc_ticketPart.endtime)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new KrbApErrException(Krb5.KRB_AP_ERR_TKT_EXPIRED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        creds = new Credentials(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                apReqMessg.ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                authenticator.cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                apReqMessg.ticket.sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                enc_ticketPart.key,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   368
                                enc_ticketPart.flags,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                enc_ticketPart.authtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                enc_ticketPart.starttime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                enc_ticketPart.endtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                enc_ticketPart.renewTill,
3483
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   373
                                enc_ticketPart.caddr,
a16fce1820ef 6821190: more InquireType values for ExtendedGSSContext
weijun
parents: 3315
diff changeset
   374
                                enc_ticketPart.authorizationData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            System.out.println(">>> KrbApReq: authenticate succeed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
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
     * Returns the credentials that are contained in the ticket that
23346
c1437bb64131 8037262: typo in error message in KrbAsReq.authenticate()
weijun
parents: 23010
diff changeset
   382
     * is part of this AP-REQ.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public Credentials getCreds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return creds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    KerberosTime getCtime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (ctime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return authenticator.ctime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    int cusec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return cusec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    APOptions getAPOptions() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (apReqMessg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return apReqMessg.apOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Returns true if mutual authentication is required and hence an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * AP-REP will need to be generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @throws KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public boolean getMutualAuthRequired() 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_MUTUAL_REQUIRED);
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
    boolean useSessionKey() throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (apReqMessg == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            decode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (apReqMessg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return apReqMessg.apOptions.get(Krb5.AP_OPTS_USE_SESSION_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Returns the optional subkey stored in the Authenticator for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * this message. Returns null if none is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public EncryptionKey getSubKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // XXX Can authenticator be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return authenticator.getSubKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns the optional sequence number stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Authenticator for this message. Returns null if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public Integer getSeqNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // XXX Can authenticator be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return authenticator.getSeqNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Returns the optional Checksum stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Authenticator for this message. Returns null if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public Checksum getChecksum() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return authenticator.getChecksum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Returns the ASN.1 encoding that should be sent to the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public byte[] getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return obuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Returns the principal name of the client that generated this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public PrincipalName getClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return creds.getClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    private void createMessage(APOptions apOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                               Ticket ticket,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                               EncryptionKey key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                               PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                               Checksum cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                               KerberosTime ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                               EncryptionKey subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                               SeqNumber seqNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                               AuthorizationData authorizationData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        int usage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        throws Asn1Exception, IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
               KdcErrException, KrbCryptoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        Integer seqno = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (seqNumber != null)
25522
10d789df41bb 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents: 23346
diff changeset
   487
            seqno = seqNumber.current();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        authenticator =
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 9240
diff changeset
   490
            new Authenticator(cname,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                              cksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                              ctime.getMicroSeconds(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                              ctime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                              subKey,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                              seqno,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                              authorizationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        byte[] temp = authenticator.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        EncryptedData encAuthenticator =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            new EncryptedData(key, temp, usage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        apReqMessg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            new APReq(apOptions, ticket, encAuthenticator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     // Check that key is one of the permitted types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     private static void checkPermittedEType(int target) throws KrbException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        int[] etypes = EType.getDefaults("permitted_enctypes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (!EType.isSupported(target, etypes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            throw new KrbException(EType.toString(target) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                " encryption type not in permitted_enctypes list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
}