Search code examples
androiddownloadanchortrust

Android DownloadManager Trust anchor for certification path not found


I have searched through many posts but no where I could find any solution or the answer to my question. How can I download files from my site where is intermediate cert installed? While using DownloadManager, I'm getting error " java.security.cert.CertPathValidatorException: Trust anchor for certification path not found." when trying to download a file. I have seen posts that I should use something like in this post https://developer.android.com/training/articles/security-ssl#java But I do not really know how should I set SslSocketFactory for the downloadmanager so he could use it to download files.


Solution

  • Ok, I have found solution. Just add to your manifest

    and to res -> xml -> new file network_security_config with following lines of code

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <domain-config>
            <domain includeSubdomains="true">example.pl</domain>
        <trust-anchors>
            <certificates src="@raw/path_to_cert"/>
        </trust-anchors>
    </domain-config>
    </network-security-config>