提交 8dcf7e33 编写于 作者: I igerasim

8137255: sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java timeouts intermittently

Summary: sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java timeouts intermittently due to large DSA key parameter generation.
Reviewed-by: valeriep
Contributed-by: NJohn Jiang <sha.jiang@oracle.com>
上级 c9c47d9b
...@@ -33,6 +33,7 @@ import java.security.spec.DSAParameterSpec; ...@@ -33,6 +33,7 @@ import java.security.spec.DSAParameterSpec;
import java.security.spec.InvalidParameterSpecException; import java.security.spec.InvalidParameterSpecException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/* /*
* @test * @test
...@@ -40,26 +41,15 @@ import java.util.List; ...@@ -40,26 +41,15 @@ import java.util.List;
* @summary Verify that DSAGenParameterSpec can and can only be used to generate * @summary Verify that DSAGenParameterSpec can and can only be used to generate
* DSA within some certain range of key sizes as described in the class * DSA within some certain range of key sizes as described in the class
* specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and * specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and
* (3072, 256) should be OK for DSAGenParameterSpec. But the real * (3072, 256) should be OK for DSAGenParameterSpec.
* implementation SUN doesn't support (3072, 256). * @run main TestDSAGenParameterSpec 2048,256,true 2048,224,true 1024,160,true 4096,256 3072,224 2048,160 1024,224 512,160
* @run main TestDSAGenParameterSpec * @run main TestDSAGenParameterSpec 3072,256,true
*/ */
public class TestDSAGenParameterSpec { public class TestDSAGenParameterSpec {
private static final String ALGORITHM_NAME = "DSA"; private static final String ALGORITHM_NAME = "DSA";
private static final String PROVIDER_NAME = "SUN"; private static final String PROVIDER_NAME = "SUN";
private static final List<DataTuple> DATA = Arrays.asList(
new DataTuple(1024, 160, true, true),
new DataTuple(2048, 224, true, true),
new DataTuple(2048, 256, true, true),
new DataTuple(3072, 256, true, false),
new DataTuple(1024, 224),
new DataTuple(2048, 160),
new DataTuple(4096, 256),
new DataTuple(512, 160),
new DataTuple(3072, 224));
private static void testDSAGenParameterSpec(DataTuple dataTuple) private static void testDSAGenParameterSpec(DataTuple dataTuple)
throws NoSuchAlgorithmException, NoSuchProviderException, throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidParameterSpecException, InvalidAlgorithmParameterException { InvalidParameterSpecException, InvalidAlgorithmParameterException {
...@@ -83,14 +73,7 @@ public class TestDSAGenParameterSpec { ...@@ -83,14 +73,7 @@ public class TestDSAGenParameterSpec {
checkParam(param, genParamSpec); checkParam(param, genParamSpec);
System.out.println("Test case passed"); System.out.println("Test case passed");
} catch (InvalidParameterException ipe) { } catch (InvalidParameterException ipe) {
// The DSAGenParameterSpec API support this, but the real throw new RuntimeException("Test case failed.", ipe);
// implementation in SUN doesn't
if (!dataTuple.isSunProviderSupported) {
System.out.println("Test case passed: expected "
+ "InvalidParameterException is caught");
} else {
throw new RuntimeException("Test case failed.", ipe);
}
} }
} }
...@@ -126,11 +109,9 @@ public class TestDSAGenParameterSpec { ...@@ -126,11 +109,9 @@ public class TestDSAGenParameterSpec {
throw new RuntimeException("Wrong seed length"); throw new RuntimeException("Wrong seed length");
} }
// use the parameters to generate real DSA keys
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME, KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
PROVIDER_NAME); PROVIDER_NAME);
keyGen.initialize(spec); keyGen.initialize(spec);
keyGen.generateKeyPair();
} }
private static DSAGenParameterSpec createGenParameterSpec( private static DSAGenParameterSpec createGenParameterSpec(
...@@ -157,10 +138,21 @@ public class TestDSAGenParameterSpec { ...@@ -157,10 +138,21 @@ public class TestDSAGenParameterSpec {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
for (DataTuple dataTuple : DATA) { List<DataTuple> dataTuples = Arrays.stream(args)
.map(arg -> arg.split(",")).map(params -> {
int primePLen = Integer.valueOf(params[0]);
int subprimeQLen = Integer.valueOf(params[1]);
boolean isDSASpecSupported = false;
if (params.length == 3) {
isDSASpecSupported = Boolean.valueOf(params[2]);
}
return new DataTuple(primePLen, subprimeQLen,
isDSASpecSupported);
}).collect(Collectors.toList());
for (DataTuple dataTuple : dataTuples) {
testDSAGenParameterSpec(dataTuple); testDSAGenParameterSpec(dataTuple);
} }
System.out.println("All tests passed");
} }
private static class DataTuple { private static class DataTuple {
...@@ -168,18 +160,13 @@ public class TestDSAGenParameterSpec { ...@@ -168,18 +160,13 @@ public class TestDSAGenParameterSpec {
private int primePLen; private int primePLen;
private int subprimeQLen; private int subprimeQLen;
private boolean isDSASpecSupported; private boolean isDSASpecSupported;
private boolean isSunProviderSupported;
private DataTuple(int primePLen, int subprimeQLen, private DataTuple(int primePLen, int subprimeQLen,
boolean isDSASpecSupported, boolean isSunProviderSupported) { boolean isDSASpecSupported) {
this.primePLen = primePLen; this.primePLen = primePLen;
this.subprimeQLen = subprimeQLen; this.subprimeQLen = subprimeQLen;
this.isDSASpecSupported = isDSASpecSupported; this.isDSASpecSupported = isDSASpecSupported;
this.isSunProviderSupported = isSunProviderSupported;
}
private DataTuple(int primePLen, int subprimeQLen) {
this(primePLen, subprimeQLen, false, false);
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册