如何使用 OpenSSL 调试证书链?

Beg*_*ner 4 openssl ssl-certificate

我是 OpenSSL 的新手,我正在阅读有关 OpenSSL 编程以连接到服务器的教程:

www.rtfm.com/openssl-examples/part1.pdf
www.rtfm.com/openssl-examples/part2.pdf
Run Code Online (Sandbox Code Playgroud)

不知何故,设置正确的证书比预期的更棘手...... :(

当我使用 openssl s_client 测试消息时:

openssl s_client -connect 123.456.789.0:666 -CAfile test.crt -debug

我收到错误消息

depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA 证书颁发机构验证错误:num=20:无法获得本地颁发者证书验证返回:0

进而:

错误:14094412:SSL 例程:SSL3_READ_BYTES:sslv3 警报错误证书:s3_pkt.c:1257:SSL 警报编号 42 140685406562208:错误:140790E5:SSL 例程:SSL23_WRITE:ssl failure.c:1257:SSL

这是证书链:

 Certificate chain  
 0 
   s:myself    
   i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Organization Validation Secure Server CA  
 1 
   s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Organization Validation Secure Server CA    
   i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority  
 2 
   s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Authority    
   i:/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root
Run Code Online (Sandbox Code Playgroud)

我试图让系统在几个小时内将这些证书识别为正确,但无济于事......

到目前为止我尝试过的:

  • 使用 update-ca-trust 将 COMODO 证书添加到受信任证书列表的各种变体。
  • 将证书添加到 /etc/ssl/certs 中的受信任证书列表中
  • 在文件夹中创建 pem 文件并使用 -CApath 添加它们。
  • 谷歌的问题在于,大多数教程都是从服务器管理员的角度讨论这个问题的,但我无权访问服务器。

操作系统是 Fedora。

有没有结构化的方法来解决这个问题?


编辑:证书创建如下:

 openssl req -new -x509 -sha256 -days 365 -key mykey.key -out test.crt
Run Code Online (Sandbox Code Playgroud)

Fal*_*mot 6

请确保包含所有中间证书并确保它们是最新的。如果test.crt实际上是一个仅包含 的文件/C=SE/O=AddTrust AB/OU=AddTrust External TTP Network/CN=AddTrust External CA Root,则这是正确的方法。您也可以包含根,大多数客户端会接受这样的链,但少数会窒息。

一般来说,最好的做法是将您的所有证书包含在根之前的最后一个证书中,以防客户端没有最后一个中间证书。

也可能test.crt包含正确链以外的内容。默认情况下,OpenSSL 不进行部分链验证(在旧版本中,它根本不进行)。在此模式下运行时,它不关心 /etc/ssl/certs 中的内容。

或者,您可能会出示过期的中介证书。CA 通常使用相同的密钥重新认证它们的中间体;如果他们这样做,只需下载更新的中间 CA 证书并替换链中过期的证书。

最后,使用 openssl s_client,您需要指定它验证的对象。例如,使用选项-CApath /etc/ssl/certs-CAfile your_ca.crt。对于第一个选项,请使用您系统的信任存储,对于第二个选项,请指定根 CA 证书。