ssl - 如何使用 openssl 验证证书链

标签 ssl openssl

我正在尝试使用 OpenSSL 验证证书文件。您能解释一下为什么 s_client 连接成功,但是具有相同证书链的 verify 文件失败了吗?如何验证文件?

注意我自己编译了 OpenSSL 1.0.1k,它不应该使用任何特定于发行版的配置。我为这两个命令提供了相同的 CAfile

$ openssl s_client -CAfile /etc/pki/tls/certs/ca-bundle.crt -connect www.google.com:443
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
CONNECTED(00000003)
depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authority
verify return:1
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = www.google.com
verify return:1
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
    ...
    Verify return code: 0 (ok)
---

如果我使用 -showcerts 参数运行它,它会输出从服务器发送的所有三个证书。我将它们连接到文件 google.pem 中。但链条无法验证。见:

$ openssl verify -CAfile /etc/pki/tls/certs/ca-bundle.crt google.pem
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
google.pem: C = US, ST = California, L = Mountain View, O = Google Inc, CN = www.google.com
error 20 at 0 depth lookup:unable to get local issuer certificate

应用 https://stackoverflow.com/a/27606964/1823988 上建议的补丁没有帮助。

最佳答案

我找到了。 openssl verify 不希望证书文件包含其链。 Chain 需要通过 -untrusted 参数传递。它使用相同的文件,信任仍然是通过在 -CAfile 中找到受信任的根来确定的。

openssl verify -CAfile /etc/pki/tls/certs/ca-bundle.crt -untrusted google.pem google.pem

关于ssl - 如何使用 openssl 验证证书链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28080408/

相关文章:

visual-studio-2015 - 使用openssl时如何检测内存泄漏

openssl - 创建证书并将其替换到分类帐中后无法理解发生了什么问题

ssl - 使用 Rapidssl heroku DNSimple rails app 添加 SSl

java - 如何创建包含客户端证书链的 BKS (BouncyCaSTLe) 格式的 Java keystore

php - 尝试在 PHP 中使用 shell_exec 通过 openssl 创建证书

ios - 计算循环中的 BIGNUM 奇怪行为

ssl - 如何在 Heroku 上部署安全的 (HTTPS) Meteor 应用程序?

java - 如何在Spring Boot Rest模板中使用.pfx证书和密码调用安全的rest api?

ssl - 尝试反序列化 SAML token 时,我可以从文件而不是证书存储中读取 SSL 证书吗

ssl - MacOS Mojave 更新 SSL/TLS 后无法从 'https ://rubygems.org/' 安装 gems(?)