zoukankan      html  css  js  c++  java
  • Charles Android 抓包失败SSLHandshake: Received fatal alert: certificate_unknown

    前提:

    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

    转载:https://blog.csdn.net/mrxiagc/article/details/75329629

  • 相关阅读:
    关于c语言的一个小bug(c专家编程)
    A10 平板开发一硬件平台搭建
    A10 平板开发二搭建Android开发环境
    hdu
    如何选择发现自己是否适合科研?
    屌丝程序员与房子
    一步一步学数据结构之n--n(Prim算法)
    pat 1049 Counting Ones
    add-strings
    这篇讲PHP的讲的有些道理 & mb_substr & 中文处理
  • 原文地址:https://www.cnblogs.com/c-x-a/p/9070052.html
Copyright © 2011-2022 走看看