3.1.1 on Android crashes with NPE when trusting all certificates
See original GitHub issue// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
};
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.sslSocketFactory(sslContext.getSocketFactory())
.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
})
.build();
This crashes with the following stack trace:
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)
This used to worked with OkHttp 2 and 3.0.1. Now after updating to 3.1.1, our app crashes.
P. S. I know it’s not secure, don’t lecture me. 😉
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Android Studio 3.1.1, changing fragment causes input method ...
When changing the fragment with EditTexts in an activity,"java.lang.NullPointerException" happens (full stack trace is below).
Read more >NullPointerException in CertificatePinner.check() · Issue #2337
It's an interesting bug report. It suggests that somehow the certificate isn't trusted, but this happens after a successful TLS handshake If you ......
Read more >Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >3.x Change Log - OkHttp
Fix: Don't crash when building HandshakeCertificates on Android API 28. ... OkHttp now uses @Nullable to annotate all possibly-null values.
Read more >Firebase Android SDK Release Notes
Learn how to install these SDKs in your app: Add Firebase to your Android Project ... Fixed a NullPointerException crash when instrumenting screen...
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
@rmakki does changing
getAcceptedIssuers()
work?Do not return
null
fromgetAcceptedIssuers()
, return a zero-length array instead.