【问题标题】:OpenSSL verify fails, can't find root certificateOpenSSL 验证失败,找不到根证书
【发布时间】:2023-03-31 22:24:01
【问题描述】:

重要提示:下面我的问题中验证证书的方法不正确,会导致误报和误报。请参阅我的答案以了解正确的方法。


我正在测试我编写的用于测试环境中所有证书的工具,但我遇到了 OpenSSL 似乎无法识别特定 GoDaddy 根证书的问题。

错误文本:

$ openssl verify -CAfile bundle.txt cert.txt
cert.txt: C = US, ST = Arizona, L = Scottsdale, O = "GoDaddy.com, Inc.", CN = Go Daddy Root Certificate Authority - G2
error 2 at 2 depth lookup:unable to get issuer certificate

但该证书肯定在/etc/pki/tls/certs/ca-bundle.crt 和ca-bundle.trusted.crt 中。我已手动验证 x509v3 扩展中的 Issuer 和 Subject 密钥与受信任捆绑包中的 KeyID D2:C4:B0:D2:91:D4:4C:11:71:B3:61:CB:3D:A1:FE:DD:A8:6A:D4:E3 匹配。

我错过了什么吗?

证书详情:

Certificate:
    Issuer:  C=US, ST=Arizona, L=Scottsdale, O=GoDaddy.com, Inc., OU=http://certs.godaddy.com/repository/, CN=Go Daddy Secure Certificate Authority - G2
    X509v3 Subject Key Identifier:
        28:3C:0E:1A:82:3E:7F:22:A6:DD:22:8C:45:78:BF:F6:40:47:4F:8A
    X509v3 Authority Key Identifier:
        keyid:40:C2:BD:27:8E:CC:34:83:30:A2:33:D7:FB:6C:B3:F0:B4:2C:80:CE

Bundle1:
    Subject: C=US, ST=Arizona, L=Scottsdale, O=GoDaddy.com, Inc., OU=http://certs.godaddy.com/repository/, CN=Go Daddy Secure Certificate Authority - G2
    Issuer:  C=US, ST=Arizona, L=Scottsdale, O=GoDaddy.com, Inc., CN=Go Daddy Root Certificate Authority - G2
    X509v3 Subject Key Identifier:
        40:C2:BD:27:8E:CC:34:83:30:A2:33:D7:FB:6C:B3:F0:B4:2C:80:CE
    X509v3 Authority Key Identifier:
        keyid:3A:9A:85:07:10:67:28:B6:EF:F6:BD:05:41:6E:20:C1:94:DA:0F:DE

Bundle2:
    Subject: C=US, ST=Arizona, L=Scottsdale, O=GoDaddy.com, Inc., CN=Go Daddy Root Certificate Authority - G2
    Issuer:  C=US, O=The Go Daddy Group, Inc., OU=Go Daddy Class 2 Certification Authority
    X509v3 Subject Key Identifier:
        3A:9A:85:07:10:67:28:B6:EF:F6:BD:05:41:6E:20:C1:94:DA:0F:DE
    X509v3 Authority Key Identifier:
        keyid:D2:C4:B0:D2:91:D4:4C:11:71:B3:61:CB:3D:A1:FE:DD:A8:6A:D4:E3

Trusted:
    Subject: C=US, O=The Go Daddy Group, Inc., OU=Go Daddy Class 2 Certification Authority
    X509v3 Subject Key Identifier:
        D2:C4:B0:D2:91:D4:4C:11:71:B3:61:CB:3D:A1:FE:DD:A8:6A:D4:E3
    X509v3 Authority Key Identifier:
        keyid:D2:C4:B0:D2:91:D4:4C:11:71:B3:61:CB:3D:A1:FE:DD:A8:6A:D4:E3
        DirName:/C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
        serial:00

编辑

要添加到正在运行的 WTFery,使用 openssl s_client 打开与相关服务器的连接会显示证书验证正常。

$ openssl s_client -servername www.foo.com -connect www.foo.com:443
Certificate chain
 0 s:/OU=Domain Control Validated/CN=*.foo.com
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
 1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
 2 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
   i:/C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
...yadda yadda yadda...
Verify return code: 0 (ok)

【问题讨论】:

  • @StephaneMartin 我应该注意到我安装了一个 ca-certificates 软件包,它是 Mozilla 受信任的根证书的汇编,并且 other 中的 50 多个证书我的环境要么验证正常,要么存在合法的信任链问题。

标签: ssl openssl x509


【解决方案1】:

openssl verify 标志的命名可能有点违反直觉,我找到的文档都没有解决这个问题。正如 x539 所涉及的那样,我错误地使用了 -CAfile 选项,此外我还缺少指定中间证书的 -untrusted 选项。

我发现大多数证书通过验证的原因是大多数 CA 已经开始在 CA 包中包含根证书,-CAfile 选项本质上定义了应该构成链的受信任部分的内容, 包括根证书。在中间包不包含根的情况下,我的初始验证方法不正确失败了。

现在我误以为-untrusted 暗示了“永远不要使用这些证书!”之类的东西,而是旨在指定一个不可信证书链,该证书链返回到“可信”@987654326 中的根@捆绑。

因此,正确使用中间证书和受信任的根包来验证证书的方法是:

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

【讨论】:

    【解决方案2】:

    如果您指定 -CAfile openssl 仅检查给定文件的颁发者,在您的情况下可能仅包含中间证书。

    【讨论】:

      猜你喜欢
      • 2015-10-19
      • 2012-05-26
      • 2011-08-29
      • 2014-03-28
      • 2015-02-01
      • 1970-01-01
      • 2021-11-28
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多