Android 在 OKHttp 中启用 TLSv1.2
i am using OKHttp for my project. i want to enable TLSv1.2 for my service call. can any body tell me how to enable it.
我在项目中使用 OKHttp。我想为我的服务调用启用 TLSv1.2。任何身体都能告诉 我如何去激活它。 7
See OkHttp’s HTTPS documentation. 看到 OkHttp HTTPS 文档。
ConnectionSpec
spec
=
new
ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .tlsVersions(TlsVersion.TLS _1_2)
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build();OkHttpClient
.cipherSuites(
client = ... client.setConnectionSpecs(Collections.singletonList(spec)); 7
As far as I know OKHttp does not include own SSL/TLS libraries, therefore it just uses the standard SSLSocket provided by Android.
据我所知 OKHttp 不包含自己的 SSL/TLS 库,因此它只使用 Android 提供的标准 SSLSocket。
What TLS versions are supported (and enabled) depends on the used Android version.
On some phone TLS 1.2 is supported but not enabled by default. In such cases you could
enable it by implementing a custom wrapper SSLSocketFactory that uses internally the
default SSLSocketFactory and calls setEnabledProtocols(new String{“TLS1.2”}) on every Socket that is created.
支持(并启用)哪些 TLS 版本取决于使用的 Android 版本。在某些电话上支持 TLS 1.2,但默认情况下不启用。在这种情况下,您可以通过实现自定义包装器