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); }