--- old/test/sun/security/krb5/auto/ReplayCacheTestProc.java 2016-10-25 15:18:47.000000000 +0800 +++ new/test/sun/security/krb5/auto/ReplayCacheTestProc.java 2016-10-25 15:18:46.000000000 +0800 @@ -25,9 +25,10 @@ * @test * @bug 7152176 * @summary More krb5 tests - * @library ../../../../java/security/testlibrary/ + * @library ../../../../java/security/testlibrary/ /test/lib * @compile -XDignore.symbol.file ReplayCacheTestProc.java - * @run main/othervm/timeout=100 ReplayCacheTestProc + * @run main/othervm/timeout=300 ReplayCacheTestProc + * @run main/othervm/timeout=300 -Djdk.krb5.rcache.usemd5=true ReplayCacheTestProc */ import java.io.*; @@ -40,15 +41,35 @@ import java.security.MessageDigest; import java.util.*; +import jdk.test.lib.Platform; import sun.security.jgss.GSSUtil; import sun.security.krb5.internal.APReq; import sun.security.krb5.internal.rcache.AuthTime; +import sun.security.krb5.internal.rcache.AuthTimeWithHash; -// This test runs multiple acceptor Procs to mimin AP-REQ replays. +/** + * This test runs multiple acceptor Procs to mimin AP-REQ replays. + * It can either run with automatic (random) test runs or user can provide + * these system properties: + * + * - test.libs on what types of acceptors to use + * Format: CSV of (J|N|N) + * Example: J,N,N/krb5-1.14/lib/libgssapi_krb5.so + * + * - test.runs on runs + * Format: (req# | client# service#) acceptor# expected... + * Example: c0h0J0v,c1h1N0v,r0J1x means 1st req is new c0 to h0 sent to J0, + * 2nd req is new c1 to h1 sent to N0, + * 3rd req is old (1st replayed) sent to J1. + * For all old reqs, client# and service# MUST be - + * + * - test.autoruns on how many autoruns + * Format: number + */ public class ReplayCacheTestProc { - private static Proc[] ps; - private static Proc pc; + private static Proc[] pa; // all acceptors + private static Proc pi; // the single initiator private static List reqs = new ArrayList<>(); private static String HOST = "localhost"; @@ -65,18 +86,14 @@ public static void main0(String[] args) throws Exception { System.setProperty("java.security.krb5.conf", OneKDC.KRB5_CONF); if (args.length == 0) { // The controller - int ns = 5; // number of servers int nu = 5; // number of users - int nx = 50; // number of experiments - int np = 5; // number of peers (services) - int mode = 0; // native(1), random(0), java(-1) - boolean random = true; // random experiments choreograph - - // Do not test interop with native GSS on some platforms - String os = System.getProperty("os.name", "???"); - if (!os.startsWith("SunOS") && !os.startsWith("Linux")) { - mode = -1; - } + int nh = 5; // number of hosts (services) + String[] libs; // available acceptor types: + // J: java + // N: default native lib + // N: native lib with the given name + Ex[] result; + int numPerType = 2; // number of servers per type uid = jdk.internal.misc.VM.geteuid(); @@ -85,93 +102,151 @@ kdc.addPrincipal(user(i), OneKDC.PASS); } kdc.addPrincipalRandKey("krbtgt/" + OneKDC.REALM); - for (int i=0; i + if (libs[type].length() == 1) { + label = libs[type]; + } else { + label = "" + (char)('A' + type); + } + pa[i] = acceptor(libs[type], label + i % numPerType); + } + + String userRuns = System.getProperty("test.runs"); + + if (userRuns != null) { + String[] runs = userRuns.split(","); + result = new Ex[runs.length]; + for (int i = 0; i < runs.length; i++) { + boolean expected = false; + int req = -1; + int client = -1; + int host = -1; + UserRun run = new UserRun(runs[i]); + while (true) { + char type = run.nextAction(); + if (type == ' ') { + break; + } + switch (type) { + case 'r': + req = result[run.nextValue()].req; + break; + case 'c': + client = run.nextValue(); + break; + case 'h': + req = req(client, run.nextValue()); + break; + case 'J': + case 'N': + for (int j = 0; j < libs.length; j++) { + if (libs[j].equals("" + type)) { + host = j * numPerType + run.nextValue(); + break; + } + } + break; + case 'v': + expected = true; + break; + case 'x': + expected = false; + break; + default: // ABC... + host = (type - 'A') * numPerType + run.nextValue(); + } + } + result[i] = new Ex(i, req, host, expected); + } } else { + result = new Ex[Integer.parseInt( + System.getProperty("test.autoruns", "100"))]; Random r = new Random(); - for (int i=0; i 1) { + String lib = type.substring(1); + String libDir = lib.substring(0, lib.lastIndexOf('/')); + p.prop("sun.security.jgss.lib", lib) + .env("DYLD_LIBRARY_PATH", libDir) + .env("LD_LIBRARY_PATH", libDir); + } + } + return p.start(); } + // generates hash of authenticator inside ap-req inside initsectoken private static String hash(String req) throws Exception { byte[] data = Base64.getDecoder().decode(req); data = Arrays.copyOfRange(data, 17, data.length); - byte[] hash = MessageDigest.getInstance("MD5").digest(new APReq(data).authenticator.getBytes()); + byte[] hash = MessageDigest.getInstance( + AuthTimeWithHash.realAlg(AuthTimeWithHash.DEFAULT_HASH_ALG)) + .digest(new APReq(data).authenticator.getBytes()); char[] h = new char[hash.length * 2]; char[] hexConst = "0123456789ABCDEF".toCharArray(); for (int i=0; i