8163498: Many long-running security libs tests

Reviewed-by: rhalade, weijun
This commit is contained in:
Fernando Guallini 2021-02-05 05:22:51 +00:00 committed by Rajan Halade
parent c5bb109272
commit d2bd499222
8 changed files with 276 additions and 26 deletions

View File

@ -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;

View File

@ -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
*/

View File

@ -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.*;

View File

@ -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
*/

View File

@ -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,11 +34,14 @@ import java.security.spec.InvalidParameterSpecException;
/*
* @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
@ -46,8 +49,6 @@ import java.security.spec.InvalidParameterSpecException;
* @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 {

View File

@ -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
*/

View File

@ -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 java.util.stream.IntStream;
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 @@ public class SignatureTest {
} 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 @@ public class SignatureTest {
+ " 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 @@ public class SignatureTest {
+ " 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());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@ -119,6 +119,22 @@ public abstract class RSAKeyPairGenerator extends KeyPairGeneratorSpi {
// Pre-calculated p and q for e == RSAKeyGenParameterSpec.F4
switch (keySize) {
case 512:
p = new BigInteger("8020197120481219323433199611941970" +
"7343202627066030554371666273840736868057027");
q = new BigInteger("1034972075609195648369724560234440" +
"70295399787770567842730763283716564384306019");
break;
case 768:
p = new BigInteger("3014340057405340213534944319905083" +
"307463736669377067548946180566257416015519309" +
"4284652308891881268862122066025991763");
q = new BigInteger("2296482383752927761663381890127318" +
"246354728737890494883686642246681037847109357" +
"2243186228256258231783150577032535521");
break;
case 1024:
p = new BigInteger("1220491537800192366196661816910427"
+ "2375185130493819649338056226264568132442590"
@ -230,6 +246,90 @@ public abstract class RSAKeyPairGenerator extends KeyPairGeneratorSpi {
+ "5341584429803583589276956979963609078497238"
+ "760757619468018224491053");
break;
case 5120:
p = new BigInteger("3832424741858359087085019371467455" +
"477820253497664907405863412466091484202728975" +
"073716151647542449749677812957312366114168136" +
"601126462176029012452318767677007998900979141" +
"998941420505000455608776648534383479255437038" +
"823585008944551642245975099397794466252853815" +
"203014018988068346182132859181656248769392421" +
"674329339264774434516306264105498304974256178" +
"026250495864309250770172644263271598862641423" +
"631834585580910907527816840629665632700476957" +
"043059773597106256672930878739201142231424811" +
"069114153595397879660681041405350927706894635" +
"213653200929550087449740488813888141436925212" +
"442118365403614623169477625363286007075561882" +
"667104018888315477880055907473210438614579462" +
"496680112778003198202297772073923181825706950" +
"337756420826065243712623977225389265073815099" +
"11493486387569031");
q = new BigInteger("4146920568848191633539637174274014" +
"273474016268898436739861681496795368277264211" +
"347843247126933726314115942365962498640261418" +
"205807625467516350689984100345264883329988411" +
"779552170850267866351632396757500932855514738" +
"069918613980688598735820287717773558232108195" +
"582003010318600589422737510968348435291394630" +
"302856598706075108993749783272560317909096664" +
"669346475063020551195971583247945204761628694" +
"928169578936651221139603528255637489949563762" +
"679333707194876390341639312682559633604823162" +
"011775857712214779083777623361101169846144970" +
"895460110829130520744350827300192454548398367" +
"308247776459836067815323028595970305077016546" +
"572729562552659889374473339319508744706500295" +
"871005194700994677334996554312946263536447080" +
"506480369599180714418422948431890690584559846" +
"74443760221378817");
break;
case 6144:
p = new BigInteger("4116778174071734089881578561570208" +
"284278483208207611885263908178511953898663059" +
"734920127853932340647715543357847246656399270" +
"584421304381161243387321196180504266791989629" +
"037762533723859313828066684108658077147663308" +
"349610753424620992228874944364889251603796733" +
"651690820777521473807836887101380451450340893" +
"342182241046213770274098088066973392388380321" +
"597140066726105421813589290486721393630060991" +
"762786515266517210263824648882183969111257670" +
"482546599227987866663009035297583354975557124" +
"885067375690161316321537733738836231124022045" +
"342294989201664821765828714777945420537586846" +
"048441021936371397157175119512813296245432265" +
"178387966306100222317125784086707249132094899" +
"996583841504000177878867233453992573758531314" +
"930995997084778704191508142386227640558575022" +
"133615865313158902645671060856578407704407774" +
"541333134066077091323113676552873589627627108" +
"360212137049807676300972916221155242551418611" +
"845736012720292530472299883528545969");
q = new BigInteger("4309839393870191337347865939376524" +
"576203152274153819273872971875048034824772989" +
"396672731779116057590220960038178464518939532" +
"420543642549157490693480032819877624270041000" +
"978557189754354533164374250973267430850549095" +
"826504764380972668230808804187197733712467810" +
"336183971273199424298548393174475795085431856" +
"013835093176229700961388036392126193800974224" +
"471901942503594710577458613014825799700253747" +
"894059557606488589338390076087557449706202211" +
"490152794976124198853288767811370937925352946" +
"840084185059748423462857292189804953877120675" +
"812342626896129968757865091819031550949977046" +
"088481307609680346652447103811683263607048407" +
"341877388569162602224005230757828237769174382" +
"379831366827054223659952996908127997873168014" +
"060581963520521443425267958786876837371303659" +
"489061589736155453144095545148190985660891326" +
"576261326549991792303912873247304434509759694" +
"274088584815015779154382635174538158301861164" +
"439921681110768794043391613853281233");
break;
case 7680:
p = new BigInteger("7034022146817764608206409206476311"
+ "1371065855827199565170055133179419153145313"