Closed afioletov closed 4 years ago
Certificates for your application needs to be configured using the network config file, documentation is at https://developer.android.com/training/articles/security-config
For your use case, you want to add a network_security_config.xml file to res/xml folder:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<!-- Trust preinstalled CAs -->
<certificates src="system" />
<!-- Additionally trust user added CAs -->
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
By default, apps trust only preinstalled CA's exclusively.
The change was introduced in API 24: https://android-developers.googleblog.com/2016/07/changes-to-trusted-certificate.html
Apps that target API Level 24 and above no longer trust user or admin-added CAs for secure connections, by default.
So it's Android thing, good to know.
Thank you, @faugusztin!
Is there anything similar in the latest iOS version?
You can trust custom certs on iOS, too, even root CA's and AFAIK it's "available/trusted" in every app (unless they do stuff like certificate pinning)
It worked. Thank you!
iOS does not like a SSL certificates with long validity period anymore.
Certificates for your application needs to be configured using the network config file, documentation is at https://developer.android.com/training/articles/security-config
For your use case, you want to add a network_security_config.xml file to res/xml folder:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config> <trust-anchors> <!-- Trust preinstalled CAs --> <certificates src="system" /> <!-- Additionally trust user added CAs --> <certificates src="user" /> </trust-anchors> </base-config> </network-security-config>
By default, apps trust only preinstalled CA's exclusively.
The change was introduced in API 24: https://android-developers.googleblog.com/2016/07/changes-to-trusted-certificate.html
Apps that target API Level 24 and above no longer trust user or admin-added CAs for secure connections, by default.
That looks like what I want to do. Can I get the Cordova build to do this for me?
That looks like what I want to do. Can I get the Cordova build to do this for me?
Yes. Create a network_security_config.xml file somewhere, and add it to your config.xml as a resource-file to be copied into the Android platform, and then use edit-config to point the AndroidManifest to it:
<!-- in your config.xml file -->
<platform name="android">
<resource-file src="path/to/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:networkSecurityConfig="@xml/network_security_config" />
</edit-config>
</platform>
That looks like what I want to do. Can I get the Cordova build to do this for me?
Yes. Create a network_security_config.xml file somewhere, and add it to your config.xml as a resource-file to be copied into the Android platform, and then use edit-config to point the AndroidManifest to it:
<!-- in your config.xml file --> <platform name="android"> <resource-file src="path/to/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" /> <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application"> <application android:networkSecurityConfig="@xml/network_security_config" /> </edit-config> </platform>
Perfect exactly what I was after. Thankyou!
Issue Type
Description
I manually installed CA certificate on device and browser works as expected with no warning about SSL certificate. But it does not happen in my Cordova app. I got exception about failed certificate validation when ajax request is executed.
Should app work with manually installed roots?
Information
Command or Code
Environment, Platform, Device
All Android devices. We tried Android 7 and 9.
It worked on iOS with manually installed profiles, but starting with 13.4 (or previous), but it stopped working too with new iOS updates.
Version information
Checklist