Windows 上安装 devsidecar 后,使用 WSL ubuntu ssl 报错

文章目录

  • [1. 问题原因](#1. 问题原因)
  • [2. 解决方案](#2. 解决方案)
    • [方法 1:禁用 SSL 验证(不推荐,仅临时测试)](#方法 1:禁用 SSL 验证(不推荐,仅临时测试))
    • [方法 2:将 Windows 证书同步到 WSL](#方法 2:将 Windows 证书同步到 WSL)
    • [方法 3:手动配置环境变量](#方法 3:手动配置环境变量)
    • [方法 4:完全绕过代理(推荐终极方案)](#方法 4:完全绕过代理(推荐终极方案))
  • 预防措施
  • 总结

在 Windows 上使用 DevSidecar(开发者边车工具)后,WSL Ubuntu 中遇到 SSL 证书错误(如 SSL certificate problem: unable to get local issuer certificate),通常是因为代理工具修改了系统证书,但 WSL 未正确同步这些更改。以下是解决方案:

1. 问题原因

DevSidecar 或类似代理工具会安装自签名根证书到 Windows 的证书存储(如 Charles Proxy 或 Fiddler 的证书)。

WSL Ubuntu 默认使用自己的证书存储(/etc/ssl/certs),无法自动识别 Windows 中添加的证书,导致 SSL 验证失败。

2. 解决方案

方法 1:禁用 SSL 验证(不推荐,仅临时测试)

在命令中临时跳过 SSL 验证(如 curl、git、pip):

bash 复制代码
# 对于 curl
curl -k https://example.com

# 对于 git
git config --global http.sslVerify false

# 对于 pip
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package_name

⚠️ 这会降低安全性,仅用于临时测试。

方法 2:将 Windows 证书同步到 WSL

  1. 导出 DevSidecar 的根证书:

    • 在 Windows 中打开 certmgr.msc,找到 DevSidecar 的根证书(通常位于 受信任的根证书颁发机构)。

    • 右键导出为 .pem 或 .crt 格式(如 devsidecar.crt)。

  2. 将证书复制到 WSL:

bash 复制代码
# 从 Windows 复制到 WSL(假设证书在 C:\)
cp /mnt/c/devsidecar.crt /usr/local/share/ca-certificates/
  1. 更新 WSL 的证书存储:
bash 复制代码
sudo update-ca-certificates
  • 输出应显示 1 added, 0 removed。
  1. 验证证书是否生效:
bash 复制代码
curl https://example.com  # 应不再报 SSL 错误

方法 3:手动配置环境变量

如果代理工具提供了 CA 证书,可显式指定证书路径:

bash 复制代码
# 对于 curl
curl --cacert /path/to/devsidecar.crt https://example.com

# 对于 git
git config --global http.sslCAInfo /path/to/devsidecar.crt

# 对于 pip
pip install --cert /path/to/devsidecar.crt package_name

方法 4:完全绕过代理(推荐终极方案)

如果不需要在 WSL 中使用代理,直接关闭 DevSidecar 并清除代理设置:

  1. 重置 WSL 的代理配置:
bash 复制代码
unset http_proxy https_proxy all_proxy
  1. 检查 Git 代理:
bash 复制代码
git config --global --unset http.proxy
git config --global --unset https.proxy
  1. 常见错误及修复
  • 错误 1:curl: (60) SSL certificate problem: unable to get local issuer certificate

    修复:执行方法 2 同步证书。

  • 错误 2:pip is configured with locations that require TLS/SSL, but the ssl module in Python is not available

    修复:重新安装 Python 的 SSL 模块:

bash 复制代码
sudo apt-get install libssl-dev
sudo apt-get install python3-pip --reinstall
  • 错误 3:Certificate verification failed: The certificate is NOT trusted
    修复:确保证书路径正确且已更新:
bash 复制代码
sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs

预防措施

  1. 统一代理配置:

    • 在 WSL 中显式设置代理环境变量(与 Windows 代理一致):
    bash 复制代码
    export http_proxy=http://<Windows_IP>:<DevSidecar_PORT>
    export https_proxy=http://<Windows_IP>:<DevSidecar_PORT>

    替换 <Windows_IP> 为 Windows 主机的 IP(如 127.0.0.1),<DevSidecar_PORT> 为 DevSidecar 的端口(默认可能为 15732)。

  2. 使用 WSL 2 的自动 DNS 解析:

    • WSL 2 默认共享 Windows 的网络,但证书仍需手动同步。

总结

  • 优先方案:同步 Windows 证书到 WSL(方法 2)。
  • 临时方案:禁用 SSL 验证(方法 1)。
  • 终极方案:关闭代理并清除配置(方法 4)。

如果问题仍存在,请检查 DevSidecar 的日志或尝试重启 WSL:

bash 复制代码
wsl --shutdown
相关推荐
_oP_i2 小时前
Win11 性能调优实用指南
windows
保持低旋律节奏3 小时前
C++——C++11特性
开发语言·c++·windows
ol木子李lo3 小时前
Visual studio 2022高亮汇编(ASM)语法方法
汇编·ide·windows·visual studio
王柏龙4 小时前
Win11 无法找到本地组策略编辑器的解决方法
windows·策略模式
q***09805 小时前
Windows 11 如何配置node.js
windows·node.js
全息数据5 小时前
WSL2 中将 Ubuntu 20.04 升级到 22.04 的详细步骤
深度学习·ubuntu·wsl2
q***47186 小时前
Windows 上彻底卸载 Node.js
windows·node.js
q***51898 小时前
ubuntu 安装 Redis
linux·redis·ubuntu
稻谷君W10 小时前
Ubuntu 远程访问 Win11 WSL2 并固定访问教程
linux·运维·ubuntu
柳暗花再明11 小时前
Visio 中设置文本框背景透明的方法
人工智能·windows