@@ -64,57 +64,59 @@ public class KeyPairGeneratorTest {
6464
6565 @ Test
6666 public void test_getInstance () throws Exception {
67- ServiceTester .test ("KeyPairGenerator" )
68- // Do not test AndroidKeyStore Provider. It does not accept vanilla public keys for
69- // signature verification. It's OKish not to test here because it's tested by
70- // cts/tests/tests/keystore.
71- .skipProvider ("AndroidKeyStore" )
72- // The SunEC provider tries to pass a sun-only AlgorithmParameterSpec to the default
73- // AlgorithmParameters:EC when its KeyPairGenerator is initialized. Since Conscrypt
74- // is the highest-ranked provider when running our tests, its implementation of
75- // AlgorithmParameters:EC is returned, and it doesn't understand the special
76- // AlgorithmParameterSpec, so the KeyPairGenerator can't be initialized.
77- .skipProvider ("SunEC" )
78- // The SunPKCS11-NSS provider on OpenJDK 7 attempts to delegate to the SunEC provider,
79- // which doesn't exist on OpenJDK 7, and thus totally fails. This appears to be a bug
80- // introduced into later revisions of OpenJDK 7.
81- .skipProvider ("SunPKCS11-NSS" )
82- .run (new ServiceTester .Test () {
83- @ Override
84- public void test (Provider provider , String algorithm ) throws Exception {
85- AlgorithmParameterSpec params = null ;
86-
87- if ("DH" .equals (algorithm ) || "DiffieHellman" .equalsIgnoreCase (algorithm )) {
88- params = getDHParams ();
89- }
90- // KeyPairGenerator.getInstance(String)
91- KeyPairGenerator kpg1 = KeyPairGenerator .getInstance (algorithm );
92- assertEquals (algorithm , kpg1 .getAlgorithm ());
93- if (params != null ) {
94- kpg1 .initialize (params );
67+ ServiceTester
68+ .test ("KeyPairGenerator" )
69+ // Do not test AndroidKeyStore Provider. It does not accept vanilla public keys for
70+ // signature verification. It's OKish not to test here because it's tested by
71+ // cts/tests/tests/keystore.
72+ .skipProvider ("AndroidKeyStore" )
73+ // The SunEC provider tries to pass a sun-only AlgorithmParameterSpec to the default
74+ // AlgorithmParameters:EC when its KeyPairGenerator is initialized. Since Conscrypt
75+ // is the highest-ranked provider when running our tests, its implementation of
76+ // AlgorithmParameters:EC is returned, and it doesn't understand the special
77+ // AlgorithmParameterSpec, so the KeyPairGenerator can't be initialized.
78+ .skipProvider ("SunEC" )
79+ // The SunPKCS11-NSS provider on OpenJDK 7 attempts to delegate to the SunEC
80+ // provider, which doesn't exist on OpenJDK 7, and thus totally fails. This appears
81+ // to be a bug introduced into later revisions of OpenJDK 7.
82+ .skipProvider ("SunPKCS11-NSS" )
83+ .run (new ServiceTester .Test () {
84+ @ Override
85+ // g3-add: @SuppressWarnings("InsecureCryptoUsage")
86+ public void test (Provider provider , String algorithm ) throws Exception {
87+ AlgorithmParameterSpec params = null ;
88+
89+ if ("DH" .equals (algorithm ) || "DiffieHellman" .equalsIgnoreCase (algorithm )) {
90+ params = getDHParams ();
91+ }
92+ // KeyPairGenerator.getInstance(String)
93+ KeyPairGenerator kpg1 = KeyPairGenerator .getInstance (algorithm );
94+ assertEquals (algorithm , kpg1 .getAlgorithm ());
95+ if (params != null ) {
96+ kpg1 .initialize (params );
97+ }
98+ test_KeyPairGenerator (kpg1 );
99+
100+ // KeyPairGenerator.getInstance(String, Provider)
101+ KeyPairGenerator kpg2 = KeyPairGenerator .getInstance (algorithm , provider );
102+ assertEquals (algorithm , kpg2 .getAlgorithm ());
103+ assertEquals (provider , kpg2 .getProvider ());
104+ if (params != null ) {
105+ kpg2 .initialize (params );
106+ }
107+ test_KeyPairGenerator (kpg2 );
108+
109+ // KeyPairGenerator.getInstance(String, String)
110+ KeyPairGenerator kpg3 =
111+ KeyPairGenerator .getInstance (algorithm , provider .getName ());
112+ assertEquals (algorithm , kpg3 .getAlgorithm ());
113+ assertEquals (provider , kpg3 .getProvider ());
114+ if (params != null ) {
115+ kpg3 .initialize (params );
116+ }
117+ test_KeyPairGenerator (kpg3 );
95118 }
96- test_KeyPairGenerator (kpg1 );
97-
98- // KeyPairGenerator.getInstance(String, Provider)
99- KeyPairGenerator kpg2 = KeyPairGenerator .getInstance (algorithm , provider );
100- assertEquals (algorithm , kpg2 .getAlgorithm ());
101- assertEquals (provider , kpg2 .getProvider ());
102- if (params != null ) {
103- kpg2 .initialize (params );
104- }
105- test_KeyPairGenerator (kpg2 );
106-
107- // KeyPairGenerator.getInstance(String, String)
108- KeyPairGenerator kpg3 = KeyPairGenerator .getInstance (algorithm ,
109- provider .getName ());
110- assertEquals (algorithm , kpg3 .getAlgorithm ());
111- assertEquals (provider , kpg3 .getProvider ());
112- if (params != null ) {
113- kpg3 .initialize (params );
114- }
115- test_KeyPairGenerator (kpg3 );
116- }
117- });
119+ });
118120 }
119121
120122 private static final Map <String , List <Integer >> KEY_SIZES = new HashMap <>();
@@ -301,6 +303,7 @@ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
301303 test_KeyWithAllKeyFactories (k );
302304 }
303305
306+ // g3-add: @SuppressWarnings("InsecureCryptoUsage")
304307 private void test_KeyWithAllKeyFactories (Key k ) throws Exception {
305308 byte [] encoded = k .getEncoded ();
306309
@@ -446,6 +449,7 @@ private static DHParameterSpec getDHParams() {
446449 });
447450
448451 @ Test
452+ // g3-add: @SuppressWarnings("InsecureCryptoUsage")
449453 public void testDSAGeneratorWithParams () throws Exception {
450454 final DSAParameterSpec dsaSpec = new DSAParameterSpec (DSA_P , DSA_Q , DSA_G );
451455
0 commit comments