標籤:tail title name received har hal des fat app
前提:
Android使用Charles抓取Https請求的報文時,Android和Charles都正確安裝了認證之後出現抓包失敗,報錯SSLHandshake: Received fatal alert: certificate_unknown,如所示:
原因:
安卓7之後調整了安全性原則會導致部分手機抓包失敗,請參考此連結:https://android-developers.googleblog.com/2016/07/changes-to-trusted-certificate.html
文中提到預設情況下,針對API Level 24及更高版本的應用程式不再信任使用者或管理員添加的CA用於安全連線。意思就是就算你在手機上安裝了受信任的認證也是沒卵用的。
解決辦法 一:
前提你的手機上已經正確安裝了Charles認證:
在你的AndroidManifest.xml檔案中添加如下配置:
<?xml version="1.0" encoding="utf-8"?><manifest ... > <application android:networkSecurityConfig="@xml/network_security_config" ... >...</application></manifest>
在res目錄下建立一個xml檔案夾,之後在res/xml/路徑下建立檔案network_security_config.xml
res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config> <domain includeSubdomains="true">你要抓取的網域名稱</domain> <trust-anchors> <certificates src="user"/>//信任使用者自己安裝的認證 </trust-anchors> </domain-config></network-security-config>
解決辦法 二:
手機上是否有裝認證都可以使用下面的方法:
在你的AndroidManifest.xml檔案中添加如下配置:
<?xml version="1.0" encoding="utf-8"?><manifest ... > <application android:networkSecurityConfig="@xml/network_security_config" ... >...</application></manifest>
在res目錄下建立一個xml檔案夾,之後在res/xml/路徑下建立檔案network_security_config.xml
res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config> <domain includeSubdomains="true">你要抓取的網域名稱</domain> <trust-anchors> <certificates src="@raw/認證檔案名稱"/> </trust-anchors> </domain-config></network-security-config>
在res目錄下建立一個raw檔案夾,將手機上安裝的認證檔案放入res/raw/目錄下,認證格式:pem,ca等(chales的話就是將你在手機瀏覽器開啟http://charlesproxy.com/getssl下載的認證放入即可),步驟2中的認證檔案名稱,就是你放入res/raw/目錄下檔案的名字
配置完重新運行項目,就可以看到報文了!
更多配置方法請參考Google-Android
轉載:75329629
Charles Android 抓包失敗SSLHandshake: Received fatal alert: certificate_unknown