mklimek / ssl-utils-android

The one line of code to trust custom certificate on Android
https://mklimek.github.io/trust-specific-certificate-on-jvm/
MIT License
59 stars 15 forks source link

setSslSocketFactory deprecated in okhttp3 #3

Open z0rti opened 5 years ago

z0rti commented 5 years ago

OkHttpClient client = new OkHttpClient(); SSLContext sslContext = SslUtils.getSslContextForCertificateFile(context, "BPClass2RootCA-sha2.cer"); client.setSslSocketFactory(sslContext.getSocketFactory());

Cannot resolve method 'setSslSocketFactory(javax.net.ssl.SSLSocketFactory)'

Update needed! ;-)

TheIvasyl commented 4 years ago

OKHttpClient documentation recomends relplacing

client.setSslSocketFactory(sslContext.getSocketFactory());

with

TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); X509TrustManager trustManager = (X509TrustManager) trustManagers[0];

client.sslSocketFactory(sslContext.getSocketFactory(), trustManager)