Skip to content

Commit

Permalink
fix(Override certificate pinning): Always overwrite with a generic ne…
Browse files Browse the repository at this point in the history
…twork security configuration

Previously some conditional checks prevented to patch YouTube for example. The current configuration should work globally for all apps.
  • Loading branch information
oSumAtrIX committed Feb 28, 2024
1 parent 020c642 commit 2a842a1
Showing 1 changed file with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.all.misc.debugging.EnableAndroidDebuggingPatch
import app.revanced.util.Utils.trimIndentMultiline
import org.w3c.dom.Element
import java.io.File

Expand Down Expand Up @@ -32,10 +33,8 @@ object OverrideCertificatePinningPatch : ResourcePatch() {

// In case the file does not exist create the "network_security_config.xml" file.
File(resXmlDirectory, "network_security_config.xml").apply {
if (!exists()) {
createNewFile()
writeText(
"""
writeText(
"""
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
Expand All @@ -55,21 +54,8 @@ object OverrideCertificatePinningPatch : ResourcePatch() {
</trust-anchors>
</debug-overrides>
</network-security-config>
""",
)
} else {
// If the file already exists.
readText().let { text ->
if (!text.contains("<certificates src=\"user\" />")) {
writeText(
text.replace(
"<trust-anchors>",
"<trust-anchors>\n<certificates src=\"user\" overridePins=\"true\" />\n<certificates src=\"system\" />",
),
)
}
}
}
""".trimIndentMultiline(),
)
}
}
}

0 comments on commit 2a842a1

Please sign in to comment.