2016-07-27 105 views
1

在我的應用程序中,我使用自簽名證書通過https進行連接。該應用程序的工作時compilesdk設置爲< 24完全正常,但是當compilesdk爲24我的應用程序無法通過https連接到服務器,並拋出以下異常:Android N java.security.cert.CertPathValidatorException:未找到證書路徑的信任錨

07-27 14:35:52.927 11424-11956/com.test.Push W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:361) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:112) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call.getResponse(Call.java:286) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.worklight.wlclient.CertificatePinningInterceptor.intercept(CertificatePinningInterceptor.java:20) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:232) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.worklight.wlclient.OkHttpInterceptor.intercept(OkHttpInterceptor.java:145) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:232) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.squareup.okhttp.Call.execute(Call.java:80) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at com.worklight.wlclient.WLRequestSender.run(WLRequestSender.java:49) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
07-27 14:35:52.927 11424-11956/com.test.Push W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at java.lang.Thread.run(Thread.java:761) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:549) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:401) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:375) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:304) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:178) 
07-27 14:35:52.928 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:596) 
07-27 14:35:52.929 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) 
07-27 14:35:52.929 11424-11956/com.test.Push W/System.err:  at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357) 
07-27 14:35:52.929 11424-11956/com.test.Push W/System.err: ... 20 more 
07-27 14:35:52.929 11424-11956/com.test.Push W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 
07-27 14:35:52.929 11424-11956/com.test.Push W/System.err: ... 30 more 

我也跟着提到的步驟這裏https://developer.android.com/preview/features/security-config.html,但是我的應用仍然無法通過https連接到服務器。我network_security_config.xml是如下:

<?xml version="1.0" encoding="utf-8"?> 
<network-security-config> 
    <domain-config> 
     <domain includeSubdomains="true">test.abc.com</domain> 
     <trust-anchors> 
      <certificates src="@raw/ca_norton"/> 
     </trust-anchors> 
    </domain-config> 
</network-security-config> 

在我AndroidManifest.xml中包含的應用程序標記

<meta-data android:name="android.security.net.config" 
      android:resource="@xml/network_security_config" /> 

ca_norton.crt也被複制到原始文件夾下的下面。我在這裏錯過了什麼嗎?提前致謝。

回答

3

在您的清單指定網絡安全配置正確的方法是:

<?xml version="1.0" encoding="utf-8"?> 
<manifest ... > 
    <application android:networkSecurityConfig="@xml/network_security_config" 
      ... > 
    ... 
    </application> 
</manifest> 

https://developer.android.com/preview/features/security-config.html#manifest。元數據方法僅出現在N早期預覽中,不再支持。

+0

是的,在清單中指定android:networkSecurityConfig =「@ xml/network_security_config」運行良好。謝謝。 –

相關問題