diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 81602c87e..342d0a1e3 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -41,6 +41,7 @@ object HttpHelper { .connectTimeout(15, TimeUnit.SECONDS) .writeTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS) + .sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager) .retryOnConnectionFailure(true) .hostnameVerifier(SSLHelper.unsafeHostnameVerifier) .connectionSpecs(specs) @@ -49,9 +50,6 @@ object HttpHelper { .protocols(listOf(Protocol.HTTP_1_1)) .addInterceptor(getHeaderInterceptor()) - SSLHelper.getSslSocketFactory()?.let { - builder.sslSocketFactory(it.sSLSocketFactory, it.trustManager) - } return builder.build() } 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 c78fbdcd5..8fc40d27c 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 @@ -5,6 +5,7 @@ import java.io.InputStream import java.security.KeyManagementException import java.security.KeyStore import java.security.NoSuchAlgorithmException +import java.security.SecureRandom import java.security.cert.CertificateException import java.security.cert.CertificateFactory import java.security.cert.X509Certificate @@ -33,6 +34,17 @@ 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) + } + } + /** * 此类是用于主机名验证的基接口。 在握手期间,如果 URL 的主机名和服务器的标识主机名不匹配, * 则验证机制可以回调此接口的实现程序来确定是否应该允许此连接。策略可以是基于证书的或依赖于其他验证方案。 diff --git a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt index 9d41cb4aa..a85ccb28c 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt @@ -8,6 +8,7 @@ import io.legado.app.data.entities.rule.ContentRule import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.htmlFormat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.withContext import retrofit2.Response @@ -83,7 +84,7 @@ object BookContent { analyzeRule.getStringList(contentRule.nextContentUrl ?: "", true)?.let { nextUrlList.addAll(it) } - val content = analyzeRule.getString(contentRule.content ?: "") ?: "" + val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" return ContentData(content, nextUrlList) } } \ No newline at end of file