Skip to content

Instantly share code, notes, and snippets.

@uchagani
Created July 21, 2023 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchagani/f4566fd6ffe2c93dd52dd559cebb19ac to your computer and use it in GitHub Desktop.
Save uchagani/f4566fd6ffe2c93dd52dd559cebb19ac to your computer and use it in GitHub Desktop.
Ignore SSL OKHTTP3 Configuration
// Add this when creating an OKHttp3 Client
var trustManager = new IgnoreSslTrustManager[]{new IgnoreSslTrustManager()};
var sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManager, new java.security.SecureRandom());
var okHttpClient = clientBuilder.addInterceptor(new AuthenticationInterceptor())
.sslSocketFactory(sslContext.getSocketFactory(), trustManager[0])
.hostnameVerifier((hostname, session) -> true)
.build();
import javax.net.ssl.X509TrustManager;
public class IgnoreSslTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment