# HG changeset patch # User weijun # Date 1536626906 -28800 # Tue Sep 11 08:48:26 2018 +0800 # Node ID f66a184bb75f698823a9487837df578702856de8 # Parent 23c77bdc49fccfdfaf48fab43df39ad5caeb91a3 8205507: jdk/javax/xml/crypto/dsig/GenerationTests.java timed out Reviewed-by: mullan diff --git a/test/javax/xml/crypto/dsig/GenerationTests.java b/test/javax/xml/crypto/dsig/GenerationTests.java --- a/test/javax/xml/crypto/dsig/GenerationTests.java +++ b/test/javax/xml/crypto/dsig/GenerationTests.java @@ -24,7 +24,7 @@ /** * @test * @bug 4635230 6283345 6303830 6824440 6867348 7094155 8038184 - * 8038349 8074784 8210736 + * 8038349 8074784 8205507 8210736 * @summary Basic unit tests for generating XML Signatures with JSR 105 * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java * X509KeySelector.java GenerationTests.java @@ -188,6 +188,26 @@ KeyValue, x509data, KeyName } + // cached keys (for performance) used by test_create_detached_signature(). + private static HashMap cachedKeys = new HashMap<>(); + + // Load cachedKeys persisted in a file to reproduce a failure. + // The keys are always saved to "cached-keys" but you can rename + // it to a different file name and load it here. Note: The keys will + // always be persisted so renaming is a good idea although the + // content might not change. + static { + String cacheFile = System.getProperty("use.cached.keys"); + if (cacheFile != null) { + try (FileInputStream fis = new FileInputStream(cacheFile); + ObjectInputStream ois = new ObjectInputStream(fis)) { + cachedKeys = (HashMap) ois.readObject(); + } catch (Exception e) { + throw new AssertionError("Cannot read " + cacheFile, e); + } + } + } + private static boolean result = true; public static void main(String args[]) throws Exception { @@ -308,6 +328,12 @@ XMLSignatureException.class); } + // persist cached keys to a file. + try (FileOutputStream fos = new FileOutputStream("cached-keys", true); + ObjectOutputStream oos = new ObjectOutputStream(fos)) { + oos.writeObject(cachedKeys); + } + if (!result) { throw new RuntimeException("At least one test case failed"); } @@ -1367,23 +1393,9 @@ SignatureMethod sm = fac.newSignatureMethod(signatureMethod, null); - Key signingKey; - Key validationKey; - switch (signatureMethod) { - case SignatureMethod.DSA_SHA1: - case SignatureMethod.RSA_SHA1: - KeyPair kp = generateKeyPair(sm); - validationKey = kp.getPublic(); - signingKey = kp.getPrivate(); - break; - case SignatureMethod.HMAC_SHA1: - KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1"); - signingKey = kg.generateKey(); - validationKey = signingKey; - break; - default: - throw new RuntimeException("Unsupported signature algorithm"); - } + Key[] pair = getCachedKeys(sm); + Key signingKey = pair[0]; + Key validationKey = pair[1]; SignedInfo si = fac.newSignedInfo(cm, sm, refs, null); @@ -1479,6 +1491,35 @@ setup(); } + private static Key[] getCachedKeys(final SignatureMethod sm) { + return cachedKeys.computeIfAbsent(sm.getAlgorithm(), signatureMethod -> { + try { + System.out.print(""); + System.out.flush(); + Key signingKey; + Key validationKey; + switch (signatureMethod) { + case SignatureMethod.DSA_SHA1: + case SignatureMethod.RSA_SHA1: + KeyPair kp = generateKeyPair(sm); + validationKey = kp.getPublic(); + signingKey = kp.getPrivate(); + break; + case SignatureMethod.HMAC_SHA1: + KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1"); + signingKey = kg.generateKey(); + validationKey = signingKey; + break; + default: + throw new RuntimeException("Unsupported signature algorithm"); + } + return new Key[] {signingKey, validationKey}; + } catch (NoSuchAlgorithmException e) { + throw new AssertionError("Should not happen", e); + } + }); + } + private static final String DSA_Y = "070662842167565771936588335128634396171789331656318483584455493822" + "400811200853331373030669235424928346190274044631949560438023934623" +