okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

NoSuchAlgorithmException: PKIX TrustManagerFactory not available

Open flocsy opened this issue 3 years ago • 7 comments

The folowing code: private static final OkHttpClient okHttpClient = new OkHttpClient(); produces the following error, when run in openjdk 17 using okhttp3 version 4.10.0:

java.security.NoSuchAlgorithmException: PKIX TrustManagerFactory not available
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
at java.base/javax.net.ssl.TrustManagerFactory.getInstance(TrustManagerFactory.java:164)
at okhttp3.internal.platform.Platform.platformTrustManager(Platform.kt:78)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:237)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:222)

flocsy avatar Aug 09 '22 13:08 flocsy

What is the output from java -version?

yschimke avatar Aug 09 '22 13:08 yschimke

java -version openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment (build 17.0.3+7-Ubuntu-0ubuntu0.22.04.1) OpenJDK 64-Bit Server VM (build 17.0.3+7-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

flocsy avatar Aug 09 '22 13:08 flocsy

It suggests the following is failing, which is worrying. Have you changed any security config?

https://github.com/square/okhttp/blob/okhttp_4.10.x/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt#L78

    val factory = TrustManagerFactory.getInstance(
        TrustManagerFactory.getDefaultAlgorithm())

yschimke avatar Aug 09 '22 13:08 yschimke

Not that I know of. This is a new AMI that devops prepared, because we're trying to move from java 8 to java 17, so there are lots of differences (like tomcat 9 instead of 7). Where would such security changes be in the filesystem?

flocsy avatar Aug 09 '22 13:08 flocsy

It turned out that we have the following:

ssl.KeyManagerFactory.algorithm=SunX509 ssl.TrustManagerFactory.algorithm=PKIX

flocsy avatar Aug 09 '22 13:08 flocsy

It's unlikely I can help from here, but we would expect that line of code above to execute, so can you confirm that first?

yschimke avatar Aug 09 '22 13:08 yschimke

Yes according to the stacktrace it executes that line. I asked devops to remove those 2 lines from the security settings, so we'll soon try it with the default settings of the jre.

flocsy avatar Aug 09 '22 13:08 flocsy

Closing, not an OkHttp issue.

yschimke avatar Aug 27 '22 13:08 yschimke