Documentation for making realtime app using django as backend and react native as frontend
Follow the step from https://github.com/mitchtabian/HOWTO-django-channels-daphne
Thank you to mitchtabian !!!!
To resolve the "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found" error, you need to obtain a valid SSL/TLS certificate from a trusted Certificate Authority (CA) like Let's Encrypt or a commercial CA. Make sure the certificate is properly configured on your WebSocket server.
openssl s_client -showcerts -connect your.domain.com:443 < /dev/null
Copy the certificate starting from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----, and save it as server.crt.
1 s:C = US, O = Let's Encrypt, CN = R3
i:C = US, O = Internet Security Research Group, CN = ISRG Root X1
a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA256
v:NotBefore: Sep 4 00:00:00 2020 GMT; NotAfter: Sep 15 16:00:00 2025 GMT
- Place the
server.crt
certificate file in theandroid/app/src/main/res/raw/
directory of your Android project.
- Create a file named
network_security_config.xml
in theandroid/app/src/main/res/xml/
directory.
Inside network_security_config.xml
, add the following lines to include the server.crt
certificate:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain><!-- debugger -->
<domain includeSubdomains="false">localhost</domain><!-- Debug port without local server -->
<domain includeSubdomains="true">YOUR_IP_ADDRESS</domain><!-- Debug port -->
<domain includeSubdomains="true">your_website.com</domain>
<trust-anchors>
<certificates src="@raw/server" />
</trust-anchors>
</domain-config>
</network-security-config>
In the android/app/src/main/AndroidManifest.xml file, add the following line to reference the network security configuration:
<application
...
android:networkSecurityConfig="@xml/network_security_config"
...>
cd android
./gradlew clean
After cleaning, run npx react-native run-android
again to rebuild the project with the network security configuration.
By following these steps, the error should be resolved, and your React Native app should be able to connect to the WebSocket server with the trusted SSL/TLS certificate.