Skip to content

Commit 75af15e

Browse files
dulmandakhfacebook-github-bot
authored andcommitted
use Conscrypt as security provider if available (#23984)
Summary: This PR adds support to use Conscrypt as Security Provider if available runtime. Consscrypt supports TLS 1.2 on Android 4.x and TLS 1.3 on all Android versions. Fixes issues (ex #23151) with HTTPS connections on Android 4.x. Just add below to your project build.gradle and it'll use it. ```gradle implementation('org.conscrypt:conscrypt-android:2.0.0') ``` [Android] [Changed] - Add TLS 1.3 support to all Android versions using Conscrypt. Pull Request resolved: #23984 Differential Revision: D14506000 Pulled By: cpojer fbshipit-source-id: 58bf18f7203d20519fb4451bae83f01e2f020a44
1 parent eec2495 commit 75af15e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/network/OkHttpClientProvider.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import com.facebook.common.logging.FLog;
1414

1515
import java.io.File;
16+
import java.security.Provider;
17+
import java.security.Security;
1618
import java.util.ArrayList;
1719
import java.util.List;
1820
import java.util.concurrent.TimeUnit;
@@ -69,7 +71,14 @@ public static OkHttpClient.Builder createClientBuilder() {
6971
.writeTimeout(0, TimeUnit.MILLISECONDS)
7072
.cookieJar(new ReactCookieJarContainer());
7173

72-
return enableTls12OnPreLollipop(client);
74+
try {
75+
Class ConscryptProvider = Class.forName("org.conscrypt.OpenSSLProvider");
76+
Security.insertProviderAt(
77+
(Provider) ConscryptProvider.newInstance(), 1);
78+
return client;
79+
} catch (Exception e) {
80+
return enableTls12OnPreLollipop(client);
81+
}
7382
}
7483

7584
public static OkHttpClient.Builder createClientBuilder(Context context) {

0 commit comments

Comments
 (0)