Self Signed Certificates demo Android | Cordova

Demo of how to configure custom trust anchors with network security configuration.

Demo includes 3 commits,

  1. Basic cordova project
  2. Add a call to a self signed certificate
  3. Add CA to custom trusted authorities

References

The self signed certificate used is from https://self-signed.badssl.com/

To get the certificate to use in step 3:

> openssl s_client -connect self-signed.badssl.com:443 -showcerts

Documentation of implementation can be found here:

Android - Network security configuration

Implementation

Implementation includes:

  1. Store the certificate in ./android/app/src/main/res/raw/<trusted_cert>

  2. Create an xml file in ./android/app/src/main/res/xml/network_security_config.xml with content:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="@raw/<trusted_cert>" />
        </trust-anchors>
    </base-config>
</network-security-config>
  1. Add network config to AndroidManifest file in root of Android platform
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...
>

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details