【问题标题】:Unable to Extract trust manager on IBM JRE8 with OKHTTP3无法使用 OKHTTP3 在 IBM JRE8 上提取信任管理器
【发布时间】:2020-09-08 05:19:23
【问题描述】:

请任何人帮忙。

我也在用OKHTTP3 version 4.8.1来写HTTP2 client。它适用于 Oracle JDK 8,但不适用于 IBM JRE 8。

错误信息: java.lang.IllegalStateException:无法在 okhttp3.internal.Platform@e85a0ce8 上提取信任管理器,sslSocketFactory 是 com.ibm.jsse2.SSLSocketFactoryImpl 类。

谢谢

【问题讨论】:

  • 能否请您包含代码的相关部分?
  • 我使用的是 OKhttp3 jar 的弃用方法。 sslSocketFactory(sslSocketFactory: SSLSocketFactory)。用 sslSocketFactory(sslSocketFactory: SSLSocketFactory,trustManager) 替换后。问题已解决。

标签: okhttp trustmanager x509trustmanager ibm-jre


【解决方案1】:

你依赖一个长期被弃用的方法

https://github.com/square/okhttp/blob/cd722373281202492043f4294fccfe6f691ddc01/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L741

它已被弃用,因为它必须对 JVM 做出很多假设,这会在每次 JVM 更新或跨供应商时中断。您应该改为使用 X509TrustManager 作为参数调用该方法

https://github.com/square/okhttp/blob/cd722373281202492043f4294fccfe6f691ddc01/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L767

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
    throw new IllegalStateException("Unexpected default trust managers:"
        + Arrays.toString(trustManagers));
}
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

OkHttpClient client = new OkHttpClient.Builder()
    .sslSocketFactory(sslSocketFactory, trustManager)
    .build();

【讨论】:

  • 此代码已修复错误“无法提取信任管理器”。感谢您的帮助
  • 在下一步中,ALPN 配置不适用于 Webshere 9 和 Java 8。使用 OKhttp3 客户端向 Apple 推送服务器发送 HTTP2 请求。服务器:Webshere 9 Java:8 OKhttp3:4.8.1 还在引导类路径中添加了 ALPN jar。 ALPN jar 版本与 bootclasspath 中的 JDK 版本准确映射。在 IBM Webshere 9 日志文件中获取此错误消息。 ALPN 回调被丢弃:HTTP/2 被禁用。 alpn-boot 在引导类路径上吗?谢谢你的帮助。
  • 我建议单独提问,以便更多人看到。
猜你喜欢
  • 1970-01-01
  • 2016-07-07
  • 1970-01-01
  • 2017-03-21
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多