aboutsummaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorEric Anderson <ejona@google.com>2018-02-15 17:14:10 -0800
committerEric Anderson <ejona@google.com>2018-03-23 10:05:45 -0700
commit7eab0d9468ae55bd2b443ae7738f9b8c03f43f26 (patch)
treeb0a908ec379ddc6b6956a0bc1cb53b9770c9782a /testing
parent0859d480e7c1498f811778d36114d9233345926a (diff)
downloadgrpc-grpc-java-7eab0d9468ae55bd2b443ae7738f9b8c03f43f26.tar.gz
netty: Add support for Conscrypt
Diffstat (limited to 'testing')
-rw-r--r--testing/src/main/java/io/grpc/internal/testing/TestUtils.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/src/main/java/io/grpc/internal/testing/TestUtils.java b/testing/src/main/java/io/grpc/internal/testing/TestUtils.java
index 8ca934ec3..59fe4172c 100644
--- a/testing/src/main/java/io/grpc/internal/testing/TestUtils.java
+++ b/testing/src/main/java/io/grpc/internal/testing/TestUtils.java
@@ -24,12 +24,15 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
+import java.security.Security;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
@@ -142,6 +145,43 @@ public class TestUtils {
}
}
+ private static boolean conscryptInstallAttempted;
+
+ /**
+ * Add Conscrypt to the list of security providers, if it is available. If it appears to be
+ * available but fails to load, this method will throw an exception. Since the list of security
+ * providers is static, this method does nothing if the provider is not available or succeeded
+ * previously.
+ */
+ public static void installConscryptIfAvailable() {
+ if (conscryptInstallAttempted) {
+ return;
+ }
+ Class<?> conscrypt;
+ try {
+ conscrypt = Class.forName("org.conscrypt.Conscrypt");
+ } catch (ClassNotFoundException ex) {
+ conscryptInstallAttempted = true;
+ return;
+ }
+ Method newProvider;
+ try {
+ newProvider = conscrypt.getMethod("newProvider");
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException("Could not find newProvider method on Conscrypt", ex);
+ }
+ Provider provider;
+ try {
+ provider = (Provider) newProvider.invoke(null);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException("Could not invoke Conscrypt.newProvider", ex);
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException("Could not invoke Conscrypt.newProvider", ex);
+ }
+ Security.addProvider(provider);
+ conscryptInstallAttempted = true;
+ }
+
/**
* Creates an SSLSocketFactory which contains {@code certChainFile} as its only root certificate.
*/