【问题标题】:Android 11 - Unable to extract the trust manager on AndroidPlatform, sslSocketFactory is class com.android.org.conscrypt.OpenSSLSocketFactoryImplAndroid 11 - 无法在 AndroidPlatform 上提取信任管理器,sslSocketFactory 是类 com.android.org.conscrypt.OpenSSLSocketFactoryImpl
【发布时间】:2021-02-01 14:16:01
【问题描述】:

Android 11 - 无法在 AndroidPlatform 上提取信任管理器,sslSocketFactory 是类 com.android.org.conscrypt.OpenSSLSocketFactoryImpl

问题仅适用于 Android 11 设备

【问题讨论】:

  • 这个问题有什么解决办法吗?

标签: android okhttp android-11


【解决方案1】:

您正在调用已弃用的方法https://github.com/square/okhttp/blob/fce60e5a09eac198a0f9c676e486163212662230/okhttp/src/main/kotlin/okhttp3/OkHttpClient.kt#L761

    /**
     * Sets the socket factory used to secure HTTPS connections. If unset, the system default will
     * be used.
     *
     * @deprecated [SSLSocketFactory] does not expose its [X509TrustManager], which is a field that
     *     OkHttp needs to build a clean certificate chain. This method instead must use reflection
     *     to extract the trust manager. Applications should prefer to call
     *     `sslSocketFactory(SSLSocketFactory, X509TrustManager)`, which avoids such reflection.
     */
    @Deprecated(
        message = "Use the sslSocketFactory overload that accepts a X509TrustManager.",
        level = DeprecationLevel.ERROR
    )
    fun sslSocketFactory(sslSocketFactory: SSLSocketFactory) = apply {
      if (sslSocketFactory != this.sslSocketFactoryOrNull) {
        this.routeDatabase = null
      }

      this.sslSocketFactoryOrNull = sslSocketFactory
      this.x509TrustManagerOrNull = Platform.get().trustManager(sslSocketFactory) ?: throw IllegalStateException(
          "Unable to extract the trust manager on ${Platform.get()}, " +
              "sslSocketFactory is ${sslSocketFactory.javaClass}")
      this.certificateChainCleaner = Platform.get().buildCertificateChainCleaner(x509TrustManagerOrNull!!)
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 2015-03-09
    • 2012-11-24
    • 2019-11-22
    • 2020-10-18
    • 2014-04-11
    • 2014-11-09
    相关资源
    最近更新 更多