pull/32/head
kunfei 5 years ago
parent 170007e893
commit 6b6beac16b
  1. 4
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  2. 12
      app/src/main/java/io/legado/app/help/http/SSLHelper.kt
  3. 3
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt

@ -41,6 +41,7 @@ object HttpHelper {
.connectTimeout(15, TimeUnit.SECONDS) .connectTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS) .writeTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS)
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager)
.retryOnConnectionFailure(true) .retryOnConnectionFailure(true)
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier) .hostnameVerifier(SSLHelper.unsafeHostnameVerifier)
.connectionSpecs(specs) .connectionSpecs(specs)
@ -49,9 +50,6 @@ object HttpHelper {
.protocols(listOf(Protocol.HTTP_1_1)) .protocols(listOf(Protocol.HTTP_1_1))
.addInterceptor(getHeaderInterceptor()) .addInterceptor(getHeaderInterceptor())
SSLHelper.getSslSocketFactory()?.let {
builder.sslSocketFactory(it.sSLSocketFactory, it.trustManager)
}
return builder.build() return builder.build()
} }

@ -5,6 +5,7 @@ import java.io.InputStream
import java.security.KeyManagementException import java.security.KeyManagementException
import java.security.KeyStore import java.security.KeyStore
import java.security.NoSuchAlgorithmException import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.security.cert.CertificateException import java.security.cert.CertificateException
import java.security.cert.CertificateFactory import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate 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 的主机名和服务器的标识主机名不匹配 * 此类是用于主机名验证的基接口 在握手期间如果 URL 的主机名和服务器的标识主机名不匹配
* 则验证机制可以回调此接口的实现程序来确定是否应该允许此连接策略可以是基于证书的或依赖于其他验证方案 * 则验证机制可以回调此接口的实现程序来确定是否应该允许此连接策略可以是基于证书的或依赖于其他验证方案

@ -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.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.htmlFormat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import retrofit2.Response import retrofit2.Response
@ -83,7 +84,7 @@ object BookContent {
analyzeRule.getStringList(contentRule.nextContentUrl ?: "", true)?.let { analyzeRule.getStringList(contentRule.nextContentUrl ?: "", true)?.let {
nextUrlList.addAll(it) nextUrlList.addAll(it)
} }
val content = analyzeRule.getString(contentRule.content ?: "") ?: "" val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: ""
return ContentData(content, nextUrlList) return ContentData(content, nextUrlList)
} }
} }
Loading…
Cancel
Save