aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWycheproof Team <noreply@google.com>2023-11-03 11:20:20 -0700
committerCopybara-Service <copybara-worker@google.com>2023-11-03 11:21:12 -0700
commitd9f6ec7d8bd8c96da05368999094e4a75ba5cb3d (patch)
tree00caf5d6e70cd990365414f4b4063e64c1b12597
parentcd5d271eab5c841f734d044683e4e30b76f65abb (diff)
downloadwycheproof-d9f6ec7d8bd8c96da05368999094e4a75ba5cb3d.tar.gz
Migrate off unsupported internal JDK APIs.
PiperOrigin-RevId: 579244139
-rw-r--r--BUILD.bazel8
-rw-r--r--WORKSPACE9
-rw-r--r--java/com/google/security/wycheproof/TestUtil.java31
-rw-r--r--java/com/google/security/wycheproof/TestUtilTest.java9
-rw-r--r--wycheproof.java.security4
5 files changed, 43 insertions, 18 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index dd5c889..e37b2d0 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -16,6 +16,7 @@ java_library(
],
deps = [
"@com_google_code_gson_gson",
+ "@com_google_guava",
"@junit",
],
)
@@ -25,8 +26,15 @@ java_test(
size = "small",
srcs = ["java/com/google/security/wycheproof/TestUtilTest.java"],
test_class = "com.google.security.wycheproof.TestUtilTest",
+ data = [
+ ":wycheproof.java.security",
+ ],
+ jvm_flags = [
+ "-Djava.security.properties=$(location //:wycheproof.java.security)",
+ ],
deps = [
":utils",
+ "@com_google_guava",
"@junit",
],
)
diff --git a/WORKSPACE b/WORKSPACE
index 8f293b5..6b427c2 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -386,6 +386,15 @@ java_import_external(
licenses = ["notice"], # Apache 2.0
)
+java_import_external(
+ name = "com_google_guava",
+ licenses = ["notice"], # The Apache Software License, Version 2.0
+ jar_sha256 = "6d4e2b5a118aab62e6e5e29d185a0224eed82c85c40ac3d33cf04a270c3b3744",
+ jar_urls = [
+ "https://repo1.maven.org/maven2/com/google/guava/guava/32.1.3-jre/guava-32.1.3-jre.jar",
+ ],
+)
+
load("//tools:local_repository_defs.bzl", "local_jars")
local_jars(name = "local")
diff --git a/java/com/google/security/wycheproof/TestUtil.java b/java/com/google/security/wycheproof/TestUtil.java
index 27e82ff..635473d 100644
--- a/java/com/google/security/wycheproof/TestUtil.java
+++ b/java/com/google/security/wycheproof/TestUtil.java
@@ -13,10 +13,11 @@
*/
package com.google.security.wycheproof;
-
+import com.google.common.collect.ImmutableSet;
import java.nio.ByteBuffer;
import java.security.Provider;
import java.security.Security;
+import java.util.Set;
import org.junit.Assume;
/** Test utilities */
@@ -79,15 +80,19 @@ public class TestUtil {
return result;
}
- public static void removeAllProviders() {
+ public static void removeProvidersExcept(Set<Provider> toRetain) {
for (Provider p : Security.getProviders()) {
+ if (toRetain.contains(p)) {
+ System.out.println("Not removing provider: " + p.getName());
+ continue;
+ }
System.out.println("Removing provider: " + p.getName());
Security.removeProvider(p.getName());
}
}
public static void installOnlyThisProvider(Provider provider) {
- removeAllProviders();
+ removeProvidersExcept(ImmutableSet.of(provider));
Security.insertProviderAt(provider, 1);
}
@@ -125,17 +130,15 @@ public class TestUtil {
* </ul>
*/
public static void installOnlyOpenJDKProviders() throws Exception {
- removeAllProviders();
- installOpenJDKProvider("sun.security.provider.Sun");
- installOpenJDKProvider("com.sun.crypto.provider.SunJCE");
- installOpenJDKProvider("sun.security.rsa.SunRsaSign");
- installOpenJDKProvider("sun.security.ec.SunEC");
- }
-
- private static void installOpenJDKProvider(String className) throws Exception {
- Provider provider = (Provider) Class.forName(className).getConstructor().newInstance();
- System.out.println("Adding provider: " + provider.getName() + " (" + className + ")");
- Security.addProvider(provider);
+ removeProvidersExcept(
+ ImmutableSet.of(
+ Security.getProvider("SUN"),
+ Security.getProvider("SunJCE"),
+ Security.getProvider("SunEC"),
+ Security.getProvider("SunRsaSign")));
+ for (Provider p : Security.getProviders()) {
+ System.out.println("Maintaining provider: " + p.getName());
+ }
}
public static void printJavaInformation() {
diff --git a/java/com/google/security/wycheproof/TestUtilTest.java b/java/com/google/security/wycheproof/TestUtilTest.java
index a920de8..ca03ffa 100644
--- a/java/com/google/security/wycheproof/TestUtilTest.java
+++ b/java/com/google/security/wycheproof/TestUtilTest.java
@@ -12,8 +12,8 @@
package com.google.security.wycheproof;
import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
+import com.google.common.collect.ImmutableSet;
import java.security.Provider;
import java.security.Security;
import java.util.ArrayList;
@@ -35,10 +35,11 @@ public final class TestUtilTest {
}
@Test
- public void removeAllProviders_succeeds() throws Exception {
- TestUtil.removeAllProviders();
+ public void removeProvidersExcept_keepsProvider() throws Exception {
+ TestUtil.removeProvidersExcept(ImmutableSet.of(Security.getProvider("SUN")));
- assertTrue("List of providers is not empty", getProviders().isEmpty());
+ assertArrayEquals(
+ "Expected provider not present", getProviders().toArray(), new String[] {"SUN"});
}
@Test
diff --git a/wycheproof.java.security b/wycheproof.java.security
new file mode 100644
index 0000000..ee911c9
--- /dev/null
+++ b/wycheproof.java.security
@@ -0,0 +1,4 @@
+security.provider.1=SUN
+security.provider.2=SunJCE
+security.provider.3=SunRsaSign
+security.provider.4=SunEC