jdk/test/sun/security/krb5/auto/KDC.java
author weijun
Thu, 04 Jun 2015 15:29:29 +0800
changeset 30959 14e1b420cdd6
parent 30038 632939157af2
child 31429 ce4193650b40
permissions -rw-r--r--
8031111: fix krb5 caddr Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     1
/*
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
     2
 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     4
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     8
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    13
 * accompanied this code).
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    14
 *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4532
diff changeset
    21
 * questions.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    22
 */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    23
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    24
import java.lang.reflect.Constructor;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    25
import java.lang.reflect.Field;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    26
import java.lang.reflect.InvocationTargetException;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    27
import java.net.*;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    28
import java.io.*;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    29
import java.lang.reflect.Method;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    30
import java.security.SecureRandom;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    31
import java.util.*;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    32
import java.util.concurrent.*;
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
    33
import sun.net.spi.nameservice.NameService;
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
    34
import sun.net.spi.nameservice.NameServiceDescriptor;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    35
import sun.security.krb5.*;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    36
import sun.security.krb5.internal.*;
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
    37
import sun.security.krb5.internal.ccache.CredentialsCache;
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
    38
import sun.security.krb5.internal.crypto.EType;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    39
import sun.security.krb5.internal.crypto.KeyUsage;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    40
import sun.security.krb5.internal.ktab.KeyTab;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    41
import sun.security.util.DerInputStream;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    42
import sun.security.util.DerOutputStream;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    43
import sun.security.util.DerValue;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    44
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    45
/**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    46
 * A KDC server.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    47
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    48
 * Features:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    49
 * <ol>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    50
 * <li> Supports TCP and UDP
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    51
 * <li> Supports AS-REQ and TGS-REQ
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    52
 * <li> Principal db and other settings hard coded in application
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    53
 * <li> Options, say, request preauth or not
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    54
 * </ol>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    55
 * Side effects:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    56
 * <ol>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    57
 * <li> The Sun-internal class <code>sun.security.krb5.Config</code> is a
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    58
 * singleton and initialized according to Kerberos settings (krb5.conf and
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    59
 * java.security.krb5.* system properties). This means once it's initialized
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    60
 * it will not automatically notice any changes to these settings (or file
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    61
 * changes of krb5.conf). The KDC class normally does not touch these
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    62
 * settings (except for the <code>writeKtab()</code> method). However, to make
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    63
 * sure nothing ever goes wrong, if you want to make any changes to these
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    64
 * settings after calling a KDC method, call <code>Config.refresh()</code> to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    65
 * make sure your changes are reflected in the <code>Config</code> object.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    66
 * </ol>
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
    67
 * System properties recognized:
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
    68
 * <ul>
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
    69
 * <li>test.kdc.save.ccache
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
    70
 * </ul>
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    71
 * Issues and TODOs:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    72
 * <ol>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    73
 * <li> Generates krb5.conf to be used on another machine, currently the kdc is
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    74
 * always localhost
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    75
 * <li> More options to KDC, say, error output, say, response nonce !=
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    76
 * request nonce
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    77
 * </ol>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    78
 * Note: This program uses internal krb5 classes (including reflection to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    79
 * access private fields and methods).
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    80
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    81
 * Usages:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    82
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    83
 * 1. Init and start the KDC:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    84
 * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    85
 * KDC kdc = KDC.create("REALM.NAME", port, isDaemon);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    86
 * KDC kdc = KDC.create("REALM.NAME");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    87
 * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    88
 * Here, <code>port</code> is the UDP and TCP port number the KDC server
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    89
 * listens on. If zero, a random port is chosen, which you can use getPort()
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    90
 * later to retrieve the value.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    91
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    92
 * If <code>isDaemon</code> is true, the KDC worker threads will be daemons.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    93
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    94
 * The shortcut <code>KDC.create("REALM.NAME")</code> has port=0 and
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    95
 * isDaemon=false, and is commonly used in an embedded KDC.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    96
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    97
 * 2. Adding users:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    98
 * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
    99
 * kdc.addPrincipal(String principal_name, char[] password);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   100
 * kdc.addPrincipalRandKey(String principal_name);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   101
 * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   102
 * A service principal's name should look like "host/f.q.d.n". The second form
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   103
 * generates a random key. To expose this key, call <code>writeKtab()</code> to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   104
 * save the keys into a keytab file.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   105
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   106
 * Note that you need to add the principal name krbtgt/REALM.NAME yourself.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   107
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   108
 * Note that you can safely add a principal at any time after the KDC is
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   109
 * started and before a user requests info on this principal.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   110
 * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   111
 * 3. Other public methods:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   112
 * <ul>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   113
 * <li> <code>getPort</code>: Returns the port number the KDC uses
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   114
 * <li> <code>getRealm</code>: Returns the realm name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   115
 * <li> <code>writeKtab</code>: Writes all principals' keys into a keytab file
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   116
 * <li> <code>saveConfig</code>: Saves a krb5.conf file to access this KDC
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   117
 * <li> <code>setOption</code>: Sets various options
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   118
 * </ul>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   119
 * Read the javadoc for details. Lazy developer can use <code>OneKDC</code>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   120
 * directly.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   121
 */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   122
