test/jdk/sun/security/krb5/auto/ReplayCacheTestProc.java
author weijun
Mon, 22 Jan 2018 12:00:41 +0800
changeset 48651 67abfee27e69
parent 47216 71c04702a3d5
child 48668 2da4a52715d8
permissions -rw-r--r--
8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     1
/*
48651
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     4
 *
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     8
 *
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    13
 * accompanied this code).
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    14
 *
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    18
 *
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    21
 * questions.
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    22
 */
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    23
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    24
/*
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    25
 * @test
48651
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
    26
 * @bug 7152176 8168518 8172017 8014628
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    27
 * @summary More krb5 tests
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    28
 * @library ../../../../java/security/testlibrary/ /test/lib
45467
99c87a16a8e4 8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents: 42998
diff changeset
    29
 * @build jdk.test.lib.Platform
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    30
 * @run main/othervm/timeout=300 ReplayCacheTestProc
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    31
 */
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    32
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    33
import java.io.*;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    34
import java.nio.BufferUnderflowException;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    35
import java.nio.channels.SeekableByteChannel;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    36
import java.nio.file.Files;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    37
import java.nio.file.Paths;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    38
import java.nio.file.StandardCopyOption;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    39
import java.nio.file.StandardOpenOption;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    40
import java.security.MessageDigest;
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    41
import java.security.NoSuchAlgorithmException;
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    42
import java.util.*;
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    43
import java.util.regex.Matcher;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    44
import java.util.regex.Pattern;
24271
19000122bb5e 8039951: com.sun.security.auth.module missing classes on some platforms
weijun
parents: 18826
diff changeset
    45
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    46
import jdk.test.lib.Platform;
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    47
import sun.security.jgss.GSSUtil;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    48
import sun.security.krb5.internal.rcache.AuthTime;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    49
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    50
/**
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    51
 * This test runs multiple acceptor Procs to mimic AP-REQ replays.
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    52
 * These system properties are supported:
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    53
 *
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    54
 * - test.libs on what types of acceptors to use
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    55
 *   Format: CSV of (J|N|N<suffix>=<libname>|J<suffix>=<launcher>)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    56
 *   Default: J,N on Solaris and Linux where N is available, or J
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    57
 *   Example: J,N,N14=/krb5-1.14/lib/libgssapi_krb5.so,J8=/java8/bin/java
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    58
 *
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    59
 * - test.runs on manual runs. If empty, a iterate through all pattern
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    60
 *   Format: (req# | client# service#) acceptor# expected, ...
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    61
 *   Default: null
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    62
 *   Example: c0s0Jav,c1s1N14av,r0Jbx means 0th req is new c0->s0 sent to Ja,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    63
 *            1st req is new c1 to s1 sent to N14a,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    64
 *            2nd req is old (0th replayed) sent to Jb.
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    65
 *            a/b at the end of acceptor is different acceptors of the same lib
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    66
 *
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    67
 * - test.autoruns on number of automatic runs
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    68
 *   Format: number
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    69
 *   Default: 100
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    70
 */
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    71
public class ReplayCacheTestProc {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    72
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    73
    private static Proc[] pa;   // all acceptors
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
    74
    private static Proc pi;     // the single initiator
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    75
    private static List<Req> reqs = new ArrayList<>();
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    76
    private static String HOST = "localhost";
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
    77
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    78
    private static final String SERVICE;
42998
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    79
    private static long uid;
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    80
    private static String cwd;
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    81
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    82
    static {
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    83
        String tmp = System.getProperty("test.service");
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    84
        SERVICE = (tmp == null) ? "service" : tmp;
42998
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    85
        uid = jdk.internal.misc.VM.geteuid();
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    86
        // Where should the rcache be saved. KRB5RCACHEDIR is not
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    87
        // recognized on Solaris (might be supported on Solaris 12),
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    88
        // and directory name is different when launched by root.
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    89
        // See manpage krb5envvar(5) on KRB5RCNAME.
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    90
        if (System.getProperty("os.name").startsWith("SunOS")) {
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    91
            if (uid == 0) {
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    92
                cwd = "/var/krb5/rcache/root/";
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    93
            } else {
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    94
                cwd = "/var/krb5/rcache/";
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    95
            }
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    96
        } else {
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    97
            cwd = System.getProperty("user.dir");
1a5bb301d855 8172017: Two tests sun/security/krb5/auto/ReplayCacheTestProc.java and rcache_usemd5.sh fail on Solaris
weijun
parents: 42108
diff changeset
    98
        }
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
    99
    }
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
   100
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   101
    private static MessageDigest md5, sha256;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   102
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   103
    static {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   104
        try {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   105
            md5 = MessageDigest.getInstance("MD5");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   106
            sha256 = MessageDigest.getInstance("SHA-256");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   107
        } catch (NoSuchAlgorithmException nsae) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   108
            throw new AssertionError("Impossible", nsae);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   109
        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   110
    }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   111
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   112
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   113
    public static void main0(String[] args) throws Exception {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   114
        System.setProperty("java.security.krb5.conf", OneKDC.KRB5_CONF);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   115
        if (args.length == 0) { // The controller
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   116
            int nc = 5;     // number of clients
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   117
            int ns = 5;     // number of services
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   118
            String[] libs;  // available acceptor types:
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   119
                            // J: java
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   120
                            // J<suffix>=<java launcher>: another java
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   121
                            // N: default native lib
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   122
                            // N<suffix>=<libname>: another native lib
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   123
            Ex[] result;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   124
            int numPerType = 2; // number of acceptors per type
18542
7b1fa08a804e 8017453: ReplayCache tests fail on multiple platforms
weijun
parents: 18536
diff changeset
   125
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   126
            KDC kdc = KDC.create(OneKDC.REALM, HOST, 0, true);
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   127
            for (int i=0; i<nc; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   128
                kdc.addPrincipal(client(i), OneKDC.PASS);
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   129
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   130
            kdc.addPrincipalRandKey("krbtgt/" + OneKDC.REALM);
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   131
            for (int i=0; i<ns; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   132
                kdc.addPrincipalRandKey(service(i));
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   133
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   134
48651
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   135
            // Native lib might not support aes-sha2
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   136
            KDC.saveConfig(OneKDC.KRB5_CONF, kdc,
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   137
                    "default_tkt_enctypes = aes128-cts",
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   138
                    "default_tgs_enctypes = aes128-cts");
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   139
67abfee27e69 8014628: Support AES Encryption with HMAC-SHA2 for Kerberos 5
weijun
parents: 47216
diff changeset
   140
            // Write KTAB after krb5.conf so it contains no aes-sha2 keys
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   141
            kdc.writeKtab(OneKDC.KTAB);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   142
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   143
            // User-provided libs
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   144
            String userLibs = System.getProperty("test.libs");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   145
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   146
            if (userLibs != null) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   147
                libs = userLibs.split(",");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   148
            } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   149
                if (Platform.isOSX() || Platform.isWindows()) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   150
                    // macOS uses Heimdal and Windows has no native lib
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   151
                    libs = new String[]{"J"};
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   152
                } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   153
                    if (acceptor("N", "sanity").waitFor() != 0) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   154
                        Proc.d("Native mode sanity check failed, only java");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   155
                        libs = new String[]{"J"};
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   156
                    } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   157
                        libs = new String[]{"J", "N"};
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   158
                    }
18826
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   159
                }
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   160
            }
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   161
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   162
            pi = Proc.create("ReplayCacheTestProc").debug("C")
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   163
                    .args("initiator")
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   164
                    .start();
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   165
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   166
            int na = libs.length * numPerType;  // total number of acceptors
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   167
            pa = new Proc[na];
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   168
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   169
            // Acceptors, numPerType for 1st, numForType for 2nd, ...
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   170
            for (int i=0; i<na; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   171
                pa[i] = acceptor(libs[i/numPerType],
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   172
                        "" + (char)('a' + i%numPerType));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   173
            }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   174
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   175
            // Manual runs
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   176
            String userRuns = System.getProperty("test.runs");
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   177
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   178
            if (userRuns == null) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   179
                result = new Ex[Integer.parseInt(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   180
                        System.getProperty("test.autoruns", "100"))];
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   181
                Random r = new Random();
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   182
                for (int i = 0; i < result.length; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   183
                    boolean expected = reqs.isEmpty() || r.nextBoolean();
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   184
                    result[i] = new Ex(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   185
                            i,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   186
                            expected ?
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   187
                                    req(r.nextInt(nc), r.nextInt(ns)) :
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   188
                                    r.nextInt(reqs.size()),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   189
                            pa[r.nextInt(na)],
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   190
                            expected);
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   191
                }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   192
            } else if (userRuns.isEmpty()) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   193
                int count = 0;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   194
                result = new Ex[libs.length * libs.length];
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   195
                for (int i = 0; i < libs.length; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   196
                    result[count] = new Ex(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   197
                            count,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   198
                            req(0, 0),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   199
                            pa[i * numPerType],
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   200
                            true);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   201
                    count++;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   202
                    for (int j = 0; j < libs.length; j++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   203
                        if (i == j) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   204
                            continue;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   205
                        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   206
                        result[count] = new Ex(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   207
                                count,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   208
                                i,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   209
                                pa[j * numPerType],
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   210
                                false);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   211
                        count++;
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   212
                    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   213
                }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   214
            } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   215
                String[] runs = userRuns.split(",");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   216
                result = new Ex[runs.length];
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   217
                for (int i = 0; i < runs.length; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   218
                    UserRun run = new UserRun(runs[i]);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   219
                    result[i] = new Ex(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   220
                            i,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   221
                            run.req() == -1 ?
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   222
                                    req(run.client(), run.service()) :
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   223
                                    result[run.req()].req,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   224
                            Arrays.stream(pa)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   225
                                    .filter(p -> p.debug().equals(run.acceptor()))
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   226
                                    .findFirst()
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   227
                                    .orElseThrow(() -> new Exception(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   228
                                            "no acceptor named " + run.acceptor())),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   229
                            run.success());
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   230
                }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   231
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   232
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   233
            for (Ex x : result) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   234
                x.run();
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   235
            }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   236
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   237
            pi.println("END");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   238
            for (int i=0; i<na; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   239
                pa[i].println("END");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   240
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   241
            System.out.println("\nAll Test Results\n================");
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   242
            boolean finalOut = true;
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   243
            System.out.println("        req**  client    service  acceptor   Result");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   244
            System.out.println("----  -------  ------  ---------  --------  -------");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   245
            for (int i=0; i<result.length; i++) {
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   246
                boolean out = result[i].expected==result[i].actual;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   247
                finalOut &= out;
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   248
                System.out.printf("%3d:    %3d%s      c%d    s%d %4s  %8s   %s  %s\n",
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   249
                        i,
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   250
                        result[i].req,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   251
                        result[i].expected ? "**" : "  ",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   252
                        reqs.get(result[i].req).client,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   253
                        reqs.get(result[i].req).service,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   254
                        "(" + result[i].csize + ")",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   255
                        result[i].acceptor.debug(),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   256
                        result[i].actual ? "++" : "--",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   257
                        out ? "   " : "xxx");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   258
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   259
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   260
            System.out.println("\nPath of Reqs\n============");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   261
            for (int j=0; ; j++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   262
                boolean found = false;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   263
                for (int i=0; i<result.length; i++) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   264
                    if (result[i].req == j) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   265
                        if (!found) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   266
                            System.out.printf("%3d (c%s -> s%s): ", j,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   267
                                    reqs.get(j).client, reqs.get(j).service);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   268
                        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   269
                        System.out.printf("%s%s(%d)%s",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   270
                                found ? " -> " : "",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   271
                                result[i].acceptor.debug(),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   272
                                i,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   273
                                result[i].actual != result[i].expected ?
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   274
                                        "xxx" : "");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   275
                        found = true;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   276
                    }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   277
                }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   278
                System.out.println();
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   279
                if (!found) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   280
                    break;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   281
                }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   282
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   283
            if (!finalOut) throw new Exception();
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   284
        } else if (args[0].equals("Nsanity")) {
18826
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   285
            // Native mode sanity check
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   286
            Proc.d("Detect start");
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   287
            Context s = Context.fromUserKtab("*", OneKDC.KTAB, true);
aba6cde7fafb 8019410: sun/security/krb5/auto/ReplayCacheTestProc.java
weijun
parents: 18542
diff changeset
   288
            s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   289
        } else if (args[0].equals("initiator")) {
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   290
            while (true) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   291
                String title = Proc.textIn();
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   292
                Proc.d("Client see " + title);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   293
                if (title.equals("END")) break;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   294
                String[] cas = title.split(" ");
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   295
                Context c = Context.fromUserPass(cas[0], OneKDC.PASS, false);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   296
                c.startAsClient(cas[1], GSSUtil.GSS_KRB5_MECH_OID);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   297
                c.x().requestCredDeleg(true);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   298
                byte[] token = c.take(new byte[0]);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   299
                Proc.d("Client AP-REQ generated");
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   300
                Proc.binOut(token);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   301
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   302
        } else {
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   303
            Proc.d(System.getProperty("java.vm.version"));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   304
            Proc.d(System.getProperty("sun.security.jgss.native"));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   305
            Proc.d(System.getProperty("sun.security.jgss.lib"));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   306
            Proc.d("---------------------------------\n");
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   307
            Proc.d("Server start");
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   308
            Context s = Context.fromUserKtab("*", OneKDC.KTAB, true);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   309
            Proc.d("Server login");
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   310
            while (true) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   311
                String title = Proc.textIn();
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   312
                Proc.d("Server sees " + title);
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   313
                if (title.equals("END")) break;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   314
                s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   315
                byte[] token = Proc.binIn();
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   316
                try {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   317
                    s.take(token);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   318
                    Proc.textOut("true");
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   319
                    Proc.d("Good");
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   320
                } catch (Exception e) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   321
                    Proc.textOut("false");
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   322
                    Proc.d("Bad");
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   323
                }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   324
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   325
        }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   326
    }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   327
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   328
    public static void main(String[] args) throws Exception {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   329
        try {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   330
            main0(args);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   331
        } catch (Exception e) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   332
            Proc.d(e);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   333
            throw e;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   334
        }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   335
    }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   336
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   337
    // returns the client name
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   338
    private static String client(int p) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   339
        return "client" + p;
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   340
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   341
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   342
    // returns the service name
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   343
    private static String service(int p) {
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
   344
        return SERVICE + p + "/" + HOST;
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   345
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   346
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   347
    // returns the dfl name for a service
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   348
    private static String dfl(int p) {
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
   349
        return SERVICE + p + (uid == -1 ? "" : ("_"+uid));
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   350
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   351
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   352
    // generates an ap-req and save into reqs, returns the index
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   353
    private static int req(int client, int service) throws Exception {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   354
        pi.println(client(client) + " " + service(service));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   355
        Req req = new Req(client, service, pi.readData());
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   356
        reqs.add(req);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   357
        return reqs.size() - 1;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   358
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   359
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   360
    // create a acceptor
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   361
    private static Proc acceptor(String type, String suffix) throws Exception {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   362
        Proc p;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   363
        String label;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   364
        String lib;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   365
        int pos = type.indexOf('=');
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   366
        if (pos < 0) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   367
            label = type;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   368
            lib = null;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   369
        } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   370
            label = type.substring(0, pos);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   371
            lib = type.substring(pos + 1);
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   372
        }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   373
        if (type.startsWith("J")) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   374
            if (lib == null) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   375
                p = Proc.create("ReplayCacheTestProc");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   376
            } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   377
                p = Proc.create("ReplayCacheTestProc", lib);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   378
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   379
            p.prop("sun.security.krb5.rcache", "dfl")
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   380
                    .prop("java.io.tmpdir", cwd);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   381
            String useMD5 = System.getProperty("jdk.krb5.rcache.useMD5");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   382
            if (useMD5 != null) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   383
                p.prop("jdk.krb5.rcache.useMD5", useMD5);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   384
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   385
        } else {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   386
            p = Proc.create("ReplayCacheTestProc")
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   387
                    .env("KRB5_CONFIG", OneKDC.KRB5_CONF)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   388
                    .env("KRB5_KTNAME", OneKDC.KTAB)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   389
                    .env("KRB5RCACHEDIR", cwd)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   390
                    .prop("sun.security.jgss.native", "true")
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   391
                    .prop("javax.security.auth.useSubjectCredsOnly", "false")
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   392
                    .prop("sun.security.nativegss.debug", "true");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   393
            if (lib != null) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   394
                String libDir = lib.substring(0, lib.lastIndexOf('/'));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   395
                p.prop("sun.security.jgss.lib", lib)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   396
                        .env("DYLD_LIBRARY_PATH", libDir)
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   397
                        .env("LD_LIBRARY_PATH", libDir);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   398
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   399
        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   400
        Proc.d(label+suffix+" started");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   401
        return p.args(label+suffix).debug(label+suffix).start();
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   402
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   403
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   404
    // generates hash of authenticator inside ap-req inside initsectoken
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   405
    private static void record(String label, Req req) throws Exception {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   406
        byte[] data = Base64.getDecoder().decode(req.msg);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   407
        data = Arrays.copyOfRange(data, 17, data.length);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   408
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   409
        try (PrintStream ps = new PrintStream(
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   410
                new FileOutputStream("log.txt", true))) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   411
            ps.printf("%s:\nmsg: %s\nMD5: %s\nSHA-256: %s\n\n",
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   412
                    label,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   413
                    req.msg,
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   414
                    hex(md5.digest(data)),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   415
                    hex(sha256.digest(data)));
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   416
        }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   417
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   418
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   419
    // Returns a compact hexdump for a byte array
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   420
    private static String hex(byte[] hash) {
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   421
        char[] h = new char[hash.length * 2];
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   422
        char[] hexConst = "0123456789ABCDEF".toCharArray();
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   423
        for (int i=0; i<hash.length; i++) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   424
            h[2*i] = hexConst[(hash[i]&0xff)>>4];
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   425
            h[2*i+1] = hexConst[hash[i]&0xf];
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   426
        }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   427
        return new String(h);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   428
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   429
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   430
    // return size of dfl file, excluding the null hash ones
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   431
    private static int csize(int p) throws Exception {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   432
        try (SeekableByteChannel chan = Files.newByteChannel(
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   433
                Paths.get(cwd, dfl(p)), StandardOpenOption.READ)) {
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   434
            chan.position(6);
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   435
            int cc = 0;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   436
            while (true) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   437
                try {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   438
                    if (AuthTime.readFrom(chan) != null) cc++;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   439
                } catch (BufferUnderflowException e) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   440
                    break;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   441
                }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   442
            }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   443
            return cc;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   444
        } catch (IOException ioe) {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   445
            return 0;
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   446
        }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   447
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   448
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   449
    // models an experiement
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   450
    private static class Ex {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   451
        int i;              // #
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   452
        int req;            // which ap-req to send
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   453
        Proc acceptor;      // which acceptor to send to
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   454
        boolean expected;   // expected result
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   455
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   456
        boolean actual;     // actual output
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   457
        int csize;          // size of rcache after test
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   458
        String hash;        // the hash of req
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   459
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   460
        Ex(int i, int req, Proc acceptor, boolean expected) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   461
            this.i = i;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   462
            this.req = req;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   463
            this.acceptor = acceptor;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   464
            this.expected = expected;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   465
        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   466
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   467
        void run() throws Exception {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   468
            Req r = reqs.get(req);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   469
            acceptor.println("TEST");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   470
            acceptor.println(r.msg);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   471
            String reply = acceptor.readData();
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   472
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   473
            actual = Boolean.valueOf(reply);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   474
            csize = csize(r.service);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   475
42108
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
   476
            String label = String.format("%03d-client%d-%s%d-%s-%s",
1542d48cebeb 8169751: sun/security/krb5/auto/rcache_usemd5.sh fails on solaris
weijun
parents: 41832
diff changeset
   477
                    i, r.client, SERVICE, r.service, acceptor.debug(), actual);
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   478
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   479
            record(label, r);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   480
            if (new File(cwd, dfl(r.service)).exists()) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   481
                Files.copy(Paths.get(cwd, dfl(r.service)), Paths.get(label),
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   482
                        StandardCopyOption.COPY_ATTRIBUTES);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   483
            }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   484
        }
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   485
    }
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   486
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   487
    // models a saved ap-req msg
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   488
    private static class Req {
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   489
        String msg;         // based64-ed req
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   490
        int client;         // which client
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   491
        int service;        // which service
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   492
        Req(int client, int service, String msg) {
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   493
            this.msg = msg;
41832
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   494
            this.client= client;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   495
            this.service = service;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   496
        }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   497
    }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   498
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   499
    private static class UserRun {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   500
        static final Pattern p
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   501
                = Pattern.compile("(c(\\d)+s(\\d+)|r(\\d+))(.*)(.)");
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   502
        final Matcher m;
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   503
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   504
        UserRun(String run) { m = p.matcher(run); m.find(); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   505
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   506
        int req() { return group(4); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   507
        int client() { return group(2); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   508
        int service() { return group(3); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   509
        String acceptor() { return m.group(5); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   510
        boolean success() { return m.group(6).equals("v"); }
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   511
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   512
        int group(int i) {
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   513
            String g = m.group(i);
15db944958a7 8168518: rcache interop with krb5-1.15
weijun
parents: 34882
diff changeset
   514
            return g == null ? -1 : Integer.parseInt(g);
18536
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   515
        }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   516
    }
092411ced388 8001326: Improve Kerberos caching
weijun
parents:
diff changeset
   517
}