SSL:错误:0B080074:x509证书例程:X509_check_private_key:键值不匹配

Gal*_*lou 84 ssl openssl key certificate nginx

我无法设置SSL.我用谷歌搜索了一些解决方案,但没有一个能为我工作.我需要一些帮助...

这是我尝试重新启动nginx时出现的错误:

root@s17925268:~# service nginx restart
Restarting nginx: nginx: [emerg] SSL_CTX_use_PrivateKey_file("/etc/nginx/conf.d/ssl/ssl.key") failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch)
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)

我的证书来自StartSSL,有效期为1年.

这是我测试的内容:

  • 证书和私钥没有尾随空格.
  • 我没有使用默认的server.key文件.
  • 我检查了nginx.conf,指令指向正确的私钥和证书.

我还检查了模数,我得到了密钥和证书的不同模数.

谢谢您的帮助.:)

Vyn*_*nce 153

一旦你确定他们不匹配,你仍然有一个问题 - 如何处理它.通常,证书可能仅仅是错误地组装.当CA签署您的证书时,他们会向您发送一个类似的块

-----BEGIN CERTIFICATE-----
MIIAA-and-a-buncha-nonsense-that-is-your-certificate
-and-a-buncha-nonsense-that-is-your-certificate-and-
a-buncha-nonsense-that-is-your-certificate-and-a-bun
cha-nonsense-that-is-your-certificate-and-a-buncha-n
onsense-that-is-your-certificate-AA+
-----END CERTIFICATE-----
Run Code Online (Sandbox Code Playgroud)

他们还会向您发送一个捆绑(通常是两个证书),代表他们授予您证书的权限.这看起来像

-----BEGIN CERTIFICATE-----
MIICC-this-is-the-certificate-that-signed-your-request
-this-is-the-certificate-that-signed-your-request-this
-is-the-certificate-that-signed-your-request-this-is-t
he-certificate-that-signed-your-request-this-is-the-ce
rtificate-that-signed-your-request-A
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIICC-this-is-the-certificate-that-signed-for-that-one
-this-is-the-certificate-that-signed-for-that-one-this
-is-the-certificate-that-signed-for-that-one-this-is-t
he-certificate-that-signed-for-that-one-this-is-the-ce
rtificate-that-signed-for-that-one-this-is-the-certifi
cate-that-signed-for-that-one-AA
-----END CERTIFICATE-----
Run Code Online (Sandbox Code Playgroud)

除了不幸的是,他们的标签不会那么清楚.

通常的做法是将这些全部捆绑到一个文件中 - 您的证书,然后是签名证书.但由于它们不容易区分,有时会发生某人意外地将它们置于另一个顺序 - 签署证书,然后是最终证书 - 而没有注意到.在这种情况下,您的证书将与您的密钥不匹配.

您可以通过运行来测试以查看证书认为它代表的内容

openssl x509 -noout -text -in yourcert.cert
Run Code Online (Sandbox Code Playgroud)

在顶部附近,你应该看到"主题:",然后看起来像你的数据.如果它看起来像你的CA,你的包可能是错误的顺序; 您可以尝试进行备份,然后将最后一个证书移到开头,希望这是您的证书.

如果这不起作用,您可能只需要重新颁发证书.当我创建CSR时,我喜欢清楚标记它的服务器(而不仅仅是ssl.key或server.key)并使用名称中的日期复制它,例如mydomain.20150306.key等.他们的私钥和公钥对不太可能与另一套混在一起.

  • 显示如何查看证书链中的内容的巨大+1. (21认同)
  • 好的,这对于Comodo证书和Ngix也对我有用。刚刚将最后一个证书块推到顶部。感谢您对此问题的详细解释和见解。 (2认同)

dev*_*v0z 61

  1. 确保您的证书和密钥是PEM格式.如果没有,则使用openssl命令转换它们
  2. 检查公钥的MD5哈希,以确保它与私钥中的内容匹配

    openssl x509 -noout -modulus -in certificate.crt | openssl md5

    openssl rsa -noout -modulus -in privateKey.key | openssl md5

  • 好建议 !好吧,即使md5哈希对我来说也是一样的^^ (6认同)
  • 感谢您提供如何验证哈希值.我发现我有一个复制粘贴错误,并且从我的pem开头就错过了一个短划线.你刚刚给我带来了很多麻烦.干杯. (3认同)

dev*_*v0z 32

我得到了一个MD5哈希,其中包含密钥和证书的不同结果.

这说明了一切.您的密钥和证书之间不匹配.

模数应匹配.确保你有正确的钥匙.


Man*_*ill 30

我有这个问题,因为我是以错误的顺序添加捆绑和证书,所以这可能会帮助其他人.

之前(这是错误的):

__CODE__

之后(这是对的)

__CODE__

并且请不要忘记更新相应的conf(ssl_certificate现在必须指向链接的crt)as

cat ca_bundle.crt certificate.crt > bundle_chained.crt
Run Code Online (Sandbox Code Playgroud)

nginx联机帮助页:

如果服务器证书和软件包的连接顺序错误,则nginx将无法启动并显示错误消息:

cat certificate.crt ca_bundle.crt > bundle_chained.crt
Run Code Online (Sandbox Code Playgroud)

  • 这实际上是对这个问题的一个更好的答案,而不是被接受的答案。 (6认同)
  • 极好的!这正是问题所在。 (3认同)

Mar*_*ian 8

如果发生这种情况并且您正在使用Let的加密/ certbot,原因很可能是您使用chain.pem而不是fullchain.pem.

它应该是这样的:

ssl_certificate /etc/certbot/live/example.com/fullchain.pem;
ssl_certificate_key /etc/certbot/live/example.com/privkey.pem;
Run Code Online (Sandbox Code Playgroud)

请参阅certbot docs"我的证书在哪里?"


fuw*_*hin 6

我遇到了同样的问题,最终通过更改证书文件中 pem 块的顺序解决了它。

cert 块应该放在文件的开头,然后是中间块,然后是根块。

我通过比较有问题的证书文件和工作证书文件来意识到这个问题。