# HTTPS 请求/响应中的 SSL 错误

> 修复 Proxyman 中的 “SSL Handshake Failed” 等 SSL 错误。检查 Proxyman 证书是否已安装并受信任，并排除 SSL Pinning 的干扰。

## 1. 问题 {#1-problems}

* 在 Proxyman 应用中看不到任何 HTTPS 流量。
* HTTPS 请求和响应出现 SSL 错误。
* 在 Response 面板中看到 **SSL Handshake Failed** 或 **Possible Certificate Pinning**。

![Proxyman 的 Response 面板显示 Client SSL Handshake Failed，错误代码为 -9806](https://proxyman.com/docs/assets/Screen%20Shot%202020-04-25%20at%2019.52.38.png)

## 2. 解决方案 {#2-solution}

SSL 握手失败的原因有很多。请按照以下步骤逐一排查。

## 2.1 移动设备 {#21-mobile-devices}

### iOS 设备 {#ios-device}

* 请按照 [iOS 设置指南](https://proxyman.com/docs/zh-cn/debug-devices/ios-device) 操作 -> 确保已安装并信任 Proxyman CA 证书。
* 如果你要抓取热门应用（例如 Facebook、Instagram、Apple、WhatsApp 等）的流量：这些应用受 SSL Pinning 保护，无法被抓取。
* 确认你的 iOS 应用没有使用 SSL Pinning。如果使用了，请将其关闭。

### iOS 模拟器 {#ios-simulator}

请按照 [iOS 模拟器设置指南](https://proxyman.com/docs/zh-cn/debug-devices/ios-simulator) 操作 -> 确保已在模拟器上安装并信任 Proxyman CA 证书。

### Android 设备 {#android-device}

* 请按照 [Android 设备设置指南](https://proxyman.com/docs/zh-cn/debug-devices/android-device) 操作 -> 确保已在设备上安装并信任 Proxyman CA 证书。
* 确认第 5 步已完成（将你的域名添加到两个文件中：**res/xml/network\_security\_config.xml** 和 **AndroidManifest.xml**）。
* 如果要抓取的不是你自己开发的 Android 应用 -> 无法抓取 -> ❌

### Android 模拟器 {#android-emulator}

* 请按照 [Android 模拟器设置指南](https://proxyman.com/docs/zh-cn/debug-devices/android-device/automatic-script-for-android-emulator) 操作 -> 确保已在模拟器上安装并信任 Proxyman CA 证书。
* 确认第 5 步已完成（将你的域名添加到两个文件中：**res/xml/network\_security\_config.xml** 和 **AndroidManifest.xml**）。
* 如果要抓取的不是你自己开发的 Android 应用 -> 无法抓取 -> ❌

### React Native 应用 {#react-native-app}

* 如果你的应用是 React Native 应用，请按照 [React Native 指南](https://proxyman.com/docs/zh-cn/debug-devices/react-native) 操作。

### Flutter {#flutter}

* 请按照 [Flutter 设置指南](https://proxyman.com/docs/zh-cn/debug-devices/flutter) 操作。

以上步骤都已尝试并确认无误，但仍然出现 SSL 错误？

### 验证能否在没有任何错误的情况下查看来自 https://google.com 的 HTTPS 请求/响应 {#verify-that-youre-able-to-see-https-requestresponse-from-httpsgooglecom-without-any-errors}

1. 准备好你的设备。
2. 打开网页浏览器（iOS 上为 Safari，Android 上为 Google Chrome）。
3. 访问 **https://google.com**
4. 在 Proxyman for macOS 中右键点击该请求，然后选择 **Enable SSL Proxying** 以对该域名生效。随后刷新页面。
5. 检查能否看到 HTTPS 响应。

#### ✅ 成功 {#-success}

1. 你可以看到来自 https://google.com 的 HTTPS 响应，说明证书已正确设置 ✅
2. 问题可能出在你的应用上。请使用你的域名或应用再试一次 -> 如果仍然出现 SSL 错误，该应用很可能受 SSL Pinning 保护。
3. 如果你认为这不是 SSL Pinning 的问题，请在 [GitHub](https://github.com/ProxymanApp/Proxyman/issues) 上提交 Issue（请注明你的设备、系统版本、应用名称等信息）。

#### ❌ 失败 {#-failed}

* Proxyman 证书很可能没有在你的设备上正确安装或受信任。请返回 [2.1 移动设备](https://proxyman.com/docs/zh-cn/troubleshooting/get-ssl-error-from-https-request-and-response#21-mobile-devices) 部分并按照步骤操作。
* 如果所有步骤都已完成但仍然出现 SSL 错误，请在 [GitHub](https://github.com/ProxymanApp/Proxyman/issues) 上提交 Issue（请注明你的设备、系统版本、应用名称等信息）。

## 2.2 MacBook 或 Windows PC {#22-macbook-or-windows-pc}

如果你在以下环境中遇到 SSL 错误：

* **Mac（MacBook、Mac mini、Mac Studio）** -> 在 Mac 上安装并信任证书 -> 请按照 [macOS 指南](https://proxyman.com/docs/zh-cn/debug-devices/macos) 操作
* **Windows** -> 在 Windows 设备上安装并信任证书 -> 请按照 [Windows 指南](https://proxyman.com/docs/zh-cn/proxyman-windows/install-certificate) 操作
* Java -> 请按照 [Java VM 指南](https://proxyman.com/docs/zh-cn/debug-devices/java) 操作
* Firefox -> 请按照 [Firefox 指南](https://proxyman.com/docs/zh-cn/debug-devices/firefox) 操作
* Python -> 请按照 [Python 指南](https://proxyman.com/docs/zh-cn/debug-devices/python) 操作
* Ruby -> 请按照 [Ruby 指南](https://proxyman.com/docs/zh-cn/debug-devices/ruby) 操作

> **注意:** 一些网络库（Ruby、NodeJS、Python、Golang）默认不信任自签名证书，你需要让该库显式信任此证书。
>
> \=> 解决方法：使用 [Automatic Setup](https://proxyman.com/docs/zh-cn/automatic-setup/automatic-setup)，打开 **Setup** -> **Automatic Setup…** -> **Open New Terminal…**，然后在该终端中运行你的脚本。它会为受支持的 NodeJS、Python、Ruby 和 Golang 库设置证书信任。对于其他库，请搜索 **"\<Your framework/library> self-signed certificate"**（将 Your framework/library 替换为你使用的框架或库名称）。

## 2.3 是否是 SSL Pinning 导致的？ {#23-ssl-pinning}

* 如果你仍然无法在应用中看到 HTTPS 响应，那么该应用很可能受 [SSL Pinning](https://en.wikipedia.org/wiki/HTTP_Public_Key_Pinning) 保护，这会阻止 MitM 应用读取内容。大多数热门应用（Facebook、Apple、Instagram、Messenger 等）都会使用它。
* 临时**关闭应用中的 SSL Pinning**，然后再试一次。

延伸阅读：[在 iOS 中使用 SSL Pinning 防范中间人攻击](https://www.kodeco.com/1484288-preventing-man-in-the-middle-attacks-in-ios-with-ssl-pinning)

> **备注:** 尝试了所有方法但仍不确定问题出在哪里？请提交 [GitHub Issue](https://github.com/ProxymanApp/Proxyman/issues)。
>
> 也请注明：Proxyman macOS/Windows 版本、你的 Proxyman 版本、你的 iOS/Android 设备等信息。

## 视频 {#video}

[Video: 使用 Proxyman 抓取 HTTP 和 HTTPS 流量](https://proxyman.com/videos/capture-http-https-traffic) (25 seconds)

## 了解更多 {#learn-more}

* [能否绕过 SSL Pinning？](https://proxyman.com/posts/2019-11-15-Can-we-bypass-ssl-pinning)