public class KDC {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   123
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   124
    public static final int DEFAULT_LIFETIME = 39600;
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   125
    public static final int DEFAULT_RENEWTIME = 86400;
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   126
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   127
    // Under the hood.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   128
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   129
    // The random generator to generate random keys (including session keys)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   130
    private static SecureRandom secureRandom = new SecureRandom();
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   131
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   132
    // Principal db. principal -> pass. A case-insensitive TreeMap is used
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   133
    // so that even if the client provides a name with different case, the KDC
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   134
    // can still locate the principal and give back correct salt.
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   135
    private TreeMap<String,char[]> passwords = new TreeMap<>
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   136
            (String.CASE_INSENSITIVE_ORDER);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   137
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   138
    // Realm name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   139
    private String realm;
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   140
    // KDC
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   141
    private String kdc;
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   142
    // Service port number
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   143
    private int port;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   144
    // The request/response job queue
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   145
    private BlockingQueue<Job> q = new ArrayBlockingQueue<>(100);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   146
    // Options
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   147
    private Map<Option,Object> options = new HashMap<>();
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   148
    // Realm-specific krb5.conf settings
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   149
    private List<String> conf = new ArrayList<>();
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   150
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
   151
    private Thread thread1, thread2, thread3;
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
   152
    private volatile boolean udpConsumerReady = false;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
   153
    private volatile boolean tcpConsumerReady = false;
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
   154
    private volatile boolean dispatcherReady = false;
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
   155
    DatagramSocket u1 = null;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
   156
    ServerSocket t1 = null;
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
   157
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   158
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   159
     * Option names, to be expanded forever.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   160
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   161
    public static enum Option {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   162
        /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   163
         * Whether pre-authentication is required. Default Boolean.TRUE
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   164
         */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   165
        PREAUTH_REQUIRED,
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   166
        /**
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   167
         * Only issue TGT in RC4
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   168
         */
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   169
        ONLY_RC4_TGT,
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   170
        /**
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   171
         * Use RC4 as the first in preauth
5802
ea99d72d3c19 6959292: regression: cannot login if session key and preauth does not use the same etype
weijun
parents: 5774
diff changeset
   172
         */
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   173
        RC4_FIRST_PREAUTH,
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   174
        /**
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   175
         * Use only one preauth, so that some keys are not easy to generate
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   176
         */
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   177
        ONLY_ONE_PREAUTH,
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   178
        /**
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   179
         * Set all name-type to a value in response
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   180
         */
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   181
        RESP_NT,
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   182
        /**
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   183
         * Multiple ETYPE-INFO-ENTRY with same etype but different salt
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   184
         */
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   185
        DUP_ETYPE,
12867
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   186
        /**
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   187
         * What backend server can be delegated to
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   188
         */
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   189
        OK_AS_DELEGATE,
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   190
        /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   191
         * Allow S4U2self, List<String> of middle servers.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   192
         * If not set, means KDC does not understand S4U2self at all, therefore
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   193
         * would ignore any PA-FOR-USER request and send a ticket using the
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   194
         * cname of teh requestor. If set, it returns FORWARDABLE tickets to
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   195
         * a server with its name in the list
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   196
         */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   197
        ALLOW_S4U2SELF,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   198
        /**
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   199
         * Allow S4U2proxy, Map<String,List<String>> of middle servers to
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   200
         * backends. If not set or a backend not in a server's list,
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   201
         * Krb5.KDC_ERR_POLICY will be send for S4U2proxy request.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   202
         */
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   203
        ALLOW_S4U2PROXY,
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   204
        /**
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   205
         * Sensitive accounts can never be delegated.
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   206
         */
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   207
        SENSITIVE_ACCOUNTS,
30959
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   208
        /**
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   209
         * If true, will check if TGS-REQ contains a non-null addresses field.
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   210
         */
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   211
        CHECK_ADDRESSES,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   212
    };
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   213
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   214
    static {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   215
        System.setProperty("sun.net.spi.nameservice.provider.1", "ns,mock");
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   216
    }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   217
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   218
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   219
     * A standalone KDC server.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   220
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   221
    public static void main(String[] args) throws Exception {
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   222
        int port = args.length > 0 ? Integer.parseInt(args[0]) : 0;
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   223
        KDC kdc = create("RABBIT.HOLE", "kdc.rabbit.hole", port, false);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   224
        kdc.addPrincipal("dummy", "bogus".toCharArray());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   225
        kdc.addPrincipal("foo", "bar".toCharArray());
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   226
        kdc.addPrincipalRandKey("krbtgt/RABBIT.HOLE");
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   227
        kdc.addPrincipalRandKey("server/host.rabbit.hole");
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   228
        kdc.addPrincipalRandKey("backend/host.rabbit.hole");
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   229
        KDC.saveConfig("krb5.conf", kdc, "forwardable = true");
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   230
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   231
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   232
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   233
     * Creates and starts a KDC running as a daemon on a random port.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   234
     * @param realm the realm name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   235
     * @return the running KDC instance
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   236
     * @throws java.io.IOException for any socket creation error
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   237
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   238
    public static KDC create(String realm) throws IOException {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   239
        return create(realm, "kdc." + realm.toLowerCase(), 0, true);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   240
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   241
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   242
    public static KDC existing(String realm, String kdc, int port) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   243
        KDC k = new KDC(realm, kdc);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   244
        k.port = port;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   245
        return k;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   246
    }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   247
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   248
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   249
     * Creates and starts a KDC server.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   250
     * @param realm the realm name
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   251
     * @param port the TCP and UDP port to listen to. A random port will to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   252
     *        chosen if zero.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   253
     * @param asDaemon if true, KDC threads will be daemons. Otherwise, not.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   254
     * @return the running KDC instance
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   255
     * @throws java.io.IOException for any socket creation error
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   256
     */
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   257
    public static KDC create(String realm, String kdc, int port, boolean asDaemon) throws IOException {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   258
        return new KDC(realm, kdc, port, asDaemon);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   259
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   260
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   261
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   262
     * Sets an option
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   263
     * @param key the option name
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   264
     * @param value the value
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   265
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   266
    public void setOption(Option key, Object value) {
12867
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   267
        if (value == null) {
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   268
            options.remove(key);
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   269
        } else {
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   270
            options.put(key, value);
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   271
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   272
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   273
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   274
    /**
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   275
     * Writes or appends keys into a keytab.
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   276
     * <p>
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   277
     * Attention: This is the most basic one of a series of methods below on
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   278
     * keytab creation or modification. All these methods reference krb5.conf
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   279
     * settings. If you need to modify krb5.conf or switch to another krb5.conf
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   280
     * later, please call <code>Config.refresh()</code> again. For example:
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   281
     * <pre>
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   282
     * kdc.writeKtab("/etc/kdc/ktab", true);  // Config is initialized,
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   283
     * System.setProperty("java.security.krb5.conf", "/home/mykrb5.conf");
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   284
     * Config.refresh();
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   285
     * </pre>
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   286
     * Inside this method there are 2 places krb5.conf is used:
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   287
     * <ol>
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   288
     * <li> (Fatal) Generating keys: EncryptionKey.acquireSecretKeys
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   289
     * <li> (Has workaround) Creating PrincipalName
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   290
     * </ol>
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   291
     * @param tab the keytab file name
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   292
     * @param append true if append, otherwise, overwrite.
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   293
     * @param names the names to write into, write all if names is empty
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   294
     */
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   295
    public void writeKtab(String tab, boolean append, String... names)
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   296
            throws IOException, KrbException {
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   297
        KeyTab ktab = append ? KeyTab.getInstance(tab) : KeyTab.create(tab);
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   298
        Iterable<String> entries =
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   299
                (names.length != 0) ? Arrays.asList(names): passwords.keySet();
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   300
        for (String name : entries) {
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   301
            char[] pass = passwords.get(name);
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   302
            int kvno = 0;
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   303
            if (Character.isDigit(pass[pass.length-1])) {
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   304
                kvno = pass[pass.length-1] - '0';
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   305
            }
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   306
            PrincipalName pn = new PrincipalName(name,
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   307
                        name.indexOf('/') < 0 ?
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   308
                            PrincipalName.KRB_NT_UNKNOWN :
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   309
                            PrincipalName.KRB_NT_SRV_HST);
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   310
            ktab.addEntry(pn,
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   311
                        getSalt(pn),
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   312
                        pass,
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   313
                        kvno,
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   314
                        true);
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   315
        }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   316
        ktab.save();
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   317
    }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   318
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   319
    /**
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   320
     * Writes all principals' keys from multiple KDCs into one keytab file.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   321
     * @throws java.io.IOException for any file output error
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   322
     * @throws sun.security.krb5.KrbException for any realm and/or principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   323
     *         name error.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   324
     */
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   325
    public static void writeMultiKtab(String tab, KDC... kdcs)
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   326
            throws IOException, KrbException {
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   327
        KeyTab.create(tab).save();      // Empty the old keytab
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   328
        appendMultiKtab(tab, kdcs);
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   329
    }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   330
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   331
    /**
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   332
     * Appends all principals' keys from multiple KDCs to one keytab file.
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   333
     */
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   334
    public static void appendMultiKtab(String tab, KDC... kdcs)
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   335
            throws IOException, KrbException {
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   336
        for (KDC kdc: kdcs) {
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   337
            kdc.writeKtab(tab, true);
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   338
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   339
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   340
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   341
    /**
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   342
     * Write a ktab for this KDC.
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   343
     */
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   344
    public void writeKtab(String tab) throws IOException, KrbException {
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   345
        writeKtab(tab, false);
2942
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   346
    }
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   347
37d9baeb7518 6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents: 1575
diff changeset
   348
    /**
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   349
     * Appends keys in this KDC to a ktab.
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   350
     */
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   351
    public void appendKtab(String tab) throws IOException, KrbException {
12199
3de38eedde69 7152176: More krb5 tests
weijun
parents: 11107
diff changeset
   352
        writeKtab(tab, true);
9499
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   353
    }
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   354
f3115698a012 6894072: always refresh keytab
weijun
parents: 9275
diff changeset
   355
    /**
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   356
     * Adds a new principal to this realm with a given password.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   357
     * @param user the principal's name. For a service principal, use the
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   358
     *        form of host/f.q.d.n
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   359
     * @param pass the password for the principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   360
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   361
    public void addPrincipal(String user, char[] pass) {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   362
        if (user.indexOf('@') < 0) {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   363
            user = user + "@" + realm;
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   364
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   365
        passwords.put(user, pass);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   366
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   367
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   368
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   369
     * Adds a new principal to this realm with a random password
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   370
     * @param user the principal's name. For a service principal, use the
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   371
     *        form of host/f.q.d.n
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   372
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   373
    public void addPrincipalRandKey(String user) {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   374
        addPrincipal(user, randomPassword());
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   375
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   376
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   377
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   378
     * Returns the name of this realm
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   379
     * @return the name of this realm
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   380
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   381
    public String getRealm() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   382
        return realm;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   383
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   384
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   385
    /**
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   386
     * Returns the name of kdc
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   387
     * @return the name of kdc
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   388
     */
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   389
    public String getKDC() {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   390
        return kdc;
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   391
    }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   392
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   393
    /**
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   394
     * Add realm-specific krb5.conf setting
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   395
     */
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   396
    public void addConf(String s) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   397
        conf.add(s);
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   398
    }
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   399
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   400
    /**
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   401
     * Writes a krb5.conf for one or more KDC that includes KDC locations for
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   402
     * each realm and the default realm name. You can also add extra strings
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   403
     * into the file. The method should be called like:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   404
     * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   405
     *   KDC.saveConfig("krb5.conf", kdc1, kdc2, ..., line1, line2, ...);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   406
     * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   407
     * Here you can provide one or more kdc# and zero or more line# arguments.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   408
     * The line# will be put after [libdefaults] and before [realms]. Therefore
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   409
     * you can append new lines into [libdefaults] and/or create your new
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   410
     * stanzas as well. Note that a newline character will be appended to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   411
     * each line# argument.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   412
     * <p>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   413
     * For example:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   414
     * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   415
     * KDC.saveConfig("krb5.conf", this);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   416
     * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   417
     * generates:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   418
     * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   419
     * [libdefaults]
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   420
     * default_realm = REALM.NAME
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   421
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   422
     * [realms]
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   423
     *   REALM.NAME = {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   424
     *     kdc = host:port_number
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   425
     *     # realm-specific settings
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   426
     *   }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   427
     * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   428
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   429
     * Another example:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   430
     * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   431
     * KDC.saveConfig("krb5.conf", kdc1, kdc2, "forwardable = true", "",
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   432
     *         "[domain_realm]",
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   433
     *         ".kdc1.com = KDC1.NAME");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   434
     * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   435
     * generates:
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   436
     * <pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   437
     * [libdefaults]
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   438
     * default_realm = KDC1.NAME
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   439
     * forwardable = true
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   440
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   441
     * [domain_realm]
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   442
     * .kdc1.com = KDC1.NAME
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   443
     *
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   444
     * [realms]
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   445
     *   KDC1.NAME = {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   446
     *     kdc = host:port1
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   447
     *   }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   448
     *   KDC2.NAME = {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   449
     *     kdc = host:port2
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   450
     *   }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   451
     * </pre>
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   452
     * @param file the name of the file to write into
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   453
     * @param kdc the first (and default) KDC
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   454
     * @param more more KDCs or extra lines (in their appearing order) to
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   455
     * insert into the krb5.conf file. This method reads each argument's type
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   456
     * to determine what it's for. This argument can be empty.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   457
     * @throws java.io.IOException for any file output error
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   458
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   459
    public static void saveConfig(String file, KDC kdc, Object... more)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   460
            throws IOException {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   461
        File f = new File(file);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   462
        StringBuffer sb = new StringBuffer();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   463
        sb.append("[libdefaults]\ndefault_realm = ");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   464
        sb.append(kdc.realm);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   465
        sb.append("\n");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   466
        for (Object o: more) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   467
            if (o instanceof String) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   468
                sb.append(o);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   469
                sb.append("\n");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   470
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   471
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   472
        sb.append("\n[realms]\n");
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   473
        sb.append(kdc.realmLine());
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   474
        for (Object o: more) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   475
            if (o instanceof KDC) {
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
   476
                sb.append(((KDC)o).realmLine());
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   477
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   478
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   479
        FileOutputStream fos = new FileOutputStream(f);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   480
        fos.write(sb.toString().getBytes());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   481
        fos.close();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   482
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   483
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   484
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   485
     * Returns the service port of the KDC server.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   486
     * @return the KDC service port
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   487
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   488
    public int getPort() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   489
        return port;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   490
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   491
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   492
    // Private helper methods
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   493
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   494
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   495
     * Private constructor, cannot be called outside.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   496
     * @param realm
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   497
     */
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   498
    private KDC(String realm, String kdc) {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   499
        this.realm = realm;
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   500
        this.kdc = kdc;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   501
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   502
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   503
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   504
     * A constructor that starts the KDC service also.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   505
     */
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   506
    protected KDC(String realm, String kdc, int port, boolean asDaemon)
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   507
            throws IOException {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   508
        this(realm, kdc);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   509
        startServer(port, asDaemon);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   510
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   511
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   512
     * Generates a 32-char random password
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   513
     * @return the password
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   514
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   515
    private static char[] randomPassword() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   516
        char[] pass = new char[32];
5622
2a600d13659a 6948287: KDC test strange knvo
weijun
parents: 5617
diff changeset
   517
        for (int i=0; i<31; i++)
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   518
            pass[i] = (char)secureRandom.nextInt();
5622
2a600d13659a 6948287: KDC test strange knvo
weijun
parents: 5617
diff changeset
   519
        // The last char cannot be a number, otherwise, keyForUser()
2a600d13659a 6948287: KDC test strange knvo
weijun
parents: 5617
diff changeset
   520
        // believes it's a sign of kvno
2a600d13659a 6948287: KDC test strange knvo
weijun
parents: 5617
diff changeset
   521
        pass[31] = 'Z';
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   522
        return pass;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   523
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   524
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   525
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   526
     * Generates a random key for the given encryption type.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   527
     * @param eType the encryption type
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   528
     * @return the generated key
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   529
     * @throws sun.security.krb5.KrbException for unknown/unsupported etype
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   530
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   531
    private static EncryptionKey generateRandomKey(int eType)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   532
            throws KrbException  {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   533
        // Is 32 enough for AES256? I should have generated the keys directly
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   534
        // but different cryptos have different rules on what keys are valid.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   535
        char[] pass = randomPassword();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   536
        String algo;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   537
        switch (eType) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   538
            case EncryptedData.ETYPE_DES_CBC_MD5: algo = "DES"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   539
            case EncryptedData.ETYPE_DES3_CBC_HMAC_SHA1_KD: algo = "DESede"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   540
            case EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96: algo = "AES128"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   541
            case EncryptedData.ETYPE_ARCFOUR_HMAC: algo = "ArcFourHMAC"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   542
            case EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96: algo = "AES256"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   543
            default: algo = "DES"; break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   544
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   545
        return new EncryptionKey(pass, "NOTHING", algo);    // Silly
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   546
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   547
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   548
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   549
     * Returns the password for a given principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   550
     * @param p principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   551
     * @return the password
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   552
     * @throws sun.security.krb5.KrbException when the principal is not inside
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   553
     *         the database.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   554
     */
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   555
    private char[] getPassword(PrincipalName p, boolean server)
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   556
            throws KrbException {
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   557
        String pn = p.toString();
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   558
        if (p.getRealmString() == null) {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   559
            pn = pn + "@" + getRealm();
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   560
        }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   561
        char[] pass = passwords.get(pn);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   562
        if (pass == null) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   563
            throw new KrbException(server?
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   564
                Krb5.KDC_ERR_S_PRINCIPAL_UNKNOWN:
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   565
                Krb5.KDC_ERR_C_PRINCIPAL_UNKNOWN, pn.toString());
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   566
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   567
        return pass;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   568
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   569
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   570
    /**
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   571
     * Returns the salt string for the principal.
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   572
     * @param p principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   573
     * @return the salt
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   574
     */
15006
10d6aacdd67f 8005447: default principal should act as anyone
weijun
parents: 14413
diff changeset
   575
    protected String getSalt(PrincipalName p) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   576
        String pn = p.toString();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   577
        if (p.getRealmString() == null) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   578
            pn = pn + "@" + getRealm();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   579
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   580
        if (passwords.containsKey(pn)) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   581
            try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   582
                // Find the principal name with correct case.
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   583
                p = new PrincipalName(passwords.ceilingEntry(pn).getKey());
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   584
            } catch (RealmException re) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   585
                // Won't happen
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   586
            }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   587
        }
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   588
        String s = p.getRealmString();
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   589
        if (s == null) s = getRealm();
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   590
        for (String n: p.getNameStrings()) {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   591
            s += n;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   592
        }
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
   593
        return s;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   594
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   595
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   596
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   597
     * Returns the key for a given principal of the given encryption type
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   598
     * @param p the principal
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   599
     * @param etype the encryption type
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   600
     * @param server looking for a server principal?
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   601
     * @return the key
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   602
     * @throws sun.security.krb5.KrbException for unknown/unsupported etype
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   603
     */
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   604
    private EncryptionKey keyForUser(PrincipalName p, int etype, boolean server)
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   605
            throws KrbException {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   606
        try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   607
            // Do not call EncryptionKey.acquireSecretKeys(), otherwise
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   608
            // the krb5.conf config file would be loaded.
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   609
            Integer kvno = null;
4532
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4531
diff changeset
   610
            // For service whose password ending with a number, use it as kvno.
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4531
diff changeset
   611
            // Kvno must be postive.
f39917c8cf46 6907425: JCK Kerberos tests fail since b77
weijun
parents: 4531
diff changeset
   612
            if (p.toString().indexOf('/') > 0) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   613
                char[] pass = getPassword(p, server);
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   614
                if (Character.isDigit(pass[pass.length-1])) {
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   615
                    kvno = pass[pass.length-1] - '0';
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   616
                }
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   617
            }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   618
            return new EncryptionKey(EncryptionKeyDotStringToKey(
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   619
                    getPassword(p, server), getSalt(p), null, etype),
4168
1a8d21bb898c 6893158: AP_REQ check should use key version number
weijun
parents: 3046
diff changeset
   620
                    etype, kvno);
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   621
        } catch (KrbException ke) {
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   622
            throw ke;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   623
        } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   624
            throw new RuntimeException(e);  // should not happen
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   625
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   626
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   627
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   628
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   629
     * Processes an incoming request and generates a response.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   630
     * @param in the request
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   631
     * @return the response
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   632
     * @throws java.lang.Exception for various errors
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   633
     */
21961
50019af27ca3 8028351: JWS doesn't get authenticated when using kerberos auth proxy
weijun
parents: 18536
diff changeset
   634
    protected byte[] processMessage(byte[] in) throws Exception {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   635
        if ((in[0] & 0x1f) == Krb5.KRB_AS_REQ)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   636
            return processAsReq(in);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   637
        else
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   638
            return processTgsReq(in);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   639
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   640
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   641
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   642
     * Processes a TGS_REQ and generates a TGS_REP (or KRB_ERROR)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   643
     * @param in the request
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   644
     * @return the response
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   645
     * @throws java.lang.Exception for various errors
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   646
     */
21961
50019af27ca3 8028351: JWS doesn't get authenticated when using kerberos auth proxy
weijun
parents: 18536
diff changeset
   647
    protected byte[] processTgsReq(byte[] in) throws Exception {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   648
        TGSReq tgsReq = new TGSReq(in);
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   649
        PrincipalName service = tgsReq.reqBody.sname;
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   650
        if (options.containsKey(KDC.Option.RESP_NT)) {
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
   651
            service = new PrincipalName((int)options.get(KDC.Option.RESP_NT),
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
   652
                    service.getNameStrings(), service.getRealm());
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   653
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   654
        try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   655
            System.out.println(realm + "> " + tgsReq.reqBody.cname +
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   656
                    " sends TGS-REQ for " +
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   657
                    service + ", " + tgsReq.reqBody.kdcOptions);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   658
            KDCReqBody body = tgsReq.reqBody;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   659
            int[] eTypes = KDCReqBodyDotEType(body);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   660
            int e2 = eTypes[0];     // etype for outgoing session key
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   661
            int e3 = eTypes[0];     // etype for outgoing ticket
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   662
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   663
            PAData[] pas = KDCReqDotPAData(tgsReq);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   664
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   665
            Ticket tkt = null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   666
            EncTicketPart etp = null;
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   667
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   668
            PrincipalName cname = null;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   669
            boolean allowForwardable = true;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   670
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   671
            if (pas == null || pas.length == 0) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   672
                throw new KrbException(Krb5.KDC_ERR_PADATA_TYPE_NOSUPP);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   673
            } else {
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   674
                PrincipalName forUserCName = null;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   675
                for (PAData pa: pas) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   676
                    if (pa.getType() == Krb5.PA_TGS_REQ) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   677
                        APReq apReq = new APReq(pa.getValue());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   678
                        EncryptedData ed = apReq.authenticator;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   679
                        tkt = apReq.ticket;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   680
                        int te = tkt.encPart.getEType();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   681
                        EncryptionKey kkey = keyForUser(tkt.sname, te, true);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   682
                        byte[] bb = tkt.encPart.decrypt(kkey, KeyUsage.KU_TICKET);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   683
                        DerInputStream derIn = new DerInputStream(bb);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   684
                        DerValue der = derIn.getDerValue();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   685
                        etp = new EncTicketPart(der.toByteArray());
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   686
                        // Finally, cname will be overwritten by PA-FOR-USER
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   687
                        // if it exists.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   688
                        cname = etp.cname;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   689
                        System.out.println(realm + "> presenting a ticket of "
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   690
                                + etp.cname + " to " + tkt.sname);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   691
                    } else if (pa.getType() == Krb5.PA_FOR_USER) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   692
                        if (options.containsKey(Option.ALLOW_S4U2SELF)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   693
                            PAForUserEnc p4u = new PAForUserEnc(
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   694
                                    new DerValue(pa.getValue()), null);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   695
                            forUserCName = p4u.name;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   696
                            System.out.println(realm + "> presenting a PA_FOR_USER "
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   697
                                    + " in the name of " + p4u.name);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   698
                        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   699
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   700
                }
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   701
                if (forUserCName != null) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   702
                    List<String> names = (List<String>)options.get(Option.ALLOW_S4U2SELF);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   703
                    if (!names.contains(cname.toString())) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   704
                        // Mimic the normal KDC behavior. When a server is not
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   705
                        // allowed to send S4U2self, do not send an error.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   706
                        // Instead, send a ticket which is useless later.
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   707
                        allowForwardable = false;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   708
                    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   709
                    cname = forUserCName;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   710
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   711
                if (tkt == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   712
                    throw new KrbException(Krb5.KDC_ERR_PADATA_TYPE_NOSUPP);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   713
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   714
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   715
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   716
            // Session key for original ticket, TGT
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   717
            EncryptionKey ckey = etp.key;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   718
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   719
            // Session key for session with the service
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   720
            EncryptionKey key = generateRandomKey(e2);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   721
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   722
            // Check time, TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   723
            KerberosTime till = body.till;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   724
            if (till == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   725
                throw new KrbException(Krb5.KDC_ERR_NEVER_VALID); // TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   726
            } else if (till.isZero()) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   727
                till = new KerberosTime(new Date().getTime() + 1000 * 3600 * 11);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   728
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   729
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   730
            boolean[] bFlags = new boolean[Krb5.TKT_OPTS_MAX+1];
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   731
            if (body.kdcOptions.get(KDCOptions.FORWARDABLE)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   732
                    && allowForwardable) {
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   733
                List<String> sensitives = (List<String>)
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   734
                        options.get(Option.SENSITIVE_ACCOUNTS);
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   735
                if (sensitives != null && sensitives.contains(cname.toString())) {
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   736
                    // Cannot make FORWARDABLE
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   737
                } else {
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   738
                    bFlags[Krb5.TKT_OPTS_FORWARDABLE] = true;
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   739
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   740
            }
30959
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   741
            if (options.containsKey(Option.CHECK_ADDRESSES)
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   742
                    && body.kdcOptions.get(KDCOptions.FORWARDED)
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   743
                    && body.addresses == null) {
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   744
                throw new KrbException(Krb5.KDC_ERR_BADOPTION);
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   745
            }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   746
            if (body.kdcOptions.get(KDCOptions.FORWARDED) ||
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   747
                    etp.flags.get(Krb5.TKT_OPTS_FORWARDED)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   748
                bFlags[Krb5.TKT_OPTS_FORWARDED] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   749
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   750
            if (body.kdcOptions.get(KDCOptions.RENEWABLE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   751
                bFlags[Krb5.TKT_OPTS_RENEWABLE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   752
                //renew = new KerberosTime(new Date().getTime() + 1000 * 3600 * 24 * 7);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   753
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   754
            if (body.kdcOptions.get(KDCOptions.PROXIABLE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   755
                bFlags[Krb5.TKT_OPTS_PROXIABLE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   756
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   757
            if (body.kdcOptions.get(KDCOptions.POSTDATED)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   758
                bFlags[Krb5.TKT_OPTS_POSTDATED] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   759
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   760
            if (body.kdcOptions.get(KDCOptions.ALLOW_POSTDATE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   761
                bFlags[Krb5.TKT_OPTS_MAY_POSTDATE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   762
            }
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   763
            if (body.kdcOptions.get(KDCOptions.CNAME_IN_ADDL_TKT)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   764
                if (!options.containsKey(Option.ALLOW_S4U2PROXY)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   765
                    // Don't understand CNAME_IN_ADDL_TKT
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   766
                    throw new KrbException(Krb5.KDC_ERR_BADOPTION);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   767
                } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   768
                    Map<String,List<String>> map = (Map<String,List<String>>)
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   769
                            options.get(Option.ALLOW_S4U2PROXY);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   770
                    Ticket second = KDCReqBodyDotFirstAdditionalTicket(body);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   771
                    EncryptionKey key2 = keyForUser(second.sname, second.encPart.getEType(), true);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   772
                    byte[] bb = second.encPart.decrypt(key2, KeyUsage.KU_TICKET);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   773
                    DerInputStream derIn = new DerInputStream(bb);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   774
                    DerValue der = derIn.getDerValue();
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   775
                    EncTicketPart tktEncPart = new EncTicketPart(der.toByteArray());
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   776
                    if (!tktEncPart.flags.get(Krb5.TKT_OPTS_FORWARDABLE)) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   777
                        //throw new KrbException(Krb5.KDC_ERR_BADOPTION);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   778
                    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   779
                    PrincipalName client = tktEncPart.cname;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   780
                    System.out.println(realm + "> and an additional ticket of "
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   781
                            + client + " to " + second.sname);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   782
                    if (map.containsKey(cname.toString())) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   783
                        if (map.get(cname.toString()).contains(service.toString())) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   784
                            System.out.println(realm + "> S4U2proxy OK");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   785
                        } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   786
                            throw new KrbException(Krb5.KDC_ERR_BADOPTION);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   787
                        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   788
                    } else {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   789
                        throw new KrbException(Krb5.KDC_ERR_BADOPTION);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   790
                    }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   791
                    cname = client;
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   792
                }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   793
            }
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   794
12867
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   795
            String okAsDelegate = (String)options.get(Option.OK_AS_DELEGATE);
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   796
            if (okAsDelegate != null && (
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   797
                    okAsDelegate.isEmpty() ||
5492127ab0a8 7172701: KDC tests cleanup
weijun
parents: 12199
diff changeset
   798
                    okAsDelegate.contains(service.getNameString()))) {
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   799
                bFlags[Krb5.TKT_OPTS_DELEGATE] = true;
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   800
            }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   801
            bFlags[Krb5.TKT_OPTS_INITIAL] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   802
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   803
            TicketFlags tFlags = new TicketFlags(bFlags);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   804
            EncTicketPart enc = new EncTicketPart(
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   805
                    tFlags,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   806
                    key,
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   807
                    cname,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   808
                    new TransitedEncoding(1, new byte[0]),  // TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   809
                    new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   810
                    body.from,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   811
                    till, body.rtime,
30959
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   812
                    body.addresses != null ? body.addresses
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   813
                            : etp.caddr,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   814
                    null);
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   815
            EncryptionKey skey = keyForUser(service, e3, true);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   816
            if (skey == null) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   817
                throw new KrbException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); // TODO
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   818
            }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   819
            Ticket t = new Ticket(
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   820
                    service,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   821
                    new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   822
            );
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   823
            EncTGSRepPart enc_part = new EncTGSRepPart(
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   824
                    key,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   825
                    new LastReq(new LastReqEntry[]{
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   826
                        new LastReqEntry(0, new KerberosTime(new Date().getTime() - 10000))
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   827
                    }),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   828
                    body.getNonce(),    // TODO: detect replay
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   829
                    new KerberosTime(new Date().getTime() + 1000 * 3600 * 24),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   830
                    // Next 5 and last MUST be same with ticket
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   831
                    tFlags,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   832
                    new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   833
                    body.from,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   834
                    till, body.rtime,
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   835
                    service,
30959
14e1b420cdd6 8031111: fix krb5 caddr
weijun
parents: 30038
diff changeset
   836
                    body.addresses
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   837
                    );
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   838
            EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_TGS_REP_PART_SESSKEY);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   839
            TGSRep tgsRep = new TGSRep(null,
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
   840
                    cname,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   841
                    t,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   842
                    edata);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   843
            System.out.println("     Return " + tgsRep.cname
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   844
                    + " ticket for " + tgsRep.ticket.sname + ", flags "
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   845
                    + tFlags);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   846
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   847
            DerOutputStream out = new DerOutputStream();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   848
            out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   849
                    true, (byte)Krb5.KRB_TGS_REP), tgsRep.asn1Encode());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   850
            return out.toByteArray();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   851
        } catch (KrbException ke) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   852
            ke.printStackTrace(System.out);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   853
            KRBError kerr = ke.getError();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   854
            KDCReqBody body = tgsReq.reqBody;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   855
            System.out.println("     Error " + ke.returnCode()
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   856
                    + " " +ke.returnCodeMessage());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   857
            if (kerr == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   858
                kerr = new KRBError(null, null, null,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   859
                        new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   860
                        0,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   861
                        ke.returnCode(),
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
   862
                        body.cname,
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
   863
                        service,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   864
                        KrbException.errorMessage(ke.returnCode()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   865
                        null);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   866
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   867
            return kerr.asn1Encode();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   868
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   869
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   870
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   871
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   872
     * Processes a AS_REQ and generates a AS_REP (or KRB_ERROR)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   873
     * @param in the request
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   874
     * @return the response
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   875
     * @throws java.lang.Exception for various errors
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   876
     */
21961
50019af27ca3 8028351: JWS doesn't get authenticated when using kerberos auth proxy
weijun
parents: 18536
diff changeset
   877
    protected byte[] processAsReq(byte[] in) throws Exception {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   878
        ASReq asReq = new ASReq(in);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   879
        int[] eTypes = null;
7977
f47f211cd627 7008713: diamond conversion of kerberos5 and security tools
smarks
parents: 7183
diff changeset
   880
        List<PAData> outPAs = new ArrayList<>();
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   881
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   882
        PrincipalName service = asReq.reqBody.sname;
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   883
        if (options.containsKey(KDC.Option.RESP_NT)) {
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   884
            service = new PrincipalName(service.getNameStrings(),
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   885
                    (int)options.get(KDC.Option.RESP_NT));
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   886
        }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   887
        try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   888
            System.out.println(realm + "> " + asReq.reqBody.cname +
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   889
                    " sends AS-REQ for " +
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   890
                    service + ", " + asReq.reqBody.kdcOptions);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   891
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   892
            KDCReqBody body = asReq.reqBody;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   893
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   894
            eTypes = KDCReqBodyDotEType(body);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   895
            int eType = eTypes[0];
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   896
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   897
            // Maybe server does not support aes256, but a kinit does
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   898
            if (!EType.isSupported(eType)) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   899
                if (eTypes.length < 2) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   900
                    throw new KrbException(Krb5.KDC_ERR_ETYPE_NOSUPP);
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   901
                }
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   902
                eType = eTypes[1];
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   903
            }
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   904
4336
4c792c19266e 6853328: Support OK-AS-DELEGATE flag
weijun
parents: 4168
diff changeset
   905
            EncryptionKey ckey = keyForUser(body.cname, eType, false);
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   906
            EncryptionKey skey = keyForUser(service, eType, true);
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   907
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   908
            if (options.containsKey(KDC.Option.ONLY_RC4_TGT)) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   909
                int tgtEType = EncryptedData.ETYPE_ARCFOUR_HMAC;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   910
                boolean found = false;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   911
                for (int i=0; i<eTypes.length; i++) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   912
                    if (eTypes[i] == tgtEType) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   913
                        found = true;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   914
                        break;
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   915
                    }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   916
                }
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   917
                if (!found) {
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   918
                    throw new KrbException(Krb5.KDC_ERR_ETYPE_NOSUPP);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   919
                }
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
   920
                skey = keyForUser(service, tgtEType, true);
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
   921
            }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   922
            if (ckey == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   923
                throw new KrbException(Krb5.KDC_ERR_ETYPE_NOSUPP);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   924
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   925
            if (skey == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   926
                throw new KrbException(Krb5.KDC_ERR_SUMTYPE_NOSUPP); // TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   927
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   928
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   929
            // Session key
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   930
            EncryptionKey key = generateRandomKey(eType);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   931
            // Check time, TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   932
            KerberosTime till = body.till;
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   933
            KerberosTime rtime = body.rtime;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   934
            if (till == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   935
                throw new KrbException(Krb5.KDC_ERR_NEVER_VALID); // TODO
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   936
            } else if (till.isZero()) {
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   937
                till = new KerberosTime(
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   938
                        new Date().getTime() + 1000 * DEFAULT_LIFETIME);
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   939
            }
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   940
            if (rtime == null && body.kdcOptions.get(KDCOptions.RENEWABLE)) {
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   941
                rtime = new KerberosTime(
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
   942
                        new Date().getTime() + 1000 * DEFAULT_RENEWTIME);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   943
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   944
            //body.from
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   945
            boolean[] bFlags = new boolean[Krb5.TKT_OPTS_MAX+1];
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   946
            if (body.kdcOptions.get(KDCOptions.FORWARDABLE)) {
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   947
                List<String> sensitives = (List<String>)
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   948
                        options.get(Option.SENSITIVE_ACCOUNTS);
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   949
                if (sensitives != null && sensitives.contains(body.cname.toString())) {
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   950
                    // Cannot make FORWARDABLE
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   951
                } else {
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   952
                    bFlags[Krb5.TKT_OPTS_FORWARDABLE] = true;
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
   953
                }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   954
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   955
            if (body.kdcOptions.get(KDCOptions.RENEWABLE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   956
                bFlags[Krb5.TKT_OPTS_RENEWABLE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   957
                //renew = new KerberosTime(new Date().getTime() + 1000 * 3600 * 24 * 7);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   958
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   959
            if (body.kdcOptions.get(KDCOptions.PROXIABLE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   960
                bFlags[Krb5.TKT_OPTS_PROXIABLE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   961
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   962
            if (body.kdcOptions.get(KDCOptions.POSTDATED)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   963
                bFlags[Krb5.TKT_OPTS_POSTDATED] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   964
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   965
            if (body.kdcOptions.get(KDCOptions.ALLOW_POSTDATE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   966
                bFlags[Krb5.TKT_OPTS_MAY_POSTDATE] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   967
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   968
            bFlags[Krb5.TKT_OPTS_INITIAL] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
   969
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
   970
            // Creating PA-DATA
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   971
            DerValue[] pas2 = null, pas = null;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   972
            if (options.containsKey(KDC.Option.DUP_ETYPE)) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   973
                int n = (Integer)options.get(KDC.Option.DUP_ETYPE);
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   974
                switch (n) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   975
                    case 1:     // customer's case in 7067974
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   976
                        pas2 = new DerValue[] {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   977
                            new DerValue(new ETypeInfo2(1, null, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   978
                            new DerValue(new ETypeInfo2(1, "", null).asn1Encode()),
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 15006
diff changeset
   979
                            new DerValue(new ETypeInfo2(1, realm, new byte[]{1}).asn1Encode()),
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   980
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   981
                        pas = new DerValue[] {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   982
                            new DerValue(new ETypeInfo(1, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   983
                            new DerValue(new ETypeInfo(1, "").asn1Encode()),
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 15006
diff changeset
   984
                            new DerValue(new ETypeInfo(1, realm).asn1Encode()),
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   985
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   986
                        break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   987
                    case 2:     // we still reject non-null s2kparams and prefer E2 over E
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   988
                        pas2 = new DerValue[] {
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 15006
diff changeset
   989
                            new DerValue(new ETypeInfo2(1, realm, new byte[]{1}).asn1Encode()),
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   990
                            new DerValue(new ETypeInfo2(1, null, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   991
                            new DerValue(new ETypeInfo2(1, "", null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   992
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   993
                        pas = new DerValue[] {
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 15006
diff changeset
   994
                            new DerValue(new ETypeInfo(1, realm).asn1Encode()),
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   995
                            new DerValue(new ETypeInfo(1, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   996
                            new DerValue(new ETypeInfo(1, "").asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   997
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   998
                        break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
   999
                    case 3:     // but only E is wrong
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1000
                        pas = new DerValue[] {
16504
1e8ff2df7152 8009875: Provide a default udp_preference_limit for krb5.conf
weijun
parents: 15006
diff changeset
  1001
                            new DerValue(new ETypeInfo(1, realm).asn1Encode()),
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1002
                            new DerValue(new ETypeInfo(1, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1003
                            new DerValue(new ETypeInfo(1, "").asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1004
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1005
                        break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1006
                    case 4:     // we also ignore rc4-hmac
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1007
                        pas = new DerValue[] {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1008
                            new DerValue(new ETypeInfo(23, "ANYTHING").asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1009
                            new DerValue(new ETypeInfo(1, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1010
                            new DerValue(new ETypeInfo(1, "").asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1011
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1012
                        break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1013
                    case 5:     // "" should be wrong, but we accept it now
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1014
                                // See s.s.k.internal.PAData$SaltAndParams
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1015
                        pas = new DerValue[] {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1016
                            new DerValue(new ETypeInfo(1, "").asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1017
                            new DerValue(new ETypeInfo(1, null).asn1Encode()),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1018
                        };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1019
                        break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1020
                }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1021
            } else {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1022
                int[] epas = eTypes;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1023
                if (options.containsKey(KDC.Option.RC4_FIRST_PREAUTH)) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1024
                    for (int i=1; i<epas.length; i++) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1025
                        if (epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1026
                            epas[i] = epas[0];
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1027
                            epas[0] = EncryptedData.ETYPE_ARCFOUR_HMAC;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1028
                            break;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1029
                        }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1030
                    };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1031
                } else if (options.containsKey(KDC.Option.ONLY_ONE_PREAUTH)) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1032
                    epas = new int[] { eTypes[0] };
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1033
                }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1034
                pas2 = new DerValue[epas.length];
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1035
                for (int i=0; i<epas.length; i++) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1036
                    pas2[i] = new DerValue(new ETypeInfo2(
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1037
                            epas[i],
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1038
                            epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1039
                                null : getSalt(body.cname),
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1040
                            null).asn1Encode());
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1041
                }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1042
                boolean allOld = true;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1043
                for (int i: eTypes) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1044
                    if (i == EncryptedData.ETYPE_AES128_CTS_HMAC_SHA1_96 ||
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1045
                            i == EncryptedData.ETYPE_AES256_CTS_HMAC_SHA1_96) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1046
                        allOld = false;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1047
                        break;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1048
                    }
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1049
                }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1050
                if (allOld) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1051
                    pas = new DerValue[epas.length];
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1052
                    for (int i=0; i<epas.length; i++) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1053
                        pas[i] = new DerValue(new ETypeInfo(
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1054
                                epas[i],
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1055
                                epas[i] == EncryptedData.ETYPE_ARCFOUR_HMAC ?
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1056
                                    null : getSalt(body.cname)
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1057
                                ).asn1Encode());
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1058
                    }
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1059
                }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1060
            }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1061
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1062
            DerOutputStream eid;
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1063
            if (pas2 != null) {
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1064
                eid = new DerOutputStream();
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1065
                eid.putSequence(pas2);
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1066
                outPAs.add(new PAData(Krb5.PA_ETYPE_INFO2, eid.toByteArray()));
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1067
            }
10432
ef33e56c55a9 7067974: multiple ETYPE-INFO-ENTRY with same etype and different salt
weijun
parents: 10141
diff changeset
  1068
            if (pas != null) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1069
                eid = new DerOutputStream();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1070
                eid.putSequence(pas);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1071
                outPAs.add(new PAData(Krb5.PA_ETYPE_INFO, eid.toByteArray()));
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1072
            }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1073
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1074
            PAData[] inPAs = KDCReqDotPAData(asReq);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1075
            if (inPAs == null || inPAs.length == 0) {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1076
                Object preauth = options.get(Option.PREAUTH_REQUIRED);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1077
                if (preauth == null || preauth.equals(Boolean.TRUE)) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1078
                    throw new KrbException(Krb5.KDC_ERR_PREAUTH_REQUIRED);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1079
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1080
            } else {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1081
                try {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1082
                    EncryptedData data = newEncryptedData(new DerValue(inPAs[0].getValue()));
5774
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
  1083
                    EncryptionKey pakey = keyForUser(body.cname, data.getEType(), false);
4b9857e483c1 6951366: kerberos login failure on win2008 with AD set to win2000 compat mode
weijun
parents: 5627
diff changeset
  1084
                    data.decrypt(pakey, KeyUsage.KU_PA_ENC_TS);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1085
                } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1086
                    throw new KrbException(Krb5.KDC_ERR_PREAUTH_FAILED);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1087
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1088
                bFlags[Krb5.TKT_OPTS_PRE_AUTHENT] = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1089
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1090
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1091
            TicketFlags tFlags = new TicketFlags(bFlags);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1092
            EncTicketPart enc = new EncTicketPart(
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1093
                    tFlags,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1094
                    key,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1095
                    body.cname,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1096
                    new TransitedEncoding(1, new byte[0]),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1097
                    new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1098
                    body.from,
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
  1099
                    till, rtime,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1100
                    body.addresses,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1101
                    null);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1102
            Ticket t = new Ticket(
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
  1103
                    service,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1104
                    new EncryptedData(skey, enc.asn1Encode(), KeyUsage.KU_TICKET)
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1105
            );
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1106
            EncASRepPart enc_part = new EncASRepPart(
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1107
                    key,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1108
                    new LastReq(new LastReqEntry[]{
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1109
                        new LastReqEntry(0, new KerberosTime(new Date().getTime() - 10000))
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1110
                    }),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1111
                    body.getNonce(),    // TODO: detect replay?
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1112
                    new KerberosTime(new Date().getTime() + 1000 * 3600 * 24),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1113
                    // Next 5 and last MUST be same with ticket
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1114
                    tFlags,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1115
                    new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1116
                    body.from,
27946
9f99b93cbbb2 8044500: Add kinit options and krb5.conf flags that allow users to obtain renewable tickets and specify ticket lifetimes
weijun
parents: 24631
diff changeset
  1117
                    till, rtime,
10141
664ba64d2472 7061379: [Kerberos] Cross-realm authentication fails, due to nameType problem
weijun
parents: 9499
diff changeset
  1118
                    service,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1119
                    body.addresses
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1120
                    );
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1121
            EncryptedData edata = new EncryptedData(ckey, enc_part.asn1Encode(), KeyUsage.KU_ENC_AS_REP_PART);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1122
            ASRep asRep = new ASRep(
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1123
                    outPAs.toArray(new PAData[outPAs.size()]),
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1124
                    body.cname,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1125
                    t,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1126
                    edata);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1127
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1128
            System.out.println("     Return " + asRep.cname
28670
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
  1129
                    + " ticket for " + asRep.ticket.sname + ", flags "
bb9afe681988 8022582: Relax response flags checking in sun.security.krb5.KrbKdcRep.check.
weijun
parents: 27946
diff changeset
  1130
                    + tFlags);
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1131
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1132
            DerOutputStream out = new DerOutputStream();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1133
            out.write(DerValue.createTag(DerValue.TAG_APPLICATION,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1134
                    true, (byte)Krb5.KRB_AS_REP), asRep.asn1Encode());
1575
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1135
            byte[] result = out.toByteArray();
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1136
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1137
            // Added feature:
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1138
            // Write the current issuing TGT into a ccache file specified
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1139
            // by the system property below.
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1140
            String ccache = System.getProperty("test.kdc.save.ccache");
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1141
            if (ccache != null) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1142
                asRep.encKDCRepPart = enc_part;
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1143
                sun.security.krb5.internal.ccache.Credentials credentials =
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1144
                    new sun.security.krb5.internal.ccache.Credentials(asRep);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1145
                CredentialsCache cache =
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1146
                    CredentialsCache.create(asReq.reqBody.cname, ccache);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1147
                if (cache == null) {
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1148
                   throw new IOException("Unable to create the cache file " +
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1149
                                         ccache);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1150
                }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1151
                cache.update(credentials);
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1152
                cache.save();
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1153
            }
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1154
e0f1979051b5 6765491: Krb5LoginModule a little too restrictive, and the doc is not clear.
weijun
parents: 1456
diff changeset
  1155
            return result;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1156
        } catch (KrbException ke) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1157
            ke.printStackTrace(System.out);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1158
            KRBError kerr = ke.getError();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1159
            KDCReqBody body = asReq.reqBody;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1160
            System.out.println("     Error " + ke.returnCode()
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1161
                    + " " +ke.returnCodeMessage());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1162
            byte[] eData = null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1163
            if (kerr == null) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1164
                if (ke.returnCode() == Krb5.KDC_ERR_PREAUTH_REQUIRED ||
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1165
                        ke.returnCode() == Krb5.KDC_ERR_PREAUTH_FAILED) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1166
                    DerOutputStream bytes = new DerOutputStream();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1167
                    bytes.write(new PAData(Krb5.PA_ENC_TIMESTAMP, new byte[0]).asn1Encode());
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1168
                    for (PAData p: outPAs) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1169
                        bytes.write(p.asn1Encode());
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1170
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1171
                    DerOutputStream temp = new DerOutputStream();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1172
                    temp.write(DerValue.tag_Sequence, bytes);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1173
                    eData = temp.toByteArray();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1174
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1175
                kerr = new KRBError(null, null, null,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1176
                        new KerberosTime(new Date()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1177
                        0,
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1178
                        ke.returnCode(),
13247
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
  1179
                        body.cname,
74902cfeb9c6 6966259: Make PrincipalName and Realm immutable
weijun
parents: 12867
diff changeset
  1180
                        service,
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1181
                        KrbException.errorMessage(ke.returnCode()),
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1182
                        eData);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1183
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1184
            return kerr.asn1Encode();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1185
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1186
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1187
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1188
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1189
     * Generates a line for a KDC to put inside [realms] of krb5.conf
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1190
     * @return REALM.NAME = { kdc = host:port etc }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1191
     */
24631
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1192
    private String realmLine() {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1193
        StringBuilder sb = new StringBuilder();
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1194
        sb.append(realm).append(" = {\n    kdc = ")
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1195
                .append(kdc).append(':').append(port).append('\n');
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1196
        for (String s: conf) {
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1197
            sb.append("    ").append(s).append('\n');
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1198
        }
dafd257bc7f3 8036779: sun.security.krb5.KdcComm interprets kdc_timeout as msec instead of sec
weijun
parents: 23010
diff changeset
  1199
        return sb.append("}\n").toString();
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1200
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1201
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1202
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1203
     * Start the KDC service. This server listens on both UDP and TCP using
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1204
     * the same port number. It uses three threads to deal with requests.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1205
     * They can be set to daemon threads if requested.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1206
     * @param port the port number to listen to. If zero, a random available
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1207
     *  port no less than 8000 will be chosen and used.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1208
     * @param asDaemon true if the KDC threads should be daemons
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1209
     * @throws java.io.IOException for any communication error
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1210
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1211
    protected void startServer(int port, boolean asDaemon) throws IOException {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1212
        if (port > 0) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1213
            u1 = new DatagramSocket(port, InetAddress.getByName("127.0.0.1"));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1214
            t1 = new ServerSocket(port);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1215
        } else {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1216
            while (true) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1217
                // Try to find a port number that's both TCP and UDP free
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1218
                try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1219
                    port = 8000 + new java.util.Random().nextInt(10000);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1220
                    u1 = null;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1221
                    u1 = new DatagramSocket(port, InetAddress.getByName("127.0.0.1"));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1222
                    t1 = new ServerSocket(port);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1223
                    break;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1224
                } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1225
                    if (u1 != null) u1.close();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1226
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1227
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1228
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1229
        final DatagramSocket udp = u1;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1230
        final ServerSocket tcp = t1;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1231
        System.out.println("Start KDC on " + port);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1232
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1233
        this.port = port;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1234
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1235
        // The UDP consumer
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1236
        thread1 = new Thread() {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1237
            public void run() {
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1238
                udpConsumerReady = true;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1239
                while (true) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1240
                    try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1241
                        byte[] inbuf = new byte[8192];
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1242
                        DatagramPacket p = new DatagramPacket(inbuf, inbuf.length);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1243
                        udp.receive(p);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1244
                        System.out.println("-----------------------------------------------");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1245
                        System.out.println(">>>>> UDP packet received");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1246
                        q.put(new Job(processMessage(Arrays.copyOf(inbuf, p.getLength())), udp, p));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1247
                    } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1248
                        e.printStackTrace();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1249
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1250
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1251
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1252
        };
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1253
        thread1.setDaemon(asDaemon);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1254
        thread1.start();
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1255
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1256
        // The TCP consumer
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1257
        thread2 = new Thread() {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1258
            public void run() {
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1259
                tcpConsumerReady = true;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1260
                while (true) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1261
                    try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1262
                        Socket socket = tcp.accept();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1263
                        System.out.println("-----------------------------------------------");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1264
                        System.out.println(">>>>> TCP connection established");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1265
                        DataInputStream in = new DataInputStream(socket.getInputStream());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1266
                        DataOutputStream out = new DataOutputStream(socket.getOutputStream());
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1267
                        byte[] token = new byte[in.readInt()];
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1268
                        in.readFully(token);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1269
                        q.put(new Job(processMessage(token), socket, out));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1270
                    } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1271
                        e.printStackTrace();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1272
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1273
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1274
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1275
        };
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1276
        thread2.setDaemon(asDaemon);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1277
        thread2.start();
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1278
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1279
        // The dispatcher
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1280
        thread3 = new Thread() {
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1281
            public void run() {
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1282
                dispatcherReady = true;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1283
                while (true) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1284
                    try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1285
                        q.take().send();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1286
                    } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1287
                    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1288
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1289
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1290
        };
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1291
        thread3.setDaemon(true);
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1292
        thread3.start();
30038
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1293
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1294
        // wait for the KDC is ready
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1295
        try {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1296
            while (!isReady()) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1297
                Thread.sleep(100);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1298
            }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1299
        } catch(InterruptedException e) {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1300
            throw new IOException(e);
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1301
        }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1302
    }
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1303
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1304
    boolean isReady() {
632939157af2 8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents: 28670
diff changeset
  1305
        return udpConsumerReady && tcpConsumerReady && dispatcherReady;
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1306
    }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1307
4531
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1308
    public void terminate() {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1309
        try {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1310
            thread1.stop();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1311
            thread2.stop();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1312
            thread3.stop();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1313
            u1.close();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1314
            t1.close();
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1315
        } catch (Exception e) {
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1316
            // OK
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1317
        }
3a9206343ab2 6843127: krb5 should not try to access unavailable kdc too often
weijun
parents: 4336
diff changeset
  1318
    }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1319
    /**
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1320
     * Helper class to encapsulate a job in a KDC.
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1321
     */
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1322
    private static class Job {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1323
        byte[] token;           // The received request at creation time and
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1324
                                // the response at send time
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1325
        Socket s;               // The TCP socket from where the request comes
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1326
        DataOutputStream out;   // The OutputStream of the TCP socket
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1327
        DatagramSocket s2;      // The UDP socket from where the request comes
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1328
        DatagramPacket dp;      // The incoming UDP datagram packet
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1329
        boolean useTCP;         // Whether TCP or UDP is used
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1330
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1331
        // Creates a job object for TCP
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1332
        Job(byte[] token, Socket s, DataOutputStream out) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1333
            useTCP = true;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1334
            this.token = token;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1335
            this.s = s;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1336
            this.out = out;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1337
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1338
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1339
        // Creates a job object for UDP
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1340
        Job(byte[] token, DatagramSocket s2, DatagramPacket dp) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1341
            useTCP = false;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1342
            this.token = token;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1343
            this.s2 = s2;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1344
            this.dp = dp;
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1345
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1346
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1347
        // Sends the output back to the client
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1348
        void send() {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1349
            try {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1350
                if (useTCP) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1351
                    System.out.println(">>>>> TCP request honored");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1352
                    out.writeInt(token.length);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1353
                    out.write(token);
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1354
                    s.close();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1355
                } else {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1356
                    System.out.println(">>>>> UDP request honored");
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1357
                    s2.send(new DatagramPacket(token, token.length, dp.getAddress(), dp.getPort()));
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1358
                }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1359
            } catch (Exception e) {
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1360
                e.printStackTrace();
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1361
            }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1362
        }
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1363
    }
3046
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1364
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1365
    public static class KDCNameService implements NameServiceDescriptor {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1366
        @Override
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1367
        public NameService createNameService() throws Exception {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1368
            NameService ns = new NameService() {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1369
                @Override
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1370
                public InetAddress[] lookupAllHostAddr(String host)
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1371
                        throws UnknownHostException {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1372
                    // Everything is localhost
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1373
                    return new InetAddress[]{
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1374
                        InetAddress.getByAddress(host, new byte[]{127,0,0,1})
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1375
                    };
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1376
                }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1377
                @Override
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1378
                public String getHostByAddr(byte[] addr)
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1379
                        throws UnknownHostException {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1380
                    // No reverse lookup, PrincipalName use original string
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1381
                    throw new UnknownHostException();
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1382
                }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1383
            };
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1384
            return ns;
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1385
        }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1386
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1387
        @Override
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1388
        public String getProviderName() {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1389
            return "mock";
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1390
        }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1391
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1392
        @Override
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1393
        public String getType() {
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1394
            return "ns";
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1395
        }
dd50d75d88e6 6849275: enhance krb5 reg tests
weijun
parents: 2942
diff changeset
  1396
    }
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1397
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1398
    // Calling private methods thru reflections
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1399
    private static final Field getPADataField;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1400
    private static final Field getEType;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1401
    private static final Constructor<EncryptedData> ctorEncryptedData;
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1402
    private static final Method stringToKey;
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1403
    private static final Field getAddlTkt;
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1404
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1405
    static {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1406
        try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1407
            ctorEncryptedData = EncryptedData.class.getDeclaredConstructor(DerValue.class);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1408
            ctorEncryptedData.setAccessible(true);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1409
            getPADataField = KDCReq.class.getDeclaredField("pAData");
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1410
            getPADataField.setAccessible(true);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1411
            getEType = KDCReqBody.class.getDeclaredField("eType");
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1412
            getEType.setAccessible(true);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1413
            stringToKey = EncryptionKey.class.getDeclaredMethod(
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1414
                    "stringToKey",
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1415
                    char[].class, String.class, byte[].class, Integer.TYPE);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1416
            stringToKey.setAccessible(true);
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1417
            getAddlTkt = KDCReqBody.class.getDeclaredField("additionalTickets");
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1418
            getAddlTkt.setAccessible(true);
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1419
        } catch (NoSuchFieldException nsfe) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1420
            throw new AssertionError(nsfe);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1421
        } catch (NoSuchMethodException nsme) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1422
            throw new AssertionError(nsme);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1423
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1424
    }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1425
    private EncryptedData newEncryptedData(DerValue der) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1426
        try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1427
            return ctorEncryptedData.newInstance(der);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1428
        } catch (Exception e) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1429
            throw new AssertionError(e);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1430
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1431
    }
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1432
    private static PAData[] KDCReqDotPAData(KDCReq req) {
7183
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1433
        try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1434
            return (PAData[])getPADataField.get(req);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1435
        } catch (Exception e) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1436
            throw new AssertionError(e);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1437
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1438
    }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1439
    private static int[] KDCReqBodyDotEType(KDCReqBody body) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1440
        try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1441
            return (int[]) getEType.get(body);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1442
        } catch (Exception e) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1443
            throw new AssertionError(e);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1444
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1445
    }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1446
    private static byte[] EncryptionKeyDotStringToKey(char[] password, String salt,
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1447
            byte[] s2kparams, int keyType) throws KrbCryptoException {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1448
        try {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1449
            return (byte[])stringToKey.invoke(
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1450
                    null, password, salt, s2kparams, keyType);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1451
        } catch (InvocationTargetException ex) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1452
            throw (KrbCryptoException)ex.getCause();
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1453
        } catch (Exception e) {
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1454
            throw new AssertionError(e);
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1455
        }
d8ccc1c73358 6960894: Better AS-REQ creation and processing
weijun
parents: 7037
diff changeset
  1456
    }
14413
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1457
    private static Ticket KDCReqBodyDotFirstAdditionalTicket(KDCReqBody body) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1458
        try {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1459
            return ((Ticket[])getAddlTkt.get(body))[0];
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1460
        } catch (Exception e) {
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1461
            throw new AssertionError(e);
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1462
        }
e954df027393 6355584: Introduce constrained Kerberos delegation
weijun
parents: 13247
diff changeset
  1463
    }
1454
d9b6f1de641f 6706974: Add krb5 test infrastructure
weijun
parents:
diff changeset
  1464
}