|
|
@ -1,5 +1,6 @@ |
|
|
|
package io.legado.app.help.http |
|
|
|
package io.legado.app.help.http |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import java.io.InputStream |
|
|
|
import java.io.InputStream |
|
|
|
import java.security.KeyManagementException |
|
|
|
import java.security.KeyManagementException |
|
|
@ -21,10 +22,12 @@ object SSLHelper { |
|
|
|
* 这是一种有很大安全漏洞的办法 |
|
|
|
* 这是一种有很大安全漏洞的办法 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
val unsafeTrustManager: X509TrustManager = object : X509TrustManager { |
|
|
|
val unsafeTrustManager: X509TrustManager = object : X509TrustManager { |
|
|
|
|
|
|
|
@SuppressLint("TrustAllX509TrustManager") |
|
|
|
@Throws(CertificateException::class) |
|
|
|
@Throws(CertificateException::class) |
|
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) { |
|
|
|
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("TrustAllX509TrustManager") |
|
|
|
@Throws(CertificateException::class) |
|
|
|
@Throws(CertificateException::class) |
|
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) { |
|
|
|
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) { |
|
|
|
} |
|
|
|
} |
|
|
@ -34,12 +37,11 @@ object SSLHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val unsafeSSLSocketFactory: SSLSocketFactory |
|
|
|
val unsafeSSLSocketFactory: SSLSocketFactory by lazy { |
|
|
|
get() { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
val sslContext = SSLContext.getInstance("SSL") |
|
|
|
val sslContext = SSLContext.getInstance("SSL") |
|
|
|
sslContext.init(null, arrayOf(unsafeTrustManager), SecureRandom()) |
|
|
|
sslContext.init(null, arrayOf(unsafeTrustManager), SecureRandom()) |
|
|
|
return sslContext.socketFactory |
|
|
|
sslContext.socketFactory |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
throw RuntimeException(e) |
|
|
|
throw RuntimeException(e) |
|
|
|
} |
|
|
|
} |
|
|
|