验证其余应用程序的证书时出现“x509:由未知颁发机构签名的证书”错误

Pra*_*gat 7 ssl https openssl client-certificates ssl-certificate

我正在 Ubuntu 中使用 openssl 生成自签名证书。我想将它用于本地主机休息服务器。但是在验证时,我收到错误:x509: certificate signed by unknown authority,有人可以告诉我如何解决此错误吗?

谢谢!

小智 1

将根证书和中间证书(如果有的话)放在 /usr/share/local/ca-certificates 中,扩展名为 .crt。

跑步:

sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Run Code Online (Sandbox Code Playgroud)

在这种情况下,curl 是你的朋友:

curl -Iv https://localhost/path/to/api
Run Code Online (Sandbox Code Playgroud)

您也可以运行 openssl s_client

openssl s_client localhost:443
Run Code Online (Sandbox Code Playgroud)

此外,您可以通过提供您的证书来查询您的证书:

openssl s_client -connect localhost:443 -CAfile /path/to/your/cert.pem
Run Code Online (Sandbox Code Playgroud)

如果您的证书不匹配,您就知道。可能您的 REST API 使用了错误的证书,或者未安装证书,您可以通过查看系统上的 /etc/ssl/certs 目录来验证这一点(如果您运行的是 Linux)