jdk/src/share/classes/sun/security/krb5/KrbAsReq.java
author weijun
Thu, 17 Jun 2010 13:46:15 +0800
changeset 5802 ea99d72d3c19
parent 5774 4b9857e483c1
child 7183 d8ccc1c73358
permissions -rw-r--r--
6959292: regression: cannot login if session key and preauth does not use the same etype Reviewed-by: xuelei, valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5627
lana
parents: 5617 5506
diff changeset
     2
 * Copyright (c) 2000, 2010, 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: 3949
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: 3949
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: 3949
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3949
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.EType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.krb5.internal.crypto.Nonce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.krb5.internal.crypto.KeyUsage;
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    38
import sun.security.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    40
import java.io.ByteArrayInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.net.UnknownHostException;
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    42
import java.util.StringTokenizer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * This class encapsulates the KRB-AS-REQ message that the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * sends to the KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class KrbAsReq extends KrbKdcReq {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private PrincipalName princName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private ASReq asReqMessg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private boolean DEBUG = Krb5.DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static KDCOptions defaultKDCOptions = new KDCOptions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // pre-auth info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private boolean PA_ENC_TIMESTAMP_REQUIRED = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean pa_exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private int pa_etype = 0;
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
    59
    private String pa_salt = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private byte[] pa_s2kparams = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // default is address-less tickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private boolean KDC_EMPTY_ADDRESSES_ALLOWED = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Creates a KRB-AS-REQ to send to the default KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @throws KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     // Called by Credentials
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    71
    KrbAsReq(PrincipalName principal, EncryptionKey[] keys)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this(keys, // for pre-authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
             false, 0, null, null, // pre-auth values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
             defaultKDCOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
             principal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
             null, // PrincipalName sname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
             null, // KerberosTime from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
             null, // KerberosTime till
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
             null, // KerberosTime rtime
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    81
             null, // int[] eTypes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
             null, // HostAddresses addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
             null); // Ticket[] additionalTickets
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
     * Creates a KRB-AS-REQ to send to the default KDC
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * with pre-authentication values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
    90
    KrbAsReq(PrincipalName principal, EncryptionKey[] keys,
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
    91
        boolean pa_exists, int etype, String salt, byte[] s2kparams)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this(keys, // for pre-authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
             pa_exists, etype, salt, s2kparams, // pre-auth values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
             defaultKDCOptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
             principal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
             null, // PrincipalName sname
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
             null, // KerberosTime from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
             null, // KerberosTime till
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
             null, // KerberosTime rtime
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   101
             null, // int[] eTypes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
             null, // HostAddresses addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
             null); // Ticket[] additionalTickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     private static int[] getETypesFromKeys(EncryptionKey[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         int[] types = new int[keys.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             types[i] = keys[i].getEType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // update with pre-auth info
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   115
    public void updatePA(int etype, String salt, byte[] params, PrincipalName name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // set the pre-auth values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        pa_exists = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        pa_etype = etype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        pa_salt = salt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        pa_s2kparams = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        // update salt in PrincipalName
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   123
        if (salt != null && salt.length() > 0) {
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   124
            name.setSalt(salt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                System.out.println("Updated salt from pre-auth = " + name.getSalt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        PA_ENC_TIMESTAMP_REQUIRED = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     // Used by Kinit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public KrbAsReq(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    char[] password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    Ticket[] additionalTickets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        this(password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
             false, 0, null, null, // pre-auth values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
             options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             sname, // PrincipalName sname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
             from,  // KerberosTime from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
             till,  // KerberosTime till
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             rtime, // KerberosTime rtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
             eTypes, // int[] eTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
             addresses, // HostAddresses addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
             additionalTickets); // Ticket[] additionalTickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     // Used by Kinit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public KrbAsReq(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    char[] password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    boolean pa_exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    int etype,
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   163
                    String salt,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    byte[] s2kparams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    Ticket[] additionalTickets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        EncryptionKey[] keys = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // update with preauth info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (pa_exists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            updatePA(etype, salt, s2kparams, cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (password != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            keys = EncryptionKey.acquireSecretKeys(password, cname.getSalt(), pa_exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                        pa_etype, pa_s2kparams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            System.out.println(">>>KrbAsReq salt is " + cname.getSalt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            init(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                 keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                 options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                 cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                 sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                 from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                 till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                 rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                 eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                 addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                 additionalTickets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
             * Its ok to destroy the key here because we created it and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
             * now done with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             if (keys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                 for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                     keys[i].destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     // Used in Kinit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public KrbAsReq(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    EncryptionKey[] keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    Ticket[] additionalTickets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        this(keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
             false, 0, null, null, // pre-auth values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
             options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
             cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
             sname, // PrincipalName sname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
             from,  // KerberosTime from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
             till,  // KerberosTime till
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
             rtime, // KerberosTime rtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
             eTypes, // int[] eTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
             addresses, // HostAddresses addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             additionalTickets); // Ticket[] additionalTickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    // Used by Kinit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public KrbAsReq(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    EncryptionKey[] keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    boolean pa_exists,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    int etype,
3949
00603a93b589 6862679: ESC: AD Authentication with user with umlauts fails
weijun
parents: 2
diff changeset
   248
                    String salt,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    byte[] s2kparams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    Ticket[] additionalTickets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        // update with preauth info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (pa_exists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            // update pre-auth info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            updatePA(etype, salt, s2kparams, cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                System.out.println(">>>KrbAsReq salt is " + cname.getSalt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        init(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
             keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
             options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
             cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
             sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
             from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
             till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
             rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
             eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
             addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
             additionalTickets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private KrbAsReq(KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
             PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
             PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
             KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
             KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
             KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
             int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
             Ticket[] additionalTickets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        init(null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
             cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
             from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
             till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
             rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
             eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
             addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
             additionalTickets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private void init(EncryptionKey[] keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                      KDCOptions options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                      PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                      PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                      KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                      KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                      KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                      int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                      HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                      Ticket[] additionalTickets )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        // check if they are valid arguments. The optional fields should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // consistent with settings in KDCOptions. Mar 17 2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (options.get(KDCOptions.FORWARDED) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            options.get(KDCOptions.PROXY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            options.get(KDCOptions.ENC_TKT_IN_SKEY) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            options.get(KDCOptions.RENEW) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            options.get(KDCOptions.VALIDATE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            // this option is only specified in a request to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            // ticket-granting server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (options.get(KDCOptions.POSTDATED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            //  if (from == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            //          throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (from != null)  from = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (options.get(KDCOptions.RENEWABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            //  if (rtime == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            //          throw new KrbException(Krb5.KRB_AP_ERR_REQ_OPTIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (rtime != null)  rtime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        princName = cname;
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   345
        int[] tktETypes = EType.getDefaults("default_tkt_enctypes", keys);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        PAData[] paData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (PA_ENC_TIMESTAMP_REQUIRED) {
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   348
            EncryptionKey key = null;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   349
            if (pa_etype != EncryptedData.ETYPE_NULL) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   350
                if (DEBUG) {
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   351
                    System.out.println("Pre-Authenticaton: find key for etype = " + pa_etype);
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   352
                }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   353
                key = EncryptionKey.findKey(pa_etype, keys);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   354
            } else {
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   355
                if (tktETypes.length > 0) {
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   356
                    key = EncryptionKey.findKey(tktETypes[0], keys);
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   357
                }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   358
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                System.out.println("AS-REQ: Add PA_ENC_TIMESTAMP now");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            PAEncTSEnc ts = new PAEncTSEnc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            byte[] temp = ts.asn1Encode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            if (key != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                // Use first key in list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                EncryptedData encTs = new EncryptedData(key, temp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    KeyUsage.KU_PA_ENC_TS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                paData = new PAData[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                paData[0] = new PAData( Krb5.PA_ENC_TIMESTAMP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                        encTs.asn1Encode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            System.out.println(">>> KrbAsReq calling createMessage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (eTypes == null) {
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   379
            eTypes = tktETypes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // check to use addresses in tickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (Config.getInstance().useAddresses()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            KDC_EMPTY_ADDRESSES_ALLOWED = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // get the local InetAddress if required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (addresses == null && !KDC_EMPTY_ADDRESSES_ALLOWED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            addresses = HostAddresses.getLocalAddresses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        asReqMessg = createMessage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                   paData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                   options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                   cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                   cname.getRealm(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                   sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                   from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                   till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                   rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                   eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                   addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                   additionalTickets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        obuf = asReqMessg.asn1Encode();
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 an AS-REP message corresponding to the AS-REQ that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * was sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param password The password that will be used to derive the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * secret key that will decrypt the AS-REP from  the KDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @exception KrbException if an error occurs while reading the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @exception IOException if an I/O error occurs while reading encoded data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public KrbAsRep getReply(char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        throws KrbException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (password == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            throw new KrbException(Krb5.API_INVALID_ARG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        KrbAsRep temp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        EncryptionKey[] keys = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            keys = EncryptionKey.acquireSecretKeys(password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                princName.getSalt(), pa_exists, pa_etype, pa_s2kparams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            temp = getReply(keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
             * Its ok to destroy the key here because we created it and are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
             * now done with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
             if (keys != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    keys[i].destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Sends an AS request to the realm of the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * returns the KDC hostname that the request was sent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public String send()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws IOException, KrbException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        String realmStr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (princName != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            realmStr = princName.getRealmString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return (send(realmStr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns an AS-REP message corresponding to the AS-REQ that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * was sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param keys The secret keys that will decrypt the AS-REP from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * the KDC; key selected depends on etype used to encrypt data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @exception KrbException if an error occurs while reading the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @exception IOException if an I/O error occurs while reading encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public KrbAsRep getReply(EncryptionKey[] keys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        throws KrbException,IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return new KrbAsRep(ibuf, keys, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    private ASReq createMessage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        PAData[] paData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                        KDCOptions kdc_options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        PrincipalName cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        Realm crealm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        PrincipalName sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        KerberosTime from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        KerberosTime till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        KerberosTime rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        int[] eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        HostAddresses addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        Ticket[] additionalTickets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        ) throws Asn1Exception, KrbApErrException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        RealmException, UnknownHostException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            System.out.println(">>> KrbAsReq in createMessage");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        PrincipalName req_sname = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (sname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (crealm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                throw new RealmException(Krb5.REALM_NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                         "default realm not specified ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            req_sname = new PrincipalName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                          "krbtgt" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                          PrincipalName.NAME_COMPONENT_SEPARATOR +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                          crealm.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                          PrincipalName.KRB_NT_SRV_INST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            req_sname = sname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        KerberosTime req_till = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (till == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            req_till = new KerberosTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            req_till = till;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        KDCReqBody kdc_req_body = new KDCReqBody(kdc_options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                                 cname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                                 crealm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                                 req_sname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                                 from,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                                 req_till,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                                 rtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                                 Nonce.value(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                                 eTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                                 addresses,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                                 additionalTickets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return new ASReq(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                         paData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                         kdc_req_body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    ASReq getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return asReqMessg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
}