Преглед изворни кода

Merge pull request #472 from xamoulin/fix/deprecated-sslSocketFactory

Use non deprecated version of the method OkHttpClient.builder.sslSocketFactory
Travis Nuttall пре 5 година
родитељ
комит
e2eef2c5b9
No account linked to committer's email address
1 измењених фајлова са 15 додато и 16 уклоњено
  1. 15
    16
      android/src/main/java/com/RNFetchBlob/RNFetchBlobUtils.java

+ 15
- 16
android/src/main/java/com/RNFetchBlob/RNFetchBlobUtils.java Прегледај датотеку

@@ -56,22 +56,21 @@ public class RNFetchBlobUtils {
56 56
     public static OkHttpClient.Builder getUnsafeOkHttpClient(OkHttpClient client) {
57 57
         try {
58 58
             // Create a trust manager that does not validate certificate chains
59
-            final TrustManager[] trustAllCerts = new TrustManager[]{
60
-                    new X509TrustManager() {
61
-                        @Override
62
-                        public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
63
-                        }
64
-
65
-                        @Override
66
-                        public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
67
-                        }
68
-
69
-                        @Override
70
-                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
71
-                            return new java.security.cert.X509Certificate[]{};
72
-                        }
73
-                    }
59
+            final X509TrustManager x509TrustManager = new X509TrustManager() {
60
+                @Override
61
+                public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
62
+                }
63
+
64
+                @Override
65
+                public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
66
+                }
67
+
68
+                @Override
69
+                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
70
+                    return new java.security.cert.X509Certificate[]{};
71
+                }
74 72
             };
73
+            final TrustManager[] trustAllCerts = new TrustManager[]{ x509TrustManager };
75 74
 
76 75
             // Install the all-trusting trust manager
77 76
             final SSLContext sslContext = SSLContext.getInstance("SSL");
@@ -80,7 +79,7 @@ public class RNFetchBlobUtils {
80 79
             final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
81 80
 
82 81
             OkHttpClient.Builder builder = client.newBuilder();
83
-            builder.sslSocketFactory(sslSocketFactory);
82
+            builder.sslSocketFactory(sslSocketFactory, x509TrustManager);
84 83
             builder.hostnameVerifier(new HostnameVerifier() {
85 84
                 @Override
86 85
                 public boolean verify(String hostname, SSLSession session) {