okhttp: Unable to extract the trust manager
Hi, after upgrading from OkHttp 3.0.1 to 3.1.0 I get the following stack trace and crash after calling build() to create a OkHttpClient.
java.lang.IllegalStateException: Unable to extract the trust manager on okhttp3.internal.Platform$Android@1d8cf999, sslSocketFactory is class com.google.android.gms.org.conscrypt.KitKatPlatformOpenSSLSocketAdapterFactory
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:187)
at okhttp3.OkHttpClient.<init>(OkHttpClient.java:60)
at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:719)
This issue was not present in 3.0.1.
Here’s where the crash happens:
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS);
OkHttpClient client = builder.build();
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 72 (18 by maintainers)
Links to this issue
Commits related to this issue
- Support the GMS security provider when searching for the trust manager. Closes https://github.com/square/okhttp/issues/2323 — committed to square/okhttp by swankjesse 8 years ago
- Support the GMS security provider when searching for the trust manager. Closes https://github.com/square/okhttp/issues/2323 — committed to square/okhttp by swankjesse 8 years ago
I experienced this error while using a custom
SocketFactory
. I realized I didn’t add all the necessary ProGuard rules. I added the following to fix the issue:In my SocketFactory class, I had the following field:
So adjust the ProGuard rule accordingly. E.g, the access modifiers like
private
,final
, etc. as well as the field name (delegate
) should match exactly as written in the class file.Wildfly 10, java8, and any version > 3.0.1: Unable to extract the trust manager on okhttp3.internal.Platform@10c89bdf, sslSocketFactory is class sun.security.ssl.SSLSocketFactoryImpl
If you rename that factory’s private
defaultFactory
field todelegate
, the hacky detector we use will do the right thing.@feresr looks like PowerMock is causing you harm here. http://stackoverflow.com/questions/14654639/when-a-trustmanagerfactory-is-not-a-trustmanagerfactory-java
to
Hey @swankjesse. I figured it would be a matter of time 😃
It turns out we actually do give our delegate factory the variable name “delegate”… but ProGuard changes it. It should be an easy fix. I believe we’ll just need to update our OkHttp regression tests to use the latest version.
For others that are watching, we’re still wrapping up some large changes to our networking monitoring code. We should be able to get to this in about 2-3 weeks.
For the Apteligent Android SDK, we’ve made some changes in version 5.6.2 that should address the issue. You can find the downloadable file for the version here:
https://app.crittercism.com/downloads/download/crittercism_v5_6_2_sdkonly.jar
+1 Having this same issue on retrofit:2.1.0, I’m simply trying to build an instance of retrofit on the setUp method of a test. I’m not event using roboelectric, I am using Mockito and PowerMock though
Full stacktrace:
The 2nd problem is currently if you want to pass an SSL session cache, you have to pass in a SSL Socket factory:
But even for stock Android
SSLCertificateSocketFactory
relies oncom.android.org.conscrypt.OpenSSLContextImpl
so the trust manager code fails looking forsun.security.ssl.SSLContextImpl
.It turns out the Parse Android SDK, which includes OkHttp2, can’t be upgraded until we get to 3.3.0. I attempted to do so just now and ran into the issue here. https://github.com/ParsePlatform/Parse-SDK-Android/pull/435/files#r58793351
I can get around the issue by using the snapshot version and implementing the code to get the default trust manager:
And then later:
So waiting for the 3.3.0 release before Parse’s Android SDK implementation can be bumped to use OkHttp3. 😃
@swankjesse thanks for the suggestion! I was already using reflection to set certain fields so the internal reflection would not run (kind of ironic if you think about it)
Edit: tested, and it works, thanks! Current solution looks like this:
Can you please elaborate on your above comment a little bit more @swankjesse !! That would be very helpful.