diff --git a/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt b/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt index 625ca4fd..70b9a494 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/network/Requests.kt @@ -1,13 +1,11 @@ package com.lagradost.cloudstream3.network +import android.annotation.SuppressLint import android.content.Context import android.util.Log import androidx.preference.PreferenceManager import com.fasterxml.jackson.module.kotlin.readValue -import com.lagradost.cloudstream3.R -import com.lagradost.cloudstream3.USER_AGENT -import com.lagradost.cloudstream3.app -import com.lagradost.cloudstream3.mapper +import com.lagradost.cloudstream3.* import kotlinx.coroutines.CancellableContinuation import kotlinx.coroutines.CompletionHandler import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -19,7 +17,12 @@ import org.jsoup.nodes.Document import java.io.File import java.io.IOException import java.net.URI +import java.security.SecureRandom +import java.security.cert.X509Certificate import java.util.concurrent.TimeUnit +import javax.net.ssl.SSLContext +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager import kotlin.coroutines.resumeWithException @@ -212,6 +215,27 @@ fun putRequestCreator( .build() } +// https://stackoverflow.com/a/59322754 +// Issues with Akwam otherwise +fun OkHttpClient.Builder.ignoreAllSSLErrors(): OkHttpClient.Builder { + val naiveTrustManager = @SuppressLint("CustomX509TrustManager") + object : X509TrustManager { + override fun getAcceptedIssuers(): Array = arrayOf() + override fun checkClientTrusted(certs: Array, authType: String) = Unit + override fun checkServerTrusted(certs: Array, authType: String) = Unit + } + + val insecureSocketFactory = SSLContext.getInstance("TLSv1.2").apply { + val trustAllCerts = arrayOf(naiveTrustManager) + init(null, trustAllCerts, SecureRandom()) + }.socketFactory + + sslSocketFactory(insecureSocketFactory, naiveTrustManager) + hostnameVerifier { _, _ -> true } + return this +} + + open class Requests { var baseClient = OkHttpClient() @@ -221,6 +245,7 @@ open class Requests { baseClient = OkHttpClient.Builder() .followRedirects(true) .followSslRedirects(true) + .ignoreAllSSLErrors() .cache( // Note that you need to add a ResponseInterceptor to make this 100% active. // The server response dictates if and when stuff should be cached.