Skip to content
Permalink
Browse files
fix UnsupportedOperationException during setting socketFactory
  • Loading branch information
korlov42 authored and gaul committed Feb 12, 2021
1 parent 44ff69d commit d74dcca6dd109b22dbb7dd43b7dd21c4df002292
Showing 2 changed files with 8 additions and 2 deletions.
@@ -46,6 +46,7 @@ protected void configure() {
bind(new TypeLiteral<Supplier<SSLContext>>() {
}).annotatedWith(Names.named("untrusted")).to(new TypeLiteral<UntrustedSSLContextSupplier>() {
});
bind(X509TrustManager.class).annotatedWith(Names.named("untrusted")).to(TrustAllCerts.class);
}

/**
@@ -21,6 +21,7 @@
import javax.inject.Named;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.X509TrustManager;

import okhttp3.OkHttpClient;

@@ -56,15 +57,19 @@ protected void configure() {
private static final class OkHttpClientProvider implements Provider<OkHttpClient> {
private final HostnameVerifier verifier;
private final Supplier<SSLContext> untrustedSSLContextProvider;
private final X509TrustManager trustAllCertsManager;
private final HttpUtils utils;
private final OkHttpClientSupplier clientSupplier;

@Inject
OkHttpClientProvider(HttpUtils utils, @Named("untrusted") HostnameVerifier verifier,
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider, OkHttpClientSupplier clientSupplier) {
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider,
@Named("untrusted") X509TrustManager trustAllCertsManager,
OkHttpClientSupplier clientSupplier) {
this.utils = utils;
this.verifier = verifier;
this.untrustedSSLContextProvider = untrustedSSLContextProvider;
this.trustAllCertsManager = trustAllCertsManager;
this.clientSupplier = clientSupplier;
}

@@ -82,7 +87,7 @@ public OkHttpClient get() {
clientBuilder.hostnameVerifier(verifier);
}
if (utils.trustAllCerts()) {
clientBuilder.sslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory());
clientBuilder.sslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory(), trustAllCertsManager);
}

return clientBuilder.build();

0 comments on commit d74dcca

Please sign in to comment.