Skip to content

Commit

Permalink
Gate this change to versions less than 24, which are the affected ver…
Browse files Browse the repository at this point in the history
…sion.
  • Loading branch information
Andy Valdez committed Aug 28, 2024
1 parent ca2f398 commit 6690beb
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Simperium/src/main/java/com/simperium/android/AndroidClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

import android.os.Build;
import android.util.Log;

/**
Expand Down Expand Up @@ -85,18 +86,23 @@ public AndroidClient(Context context){

mSessionId = String.format("%s-%s", Version.LIBRARY_NAME, sessionToken);

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");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
// This code manually adds two trusted certificates for SSL.
// See this for more info: https://letsencrypt.org/2023/07/10/cross-sign-expiration.
// I got the certificates directly from letsencrypt here: https://letsencrypt.org/certificates/.
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) };
Expand Down

0 comments on commit 6690beb

Please sign in to comment.