python-3.x - Openssl:0 深度查找时出现错误 20:无法获取本地颁发者证书

标签 python-3.x ssl openssl python-cryptography

我使用 Python 创建了 3 个证书:rootca.crt、intermediateca.crt 和 server.crt。 我使用rootca.crt来签署intermediateca.crt,它按预期工作:

openssl verify -CAfile rootca.crt intermediateca.crt
intermediateca.crt: OK

然后我用中间ca签署了server.crt,但验证失败:

openssl verify -CAfile rootca.crt -untrusted intermediateca.crt server.crt
server.crt: C = DE, ST = mein Bundesland, L = meine Stadt, O = meine Firma, CN = server.example.com, emailAddress = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cda4a3aba28da0a8a4a3a8e0aba4bfa0ace3a9a8" rel="noreferrer noopener nofollow">[email protected]</a>
error 20 at 0 depth lookup:unable to get local issuer certificate

当我解析证书时,server.crt 授权 key 标识符与 middleca 主题 key 标识符匹配。谁能给我提示可能出了什么问题?如果我使用 openssl 命令行工具生成相同的证书,它就可以工作。解析的内容是相同的,除了授权 key 标识符还包含 openssl 生成的证书的序列号和 cn 之外。

最佳答案

中间 CA 无法用于验证服务器证书,因为其使用者名称与服务器证书中指定的颁发者名称不匹配。

openssl 转储主题和颁发者名称。 -xx_hash 显示 openssl 用于构建证书链的哈希:

$ openssl x509 -subject -subject_hash -noout -in rootca.crt 
subject=C = DE, ST = mein Bundesland, L = meine Stadt, O = meine Firma, OU = meine Abteilung, CN = serviceserver.example.com, emailAddress = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="137a7d757c537e767a7d763e757a617e723d7776" rel="noreferrer noopener nofollow">[email protected]</a>
347e2056

$ openssl x509 -issuer -issuer_hash -noout -in intermediateca.crt 
issuer=C = DE, ST = mein Bundesland, L = meine Stadt, O = meine Firma, OU = meine Abteilung, CN = serviceserver.example.com, emailAddress = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f363139301f323a36313a7239362d323e713b3a" rel="noreferrer noopener nofollow">[email protected]</a>
347e2056

太好了,中间体的发行者名称与根的主题名称相匹配。链条的这一部分起作用了。

$ openssl x509 -subject -subject_hash -noout -in intermediateca.crt 
subject=C = DE, ST = mein Bundesland, L = meine Stadt, O = meine Firma, CN = serviceserver.example.com, emailAddress = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5930373f3619343c30373c743f302b3438773d3c" rel="noreferrer noopener nofollow">[email protected]</a>
c4dff14c

$ openssl x509 -issuer -issuer_hash -noout -in server.crt 
issuer=C = DE, ST = mein Bundesland, L = meine Stadt, O = meine Firma, OU = meine Abteilung, CN = serviceserver.example.com, emailAddress = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e881868e87a8858d81868dc58e819a8589c68c8d" rel="noreferrer noopener nofollow">[email protected]</a>
347e2056

糟糕:哈希值不同,因此 openssl 无法将中间 CA 连接到服务器证书。不同之处在于中间体的主题名称包含 OU 字段,而服务器的颁发者名称则不包含。 openssl 当它告诉您找不到颁发者时是正确的。

我不确定您是如何获得这种状态的,我的猜测是主题或发行人名称的配置错误。

关于python-3.x - Openssl:0 深度查找时出现错误 20:无法获取本地颁发者证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63827480/

相关文章:

node.js - 如果 node.js 是在没有 openssl 的情况下编译的,Socket.io 可以在 node.js 上使用吗?

python - 使用从另一个导入导入的模块

python - win7上python3.2和pyodbc在SQL Server 2008 R2上建表出错

python - 如何阻止我的蛇向自身移动(python,pygame)

java - 有没有办法通过浏览器测试 2 路 ssl?

linux - openssl 命令挂起

python - 如何将 PIL 图像转换为字符串,然后将其转换回 PIL 图像?转换将在不保存到新文件的情况下完成

java - 配置为使用 SSL 的 Tomcat6 不起作用

php - jquery POST 不在 https 中返回任何结果

php - 为什么 PHP 的 md5 与 OpenSSL 的 md5 不同?