Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit d2bd499

Browse files
fguallinirhalade
authored andcommittedFeb 5, 2021
8163498: Many long-running security libs tests
Reviewed-by: rhalade, weijun
1 parent c5bb109 commit d2bd499

File tree

8 files changed

+276
-26
lines changed

8 files changed

+276
-26
lines changed
 

‎test/jdk/com/sun/crypto/provider/KeyAgreement/SupportedDHParamGens.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,14 +23,16 @@
2323

2424
/**
2525
* @test
26-
* @bug 8072452
26+
* @bug 8072452 8163498
2727
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
28+
* This test has been split based on lower/higher key sizes in order to
29+
* reduce individual execution times and run in parallel
30+
* (see SupportedDHParamGensLongKey.java)
2831
* @run main/timeout=300 SupportedDHParamGens 512
2932
* @run main/timeout=300 SupportedDHParamGens 768
3033
* @run main/timeout=300 SupportedDHParamGens 832
3134
* @run main/timeout=300 SupportedDHParamGens 1024
3235
* @run main/timeout=600 SupportedDHParamGens 2048
33-
* @run main/timeout=700 SupportedDHParamGens 3072
3436
*/
3537

3638
import java.math.BigInteger;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8072452 8163498
27+
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
28+
* This test has been split based on lower/higher key sizes in order to
29+
* reduce individual execution times and run in parallel
30+
* (see SupportedDHParamGens.java)
31+
* @run main/timeout=700 SupportedDHParamGens 3072
32+
*/

‎test/jdk/sun/security/provider/DSA/SupportedDSAParamGen.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,12 +23,14 @@
2323

2424
/*
2525
* @test
26-
* @bug 8072452
26+
* @bug 8072452 8163498
2727
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
28+
* This test has been split based on lower/higher key sizes in order to
29+
* reduce individual execution times and run in parallel
30+
* (see SupportedDSAParamGenLongKey.java)
2831
* @run main/timeout=300 SupportedDSAParamGen 1024 160
2932
* @run main/timeout=300 SupportedDSAParamGen 2048 224
3033
* @run main/timeout=300 SupportedDSAParamGen 2048 256
31-
* @run main/timeout=700 SupportedDSAParamGen 3072 256
3234
*/
3335
import java.security.*;
3436
import java.security.spec.*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8072452 8163498
27+
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
28+
* This test has been split based on lower/higher key sizes in order to
29+
* reduce individual execution times and run in parallel
30+
* (see SupportedDSAParamGen.java)
31+
* @run main/timeout=700 SupportedDSAParamGen 3072 256
32+
*/

‎test/jdk/sun/security/provider/NSASuiteB/TestDSAGenParameterSpec.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,20 +34,21 @@
3434

