Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,7 @@ else if(this.options.fileCache)
OkHttpClient.Builder clientBuilder;

try {
// use trusty SSL socket
if (this.options.trusty) {
clientBuilder = RNFetchBlobUtils.getUnsafeOkHttpClient(client);
} else {
clientBuilder = client.newBuilder();
}
clientBuilder = client.newBuilder();

final Request.Builder builder = new Request.Builder();
try {
Expand Down
41 changes: 0 additions & 41 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,4 @@ public static void emitWarningEvent(String data) {
RNFetchBlob.RCTContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(RNFetchBlobConst.EVENT_MESSAGE, args);
}

public static OkHttpClient.Builder getUnsafeOkHttpClient(OkHttpClient client) {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}

@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}

@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
};

// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

OkHttpClient.Builder builder = client.newBuilder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});

return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}