From 5f8099de05ef4f22e30cffa548e306ec6ff1305b Mon Sep 17 00:00:00 2001 From: Sofie <117321707+Sofie99@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:21:21 +0700 Subject: [PATCH] Mangaforfreecom: trust all certificate (#822) * Mangaforfreecom: trust all certificate * clean * small fix * comply * comply --------- Co-authored-by: ghost --- .../mangaforfreecom/src/Mangaforfreecom.kt | 44 +++++++++++++++++++ .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 multisrc/overrides/madara/mangaforfreecom/src/Mangaforfreecom.kt diff --git a/multisrc/overrides/madara/mangaforfreecom/src/Mangaforfreecom.kt b/multisrc/overrides/madara/mangaforfreecom/src/Mangaforfreecom.kt new file mode 100644 index 000000000..91df4654b --- /dev/null +++ b/multisrc/overrides/madara/mangaforfreecom/src/Mangaforfreecom.kt @@ -0,0 +1,44 @@ +package eu.kanade.tachiyomi.extension.all.mangaforfreecom + +import android.annotation.SuppressLint +import eu.kanade.tachiyomi.multisrc.madara.Madara +import okhttp3.OkHttpClient +import java.security.cert.X509Certificate +import javax.net.ssl.SSLContext +import javax.net.ssl.TrustManager +import javax.net.ssl.X509TrustManager + +class Mangaforfreecom : Madara("Mangaforfree.com", "https://mangaforfree.com", "en") { + override val client = getUnsafeOkHttpClient() + + private fun getUnsafeOkHttpClient(): OkHttpClient { + val trustAllCerts = + arrayOf( + @SuppressLint("CustomX509TrustManager") + object : X509TrustManager { + @SuppressLint("TrustAllX509TrustManager") + override fun checkClientTrusted( + chain: Array?, + authType: String?, + ) { + } + + @SuppressLint("TrustAllX509TrustManager") + override fun checkServerTrusted( + chain: Array?, + authType: String?, + ) { + } + + override fun getAcceptedIssuers() = arrayOf() + }, + ) + + val sslContext = SSLContext.getInstance("SSL") + sslContext.init(null, trustAllCerts, java.security.SecureRandom()) + val sslSocketFactory = sslContext.socketFactory + return super.client.newBuilder() + .sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) + .hostnameVerifier { _, _ -> true }.build() + } +} diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index be390bdbb..98f402450 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -257,7 +257,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("MangaDods", "https://mangadods.com", "en", overrideVersionCode = 3), SingleLang("MangaDol", "https://mangadol.com", "en"), SingleLang("MangaEffect", "https://mangaeffect.com", "en", overrideVersionCode = 1), - SingleLang("Mangaforfree.com", "https://mangaforfree.com", "en", isNsfw = true, className = "Mangaforfreecom"), + SingleLang("Mangaforfree.com", "https://mangaforfree.com", "en", isNsfw = true, className = "Mangaforfreecom", overrideVersionCode = 1), SingleLang("MangaFoxFull", "https://mangafoxfull.com", "en"), SingleLang("MangaFreak.online", "https://mangafreak.online", "en", className = "MangaFreakOnline"), SingleLang("MangaGG", "https://mangagg.com", "en", overrideVersionCode = 2),