From 0a3dcc7f064e371ec0d6e2aa67585811d98e95a7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Sep 2019 10:55:49 +0800 Subject: [PATCH] up --- .../java/io/legado/app/help/http/SSLHelper.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt index 8fc40d27c..ef70ac1b5 100644 --- a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt @@ -1,5 +1,6 @@ package io.legado.app.help.http +import android.annotation.SuppressLint import java.io.IOException import java.io.InputStream import java.security.KeyManagementException @@ -21,10 +22,12 @@ object SSLHelper { * 这是一种有很大安全漏洞的办法 */ val unsafeTrustManager: X509TrustManager = object : X509TrustManager { + @SuppressLint("TrustAllX509TrustManager") @Throws(CertificateException::class) override fun checkClientTrusted(chain: Array, authType: String) { } + @SuppressLint("TrustAllX509TrustManager") @Throws(CertificateException::class) override fun checkServerTrusted(chain: Array, authType: String) { } @@ -34,16 +37,15 @@ object SSLHelper { } } - val unsafeSSLSocketFactory: SSLSocketFactory - get() { - try { - val sslContext = SSLContext.getInstance("SSL") - sslContext.init(null, arrayOf(unsafeTrustManager), SecureRandom()) - return sslContext.socketFactory - } catch (e: Exception) { - throw RuntimeException(e) - } + val unsafeSSLSocketFactory: SSLSocketFactory by lazy { + try { + val sslContext = SSLContext.getInstance("SSL") + sslContext.init(null, arrayOf(unsafeTrustManager), SecureRandom()) + sslContext.socketFactory + } catch (e: Exception) { + throw RuntimeException(e) } + } /** * 此类是用于主机名验证的基接口。 在握手期间,如果 URL 的主机名和服务器的标识主机名不匹配,