Has Android changed SSL configuration in API 24?

前端 未结 1 466
清酒与你
清酒与你 2020-12-30 17:09

When my Android 23 project attempts to connect to my server via HTTPS, all is fine.

If I switch the target SDK to 24, I get the following error:

 jav         


        
相关标签:
1条回答
  • 2020-12-30 18:01

    User-installed certificates, via the Settings app, are not incorporated by default on Android 7.0 if your targetSdkVersion is 24+:

    By default secure (e.g. TLS, HTTPS) connections from all apps trust the pre-installed system CAs, and apps targeting API level 23 (Android M) and below also trust the user-added CA store by default.

    (from the network security configuration docs)

    To work around that, you will need to define a network security configuration XML resource:

    <?xml version="1.0" encoding="utf-8"?>
    
    <network-security-config>
        <base-config>
            <trust-anchors>
                <certificates src="system"/>
                <certificates src="user"/>
            </trust-anchors>
        </base-config>
    </network-security-config>
    

    Then, point to that XML resource from your android:networkSecurityConfig attribute in your <application> element in your manifest.


    In general, Android 7.0 routes HTTPS through the network security configuration subsystem (android.security.net.config.RootTrustManager and kin from your stack trace). It's possible that there are other compatibility issues introduced here that are tied to targetSdkVersion. So, if the lack of user certificates is not your issue, and you can create a sample project that reproduces the problem, file an issue. Since I maintain a backport of that stuff, I would be interested in knowing about any bugs. :-)

    0 讨论(0)
提交回复
热议问题