Skip to content
Permalink
Browse files
8163498: Many long-running security libs tests
Reviewed-by: rhalade, weijun
  • Loading branch information
Fernando Guallini authored and rhalade committed Feb 5, 2021
1 parent c5bb109 commit d2bd499222382e44d849b4884e72d2c9117895ed
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,14 +23,16 @@

/**
* @test
* @bug 8072452
* @bug 8072452 8163498
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
* This test has been split based on lower/higher key sizes in order to
* reduce individual execution times and run in parallel
* (see SupportedDHParamGensLongKey.java)
* @run main/timeout=300 SupportedDHParamGens 512
* @run main/timeout=300 SupportedDHParamGens 768
* @run main/timeout=300 SupportedDHParamGens 832
* @run main/timeout=300 SupportedDHParamGens 1024
* @run main/timeout=600 SupportedDHParamGens 2048
* @run main/timeout=700 SupportedDHParamGens 3072
*/

import java.math.BigInteger;
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8072452 8163498
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
* This test has been split based on lower/higher key sizes in order to
* reduce individual execution times and run in parallel
* (see SupportedDHParamGens.java)
* @run main/timeout=700 SupportedDHParamGens 3072
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,12 +23,14 @@

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

/*
* @test
* @bug 8072452 8163498
* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
* This test has been split based on lower/higher key sizes in order to
* reduce individual execution times and run in parallel
* (see SupportedDSAParamGen.java)
* @run main/timeout=700 SupportedDSAParamGen 3072 256
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,20 +34,21 @@

/*
* @test
* @bug 8075286
* @bug 8075286 8163498
* @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.
* This test has been split based on lower/higher key sizes in order to
* reduce individual execution times and run in parallel
* (see TestDSAGenParameterSpecLongKey.java)
* @run main TestDSAGenParameterSpec 512 160
* @run main TestDSAGenParameterSpec 1024 160 true
* @run main TestDSAGenParameterSpec 1024 224
* @run main TestDSAGenParameterSpec 2048 160
* @run main/timeout=300 TestDSAGenParameterSpec 2048 224 true
* @run main/timeout=300 TestDSAGenParameterSpec 2048 256 true
* @run main TestDSAGenParameterSpec 3072 224
* @run main/timeout=700 TestDSAGenParameterSpec 3072 256 true
* @run main TestDSAGenParameterSpec 4096 256
*/
public class TestDSAGenParameterSpec {

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8075286 8163498
* @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.
* This test has been split based on lower/higher key sizes in order to
* reduce individual execution times and run in parallel
* (see TestDSAGenParameterSpec.java)
* @run main/timeout=700 TestDSAGenParameterSpec 3072 256 true
* @run main TestDSAGenParameterSpec 4096 256
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,17 +29,21 @@
import static javax.crypto.Cipher.PRIVATE_KEY;
import static javax.crypto.Cipher.PUBLIC_KEY;

import jdk.test.lib.Asserts;
import jdk.test.lib.SigTestUtil;
import static jdk.test.lib.SigTestUtil.SignatureType;

/**
* @test
* @bug 8044199 8146293
* @summary Create a signature for RSA and get its signed data. re-initiate
* @bug 8044199 8146293 8163498
* @summary Ensure keys created from KeyFactory::getKeySpec and from constructors
* are equal.
* Create a signature for RSA and get its signed data. re-initiate
* the signature with the public key. The signature can be verified
* by acquired signed data.
* @library /test/lib
* @library /test/lib ../tools/keytool/fakegen
* @build jdk.test.lib.SigTestUtil
* @build java.base/sun.security.rsa.RSAKeyPairGenerator
* @run main SignatureTest 512
* @run main SignatureTest 768
* @run main SignatureTest 1024
@@ -133,12 +137,24 @@ private static KeyPair generateKeys(String keyalg, int size)
} catch (InvalidKeySpecException expected) {
}

RSAPublicKeySpec pubKeySpec1 = kf.getKeySpec(key, RSAPublicKeySpec.class);
RSAPublicKeySpec pubKeySpec2 = new RSAPublicKeySpec(
((RSAPublicKey) key).getModulus(),
((RSAPublicKey) key).getPublicExponent());

Asserts.assertTrue(keySpecEquals(pubKeySpec1, pubKeySpec2),
"Both RSAPublicKeySpec should be equal");

X509EncodedKeySpec x509KeySpec1 = kf.getKeySpec(key, X509EncodedKeySpec.class);
X509EncodedKeySpec x509KeySpec2 = new X509EncodedKeySpec(key.getEncoded());

Asserts.assertTrue(encodedKeySpecEquals(x509KeySpec1, x509KeySpec2),
"Both X509EncodedKeySpec should be equal");

return new Key[]{
kf.generatePublic(kf.getKeySpec(key, RSAPublicKeySpec.class)),
kf.generatePublic(new X509EncodedKeySpec(key.getEncoded())),
kf.generatePublic(new RSAPublicKeySpec(
((RSAPublicKey) key).getModulus(),
((RSAPublicKey) key).getPublicExponent()))
key,
kf.generatePublic(pubKeySpec1),
kf.generatePublic(x509KeySpec1)
};
case PRIVATE_KEY:
try {
@@ -147,13 +163,24 @@ private static KeyPair generateKeys(String keyalg, int size)
+ " not thrown");
} catch (InvalidKeySpecException expected) {
}
RSAPrivateKeySpec privKeySpec1 = kf.getKeySpec(key, RSAPrivateKeySpec.class);
RSAPrivateKeySpec privKeySpec2 = new RSAPrivateKeySpec(
((RSAPrivateKey) key).getModulus(),
((RSAPrivateKey) key).getPrivateExponent());

Asserts.assertTrue(keySpecEquals(privKeySpec1, privKeySpec2),
"Both RSAPrivateKeySpec should be equal");

PKCS8EncodedKeySpec pkcsKeySpec1 = kf.getKeySpec(key, PKCS8EncodedKeySpec.class);
PKCS8EncodedKeySpec pkcsKeySpec2 = new PKCS8EncodedKeySpec(key.getEncoded());

Asserts.assertTrue(encodedKeySpecEquals(pkcsKeySpec1, pkcsKeySpec2),
"Both PKCS8EncodedKeySpec should be equal");

return new Key[]{
kf.generatePrivate(kf.getKeySpec(key,
RSAPrivateKeySpec.class)),
kf.generatePrivate(new PKCS8EncodedKeySpec(
key.getEncoded())),
kf.generatePrivate(new RSAPrivateKeySpec(((RSAPrivateKey) key).getModulus(),
((RSAPrivateKey) key).getPrivateExponent()))
key,
kf.generatePrivate(privKeySpec1),
kf.generatePrivate(pkcsKeySpec1)
};
}
throw new RuntimeException("We shouldn't reach here");
@@ -197,4 +224,22 @@ private static void checkSignature(byte[] data, PublicKey pub,
+ " signature");
}
}

private static boolean keySpecEquals(RSAPublicKeySpec spec1, RSAPublicKeySpec spec2) {
return spec1.getModulus().equals(spec2.getModulus())
&& spec1.getPublicExponent().equals(spec2.getPublicExponent())
&& Objects.equals(spec1.getParams(), spec2.getParams());
}

private static boolean keySpecEquals(RSAPrivateKeySpec spec1, RSAPrivateKeySpec spec2) {
return spec1.getModulus().equals(spec2.getModulus())
&& spec1.getPrivateExponent().equals(spec2.getPrivateExponent())
&& Objects.equals(spec1.getParams(), spec2.getParams());
}

private static boolean encodedKeySpecEquals(EncodedKeySpec spec1, EncodedKeySpec spec2) {
return Objects.equals(spec1.getAlgorithm(), spec2.getAlgorithm())
&& spec1.getFormat().equals(spec2.getFormat())
&& Arrays.equals(spec1.getEncoded(), spec2.getEncoded());
}
}
Loading

0 comments on commit d2bd499

Please sign in to comment.