From ca2f3981ca397fc2488bfcc40b1a9c9a3fef4e33 Mon Sep 17 00:00:00 2001 From: Andy Valdez Date: Wed, 28 Aug 2024 17:10:05 -0400 Subject: [PATCH] First change didn't work. Take 2. --- .../com/simperium/android/AndroidClient.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Simperium/src/main/java/com/simperium/android/AndroidClient.java b/Simperium/src/main/java/com/simperium/android/AndroidClient.java index e1c60f6..e86adf5 100644 --- a/Simperium/src/main/java/com/simperium/android/AndroidClient.java +++ b/Simperium/src/main/java/com/simperium/android/AndroidClient.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; +import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -25,6 +26,8 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; + +import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; @@ -82,11 +85,21 @@ public AndroidClient(Context context){ mSessionId = String.format("%s-%s", Version.LIBRARY_NAME, sessionToken); - TrustManager[] trustManagers = new TrustManager[] { - buildPinnedTrustManager(context), - loadCertificate(context, R.raw.isrgrootx1), - loadCertificate(context, R.raw.isrgrootx2) - }; + try { + final SSLContext sslContext = SSLContext.getInstance("TLS"); + final TrustManager[] customTrustManagers = new TrustManager[]{ + loadCertificate(context, R.raw.isrgrootx1), + loadCertificate(context, R.raw.isrgrootx2) + }; + sslContext.init(null, customTrustManagers, null); + mHttpClient.getSSLSocketMiddleware().setSSLContext(sslContext); + } catch (NoSuchAlgorithmException e) { + Log.e(TAG, "Problem getting instance of SSLContext"); + } catch (KeyManagementException e) { + Log.e(TAG, "Problem trying to init SSLContext"); + } + + TrustManager[] trustManagers = new TrustManager[] { buildPinnedTrustManager(context) }; mHttpClient.getSSLSocketMiddleware().setTrustManagers(trustManagers); }