Charles Android 抓包失敗SSLHandshake: Received fatal alert: certificate_unknown

來源:互聯網
上載者:User

標籤: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認證:

  1. 在你的AndroidManifest.xml檔案中添加如下配置:

    <?xml version="1.0" encoding="utf-8"?><manifest ... >    <application android:networkSecurityConfig="@xml/network_security_config"                ... >...</application></manifest>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  2. 在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>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
解決辦法 二:

手機上是否有裝認證都可以使用下面的方法:

  1. 在你的AndroidManifest.xml檔案中添加如下配置:

    <?xml version="1.0" encoding="utf-8"?><manifest ... >    <application android:networkSecurityConfig="@xml/network_security_config"                ... >...</application></manifest>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  2. 在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>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  3. 在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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.