You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下OpenSSL无法读取CA证书存储问题求助

让OpenSSL读取Windows证书存储中CA证书链的解决方法

问题场景

我持有叶证书、中间证书和根证书,通过以下命令将三者合并到client.crt:

cat leaf.crt intermediate.crt root.crt > client.crt

执行验证时出现如下情况:

# 直接验证失败
openssl.exe verify client.crt
C = US, ...
error 20 at 0 depth lookup: unable to get local issuer certificate
error client.crt: verification failed

# 指定CA文件后验证成功
openssl.exe verify -CAfile client.crt client.crt
client.crt: OK

# 将根证书和中间证书安装到Windows证书存储
certutil.exe -addstore -f "ROOT" .\root.crt
CertUtil: -addstore command completed successfully.
certutil.exe -addstore -f "CA" .\intermediate.crt
CertUtil: -addstore command completed successfully.

# 再次直接验证仍失败
openssl.exe verify client.crt
C = US, ...
error 20 at 0 depth lookup: unable to get local issuer certificate
error client.crt: verification failed
openssl.exe verify leaf.crt
C = US, ...
error 20 at 0 depth lookup: unable to get local issuer certificate
error leaf.crt: verification failed

核心问题:OpenSSL默认无法读取Windows系统证书存储中的CA证书,即使手动安装了根和中间证书也无效。

解决方法

方法1:验证时手动指定CA证书链文件

这是最直接的方式,即你已经验证有效的方法:

# 使用合并后的证书链作为CA文件验证叶证书
openssl.exe verify -CAfile client.crt leaf.crt
# 或者验证合并后的证书文件
openssl.exe verify -CAfile client.crt client.crt

如果需要频繁使用,可以把CA文件路径写入OpenSSL配置文件,避免每次手动指定。

方法2:使用OpenSSL的CAPI引擎调用Windows证书存储

OpenSSL提供了capi引擎,可以让它直接读取Windows系统的证书存储。执行验证时需要指定该引擎:

# 验证叶证书
openssl.exe verify -engine capi leaf.crt
# 验证合并后的证书文件
openssl.exe verify -engine capi client.crt

注意事项:

  • 确保你的OpenSSL版本编译时包含了capi引擎(大部分Windows版本的OpenSSL都默认支持)。
  • 若使用32位OpenSSL,需对应安装32位证书到Windows的32位证书存储(可通过certutil.exe -store -user ROOT查看当前用户存储,或使用32位证书管理器操作)。
  • 运行OpenSSL的用户需要具备读取证书存储的权限。

方法3:构建OpenSSL默认识别的CA证书池

OpenSSL默认会从指定路径加载CA证书,操作步骤如下:

  1. 通过openssl version -d命令查看OpenSSL默认配置目录。
  2. 找到该目录下的openssl.cnf配置文件,确认dir参数指向的CA证书存放路径。
  3. 将根证书和中间证书复制到该路径,或把证书内容追加到路径下的cacert.pem文件中。
  4. 之后直接执行openssl.exe verify leaf.crt即可完成验证。

内容的提问来源于stack exchange,提问作者Chris

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 16:00:20