提交 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;
import java.security.spec.InvalidParameterSpecException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/*
* @test
......@@ -40,26 +41,15 @@ import java.util.List;
* @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
* specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and
* (3072, 256) should be OK for DSAGenParameterSpec. But the real
* implementation SUN doesn't support (3072, 256).
* @run main TestDSAGenParameterSpec
* (3072, 256) should be OK for DSAGenParameterSpec.
* @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 3072,256,true
*/
public class TestDSAGenParameterSpec {
private static final String ALGORITHM_NAME = "DSA";
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)
throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidParameterSpecException, InvalidAlgorithmParameterException {
......@@ -83,16 +73,9 @@ public class TestDSAGenParameterSpec {
checkParam(param, genParamSpec);
System.out.println("Test case passed");
} catch (InvalidParameterException ipe) {
// The DSAGenParameterSpec API support this, but the real
// 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);
}
}
}
private static void checkParam(AlgorithmParameters param,
DSAGenParameterSpec genParam) throws InvalidParameterSpecException,
......@@ -126,11 +109,9 @@ public class TestDSAGenParameterSpec {
throw new RuntimeException("Wrong seed length");
}
// use the parameters to generate real DSA keys
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
PROVIDER_NAME);
keyGen.initialize(spec);
keyGen.generateKeyPair();
}
private static DSAGenParameterSpec createGenParameterSpec(
......@@ -157,10 +138,21 @@ public class TestDSAGenParameterSpec {
}
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);
}
System.out.println("All tests passed");
}
private static class DataTuple {
......@@ -168,18 +160,13 @@ public class TestDSAGenParameterSpec {
private int primePLen;
private int subprimeQLen;
private boolean isDSASpecSupported;
private boolean isSunProviderSupported;
private DataTuple(int primePLen, int subprimeQLen,
boolean isDSASpecSupported, boolean isSunProviderSupported) {
boolean isDSASpecSupported) {
this.primePLen = primePLen;
this.subprimeQLen = subprimeQLen;
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.
先完成此消息的编辑!
想要评论请 注册