sslSocketFactory NullPointException
See original GitHub issueOkHttpClient.Builder mBuilder=mBuilder = new OkHttpClient.Builder();
mBuilder.sslSocketFactory(createSSLSocketFactory());
mBuilder.hostnameVerifier(new TrustAllHostnameVerifier());
mBuilder.build();
/**
* 默认信任所有的证书
* TODO 最好加上证书认证,主流App都有自己的证书
*
* @return
*/
@SuppressLint("TrulyRandom")
private static SSLSocketFactory createSSLSocketFactory() {
SSLSocketFactory sSLSocketFactory = null;
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[]{new TrustAllManager()},
new SecureRandom());
sSLSocketFactory = sc.getSocketFactory();
} catch (Exception e) {
}
return sSLSocketFactory;
}
private static class TrustAllManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
private static class TrustAllHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
this will cause NullPointException in 3.1.2,but it’s ok in 3.0.1
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at okhttp3.internal.tls.RealTrustRootIndex.<init>(RealTrustRootIndex.java:31)
at okhttp3.internal.Platform.trustRootIndex(Platform.java:97)
at okhttp3.internal.Platform$Android.trustRootIndex(Platform.java:271)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:189)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:718)
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
NullPointerException when creating an SSL-Socket
createSocket(SSLSocketFactory.java:375) W/System.err( 2328): at ... point where the NullPointerException can come from is because sslParameters is null .
Read more >PM14425: SSLSOCKETFACTORY.CREATESOCKET ... - IBM
NullPointerException at com.ibm.websphere.ssl.protocol.SSLSocketFactory.createSocket(SSL SocketFactory.java:431) FFDC reports the following message ...
Read more >nullpointer at SSLSocketFactory.createSocket ... - CodeRanch
I am attempting to make a HTTPS POST call from my Websphere application. Locally on my machine the below code works but when...
Read more >Websphere SSL socket implementation can return null for ...
SSLSocketFactory. Exception: com.mongodb.MongoException: java.lang.NullPointerException. at com.mongodb.connection.
Read more >1918144 – Null pointer exception on ssl connection
getDefault(SSLSocketFactory.java:123) at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Change your TrustAllManager to do this:
bug bug 崩溃