3535
/*
3636
* @test
37-
* @bug 8075286
37+
* @bug 8075286 8163498
3838
* @summary Verify that DSAGenParameterSpec can and can only be used to generate
3939
* DSA within some certain range of key sizes as described in the class
4040
* specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and
4141
* (3072, 256) should be OK for DSAGenParameterSpec.
42+
* This test has been split based on lower/higher key sizes in order to
43+
* reduce individual execution times and run in parallel
44+
* (see TestDSAGenParameterSpecLongKey.java)
4245
* @run main TestDSAGenParameterSpec 512 160
4346
* @run main TestDSAGenParameterSpec 1024 160 true
4447
* @run main TestDSAGenParameterSpec 1024 224
4548
* @run main TestDSAGenParameterSpec 2048 160
4649
* @run main/timeout=300 TestDSAGenParameterSpec 2048 224 true
4750
* @run main/timeout=300 TestDSAGenParameterSpec 2048 256 true
4851
* @run main TestDSAGenParameterSpec 3072 224
49-
* @run main/timeout=700 TestDSAGenParameterSpec 3072 256 true
50-
* @run main TestDSAGenParameterSpec 4096 256
5152
*/
5253
public class TestDSAGenParameterSpec {
5354

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8075286 8163498
27+
* @summary Verify that DSAGenParameterSpec can and can only be used to generate
28+
* DSA within some certain range of key sizes as described in the class
29+
* specification (L, N) as (1024, 160), (2048, 224), (2048, 256) and
30+
* (3072, 256) should be OK for DSAGenParameterSpec.
31+
* This test has been split based on lower/higher key sizes in order to
32+
* reduce individual execution times and run in parallel
33+
* (see TestDSAGenParameterSpec.java)
34+
* @run main/timeout=700 TestDSAGenParameterSpec 3072 256 true
35+
* @run main TestDSAGenParameterSpec 4096 256
36+
*/

‎test/jdk/sun/security/rsa/SignatureTest.java

+60-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,17 +29,21 @@
2929
import static javax.crypto.Cipher.PRIVATE_KEY;
3030
import static javax.crypto.Cipher.PUBLIC_KEY;
3131

32+
import jdk.test.lib.Asserts;
3233
import jdk.test.lib.SigTestUtil;
3334
import static jdk.test.lib.SigTestUtil.SignatureType;
3435

3536
/**
3637
* @test
37-
* @bug 8044199 8146293
38-
* @summary Create a signature for RSA and get its signed data. re-initiate
38+
* @bug 8044199 8146293 8163498
39+
* @summary Ensure keys created from KeyFactory::getKeySpec and from constructors
40+
* are equal.
41+
* Create a signature for RSA and get its signed data. re-initiate
3942
* the signature with the public key. The signature can be verified
4043
* by acquired signed data.
41-
* @library /test/lib
44+
* @library /test/lib ../tools/keytool/fakegen
4245
* @build jdk.test.lib.SigTestUtil
46+
* @build java.base/sun.security.rsa.RSAKeyPairGenerator
4347
* @run main SignatureTest 512
4448
* @run main SignatureTest 768
4549
* @run main SignatureTest 1024
@@ -133,12 +137,24 @@ private static Key[] manipulateKey(int type, Key key)
133137
} catch (InvalidKeySpecException expected) {
134138
}
135139

140+
RSAPublicKeySpec pubKeySpec1 = kf.getKeySpec(key, RSAPublicKeySpec.class);
141+
RSAPublicKeySpec pubKeySpec2 = new RSAPublicKeySpec(
142+
((RSAPublicKey) key).getModulus(),
143+
((RSAPublicKey) key).getPublicExponent());
144+
145+
Asserts.assertTrue(keySpecEquals(pubKeySpec1, pubKeySpec2),
146+
"Both RSAPublicKeySpec should be equal");
147+
148+
X509EncodedKeySpec x509KeySpec1 = kf.getKeySpec(key, X509EncodedKeySpec.class);
149+
X509EncodedKeySpec x509KeySpec2 = new X509EncodedKeySpec(key.getEncoded());
150+
151+
Asserts.assertTrue(encodedKeySpecEquals(x509KeySpec1, x509KeySpec2),
152+
"Both X509EncodedKeySpec should be equal");
153+
136154
return new Key[]{
137-
kf.generatePublic(kf.getKeySpec(key, RSAPublicKeySpec.class)),
138-
kf.generatePublic(new X509EncodedKeySpec(key.getEncoded())),
139-
kf.generatePublic(new RSAPublicKeySpec(
140-
((RSAPublicKey) key).getModulus(),
141-
((RSAPublicKey) key).getPublicExponent()))
155+
key,
156+
kf.generatePublic(pubKeySpec1),
157+
kf.generatePublic(x509KeySpec1)
142158
};
143159
case PRIVATE_KEY:
144160
try {
@@ -147,13 +163,24 @@ private static Key[] manipulateKey(int type, Key key)
147163
+ " not thrown");
148164
} catch (InvalidKeySpecException expected) {
149165
}
166+
RSAPrivateKeySpec privKeySpec1 = kf.getKeySpec(key, RSAPrivateKeySpec.class);
167+
RSAPrivateKeySpec privKeySpec2 = new RSAPrivateKeySpec(
168+
((RSAPrivateKey) key).getModulus(),
169+
((RSAPrivateKey) key).getPrivateExponent());
170+
171+
Asserts.assertTrue(keySpecEquals(privKeySpec1, privKeySpec2),
172+
"Both RSAPrivateKeySpec should be equal");
173+
174+
PKCS8EncodedKeySpec pkcsKeySpec1 = kf.getKeySpec(key, PKCS8EncodedKeySpec.class);
175+
PKCS8EncodedKeySpec pkcsKeySpec2 = new PKCS8EncodedKeySpec(key.getEncoded());
176+
177+
Asserts.assertTrue(encodedKeySpecEquals(pkcsKeySpec1, pkcsKeySpec2),
178+
"Both PKCS8EncodedKeySpec should be equal");
179+
150180
return new Key[]{
151-
kf.generatePrivate(kf.getKeySpec(key,
152-
RSAPrivateKeySpec.class)),
153-
kf.generatePrivate(new PKCS8EncodedKeySpec(
154-
key.getEncoded())),
155-
kf.generatePrivate(new RSAPrivateKeySpec(((RSAPrivateKey) key).getModulus(),
156-
((RSAPrivateKey) key).getPrivateExponent()))
181+
key,
182+
kf.generatePrivate(privKeySpec1),
183+
kf.generatePrivate(pkcsKeySpec1)
157184
};
158185
}
159186
throw new RuntimeException("We shouldn't reach here");
@@ -197,4 +224,22 @@ private static void checkSignature(byte[] data, PublicKey pub,
197224
+ " signature");
198225
}
199226
}
227+
228+
private static boolean keySpecEquals(RSAPublicKeySpec spec1, RSAPublicKeySpec spec2) {
229+
return spec1.getModulus().equals(spec2.getModulus())
230+
&& spec1.getPublicExponent().equals(spec2.getPublicExponent())
231+
&& Objects.equals(spec1.getParams(), spec2.getParams());
232+
}
233+
234+
private static boolean keySpecEquals(RSAPrivateKeySpec spec1, RSAPrivateKeySpec spec2) {
235+
return spec1.getModulus().equals(spec2.getModulus())
236+
&& spec1.getPrivateExponent().equals(spec2.getPrivateExponent())
237+
&& Objects.equals(spec1.getParams(), spec2.getParams());
238+
}
239+
240+
private static boolean encodedKeySpecEquals(EncodedKeySpec spec1, EncodedKeySpec spec2) {
241+
return Objects.equals(spec1.getAlgorithm(), spec2.getAlgorithm())
242+
&& spec1.getFormat().equals(spec2.getFormat())
243+
&& Arrays.equals(spec1.getEncoded(), spec2.getEncoded());
244+
}
200245
}

0 commit comments

Comments
 (0)
This repository has been archived.