I am working on a project that needs to utilize allow all certificates for a single call and whenever I tried setting the sslSocketFactory, I would receive an error indicating an ExceptionInInitializerError.
I searched SO and found this question, but it did not resolve the issue for me; same for this Git issue.
My sample code is below:
X509TrustManager trustManager = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string)
throws CertificateException {}
public void checkServerTrusted(X509Certificate[] xcs, String string)
throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext;
SSLSocketFactory sslSocketFactory = null;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{trustManager}, null);
sslSocketFactory = sslContext.getSocketFactory();
} catch (Exception e){
e.printStackTrace();
}
OkHttpClient client = new OkHttpClient.Builder().sslSocketFactory(sslSocketFactory,
trustManager).addInterceptor(interceptor).build();
Why would I be receiving an error when the params being sent are all valid and not null?