Skip to content

Instantly share code, notes, and snippets.

@Turnsole
Created June 22, 2020 18:17
Show Gist options
  • Save Turnsole/bb103ec8b60291c77072e14daeefa54a to your computer and use it in GitHub Desktop.
Save Turnsole/bb103ec8b60291c77072e14daeefa54a to your computer and use it in GitHub Desktop.
Modify Android app to allow user-signed SSL certificates (such as Charles Proxy)
#!/bin/bash
# To use Charles Proxy with SSL:
# (1) On the device, open a browser and visit https://chls.pro/ssl to download a security certificate
# (2) Open the certificate, and when it installs select "VPN and apps"
# (3) Open up wifi settings, under "Advanced" set the proxy address to your laptop's IP address, port 8888
# (4) Run this script from the app module before building the app so that it will allow proxying with a user-installed certificate (such as you installed in step (2))
#
# Don't forget to revert these changes when you're done if you don't mean to commit them.
mkdir -p src/main/res/xml/
cat > src/main/res/xml/network_security_config.xml <<EOF
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
EOF
sed -i "" "/<application/ a\\
android:networkSecurityConfig='@xml/network_security_config'
" src/main/AndroidManifest.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment