Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import my selfsigned CA, it seems to not recognize the raw directory

I'm trying to import my selfsigned CA in android so I can make HTTPS POST to a web server I selfsigned. Following Google Doc(https://developer.android.com/training/articles/security-config.html#ConfigCustom) I created directory res/raw/mycertificate and added my certificate in it. Created /res/xml directory and added the xml file network_security_config.xml to the manifest. It's in the network_security_config.xml file that I'm having some trouble, because when I create the tag Android Studio get me an error on src telling me "Missing src resource" but I placed the certificate.pem in the directory /res/raw/mycertificate, and the folders raw and mycertificate does exists. How can I make Android Studio take correctly that path folder?

<network-security-config>
<domain-config>
    <domain includeSubdomains="true">192.168.1.200</domain>
    <trust-anchors>
          <certificates src="@raw/my_ca" />
    </trust-anchors>
</domain-config>

like image 865
Benjamin_B Avatar asked Feb 10 '18 17:02

Benjamin_B


1 Answers

Omit the file extension for your certificate file in the network config XML file. If your cert is at res/raw/my_cert.pem, use this XML code:

<network-security-config>
<domain-config>
    <domain includeSubdomains="true">192.168.1.200</domain>
    <trust-anchors>
          <certificates src="@raw/my_cert" />
    </trust-anchors>
</domain-config>
like image 77
Jack M Avatar answered Sep 17 '22 17:09

Jack M