From 223cc6451860f10fe8095705da07aaf7e882188f Mon Sep 17 00:00:00 2001 From: Matthew Donovan Date: Wed, 19 Nov 2025 19:14:33 +0000 Subject: [PATCH] 8343316: Review and update tests using explicit provider names Reviewed-by: rhalade --- .../KeyAgreement/DHGenSharedSecret.java | 11 ++++++---- .../KeyAgreement/DHKeyAgreement2.java | 21 ++++++++++--------- .../KeyAgreement/DHKeyAgreement3.java | 17 ++++++++------- .../Provider/ProviderVersionCheck.java | 7 ++++++- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHGenSharedSecret.java b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHGenSharedSecret.java index 9fe96d967dc..a89efa7bddd 100644 --- a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHGenSharedSecret.java +++ b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHGenSharedSecret.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, 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 @@ -39,6 +39,9 @@ import jdk.test.lib.security.SecurityUtils; public class DHGenSharedSecret { + private static final String PROVIDER_NAME = + System.getProperty("test.provider.name", "SunJCE"); + public static void main(String[] args) throws Exception { DHGenSharedSecret test = new DHGenSharedSecret(); test.run(); @@ -57,7 +60,7 @@ public class DHGenSharedSecret { // generate keyPairs using parameters KeyPairGenerator keyGen = - KeyPairGenerator.getInstance("DH", "SunJCE"); + KeyPairGenerator.getInstance("DH", PROVIDER_NAME); keyGen.initialize(spec); // Alice generates her key pairs @@ -77,11 +80,11 @@ public class DHGenSharedSecret { // bob uses it to generate Secret X509EncodedKeySpec x509Spec = new X509EncodedKeySpec(alicePubKeyEnc); - KeyFactory bobKeyFac = KeyFactory.getInstance("DH", "SunJCE"); + KeyFactory bobKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME); PublicKey alicePubKey = bobKeyFac.generatePublic(x509Spec); - KeyAgreement bobAlice = KeyAgreement.getInstance("DH", "SunJCE"); + KeyAgreement bobAlice = KeyAgreement.getInstance("DH", PROVIDER_NAME); start = System.currentTimeMillis(); bobAlice.init(keyB.getPrivate()); bobAlice.doPhase(alicePubKey, true); diff --git a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java index da583c9dc29..c972c8a696b 100644 --- a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java +++ b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, 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 @@ -53,7 +53,8 @@ import jdk.test.lib.security.SecurityUtils; public class DHKeyAgreement2 { - private static final String SUNJCE = "SunJCE"; + private static final String PROVIDER_NAME = System.getProperty( + "test.provider.name", "SunJCE"); // Hex formatter to upper case with ":" delimiter private static final HexFormat HEX_FORMATTER = HexFormat.ofDelimiter(":").withUpperCase(); @@ -90,7 +91,7 @@ public class DHKeyAgreement2 { // Some central authority creates new DH parameters System.err.println("Creating Diffie-Hellman parameters ..."); AlgorithmParameterGenerator paramGen - = AlgorithmParameterGenerator.getInstance("DH", SUNJCE); + = AlgorithmParameterGenerator.getInstance("DH", PROVIDER_NAME); paramGen.init(primeSize); AlgorithmParameters params = paramGen.generateParameters(); dhParameterSpec = (DHParameterSpec)params.getParameterSpec @@ -108,7 +109,7 @@ public class DHKeyAgreement2 { * above */ System.err.println("ALICE: Generate DH keypair ..."); - KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", SUNJCE); + KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME); aliceKpairGen.initialize(dhParameterSpec); KeyPair aliceKpair = aliceKpairGen.generateKeyPair(); System.out.println("Alice DH public key:\n" + @@ -117,14 +118,14 @@ public class DHKeyAgreement2 { aliceKpair.getPrivate().toString()); DHParameterSpec dhParamSpec = ((DHPublicKey)aliceKpair.getPublic()).getParams(); - AlgorithmParameters algParams = AlgorithmParameters.getInstance("DH", SUNJCE); + AlgorithmParameters algParams = AlgorithmParameters.getInstance("DH", PROVIDER_NAME); algParams.init(dhParamSpec); System.out.println("Alice DH parameters:\n" + algParams.toString()); // Alice executes Phase1 of her version of the DH protocol System.err.println("ALICE: Execute PHASE1 ..."); - KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", SUNJCE); + KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME); aliceKeyAgree.init(aliceKpair.getPrivate()); // Alice encodes her public key, and sends it over to Bob. @@ -135,7 +136,7 @@ public class DHKeyAgreement2 { * in encoded format. * He instantiates a DH public key from the encoded key material. */ - KeyFactory bobKeyFac = KeyFactory.getInstance("DH", SUNJCE); + KeyFactory bobKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME); X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec (alicePubKeyEnc); PublicKey alicePubKey = bobKeyFac.generatePublic(x509KeySpec); @@ -149,7 +150,7 @@ public class DHKeyAgreement2 { // Bob creates his own DH key pair System.err.println("BOB: Generate DH keypair ..."); - KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", SUNJCE); + KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME); bobKpairGen.initialize(dhParamSpec); KeyPair bobKpair = bobKpairGen.generateKeyPair(); System.out.println("Bob DH public key:\n" + @@ -159,7 +160,7 @@ public class DHKeyAgreement2 { // Bob executes Phase1 of his version of the DH protocol System.err.println("BOB: Execute PHASE1 ..."); - KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", SUNJCE); + KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME); bobKeyAgree.init(bobKpair.getPrivate()); // Bob encodes his public key, and sends it over to Alice. @@ -171,7 +172,7 @@ public class DHKeyAgreement2 { * Before she can do so, she has to instanticate a DH public key * from Bob's encoded key material. */ - KeyFactory aliceKeyFac = KeyFactory.getInstance("DH", SUNJCE); + KeyFactory aliceKeyFac = KeyFactory.getInstance("DH", PROVIDER_NAME); x509KeySpec = new X509EncodedKeySpec(bobPubKeyEnc); PublicKey bobPubKey = aliceKeyFac.generatePublic(x509KeySpec); System.err.println("ALICE: Execute PHASE2 ..."); diff --git a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement3.java b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement3.java index d4f70ea2563..5315d62aee8 100644 --- a/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement3.java +++ b/test/jdk/com/sun/crypto/provider/KeyAgreement/DHKeyAgreement3.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025, 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 @@ -50,6 +50,9 @@ import jdk.test.lib.security.SecurityUtils; public class DHKeyAgreement3 { + private static final String PROVIDER_NAME = + System.getProperty("test.provider.name", "SunJCE"); + // Hex formatter to upper case with ":" delimiter private static final HexFormat HEX_FORMATTER = HexFormat.ofDelimiter(":").withUpperCase(); @@ -70,36 +73,36 @@ public class DHKeyAgreement3 { // Alice creates her own DH key pair System.err.println("ALICE: Generate DH keypair ..."); - KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE"); + KeyPairGenerator aliceKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME); aliceKpairGen.initialize(dhParamSpec); KeyPair aliceKpair = aliceKpairGen.generateKeyPair(); // Bob creates his own DH key pair System.err.println("BOB: Generate DH keypair ..."); - KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE"); + KeyPairGenerator bobKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME); bobKpairGen.initialize(dhParamSpec); KeyPair bobKpair = bobKpairGen.generateKeyPair(); // Carol creates her own DH key pair System.err.println("CAROL: Generate DH keypair ..."); - KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH", "SunJCE"); + KeyPairGenerator carolKpairGen = KeyPairGenerator.getInstance("DH", PROVIDER_NAME); carolKpairGen.initialize(dhParamSpec); KeyPair carolKpair = carolKpairGen.generateKeyPair(); // Alice initialize System.err.println("ALICE: Initialize ..."); - KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", "SunJCE"); + KeyAgreement aliceKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME); aliceKeyAgree.init(aliceKpair.getPrivate()); // Bob initialize System.err.println("BOB: Initialize ..."); - KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", "SunJCE"); + KeyAgreement bobKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME); bobKeyAgree.init(bobKpair.getPrivate()); // Carol initialize System.err.println("CAROL: Initialize ..."); - KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH", "SunJCE"); + KeyAgreement carolKeyAgree = KeyAgreement.getInstance("DH", PROVIDER_NAME); carolKeyAgree.init(carolKpair.getPrivate()); diff --git a/test/jdk/java/security/Provider/ProviderVersionCheck.java b/test/jdk/java/security/Provider/ProviderVersionCheck.java index 43d1c502b3f..2af2be0a7ad 100644 --- a/test/jdk/java/security/Provider/ProviderVersionCheck.java +++ b/test/jdk/java/security/Provider/ProviderVersionCheck.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, 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 @@ -42,6 +42,11 @@ public class ProviderVersionCheck { for (Provider p: Security.getProviders()) { System.out.print(p.getName() + " "); + if (p.getName().equals(System.getProperty("test.provider.name"))) { + // Version numbers of non JDK-providers do not match JDK version number. + continue; + } + String specVersion = System.getProperty("java.specification.version"); if (p.getVersion() != Double.parseDouble(specVersion)) { System.out.println("failed. " + "Version received was " +