如何找到OpenSSL可信证书的路径?
如何找出我的 OpenSSL 安装在哪里寻找已安装(受信任)的证书?
有时是 /etc/ssl/cert
,但我有一个新系统,它无法使用此路径。
How can I find out where my OpenSSL installation is looking for installed (trusted) certificates?
It is sometimes /etc/ssl/cert
, but I have a new system and it is not working with this path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查找证书的默认路径在每个平台上可能有所不同。您可以使用以下命令查找系统配置:
The default path where certificates are looked up might be different on each platform. You can lookup your system configuration using the following command:
这个针对 OpenSSL 编译的 C 代码片段将告诉您:
This C snippet, compiled against OpenSSL, will tell you:
您正在寻找的路径是“OpenSSL 文件目录”。正如 @tnbt 回答,
openssl version -d
(或-a
) 为您提供此目录的路径。 OpenSSL 在此查找名为cert.pem
的文件和子目录certs/
。它找到的证书被openssl s_client
和openssl verify
视为可信(来源:文章,OpenSSL 认可哪些证书颁发机构?)。事实证明,在我的系统上安装 OpenSSL 的安装程序还安装了
cert.pem
作为工具cUrl
。这些又来自 Mozilla。您可能没有在此文件或目录中安装任何内容,或者您可能拥有一组不同的证书。这将影响 OpenSSL 验证哪些服务器证书。
支持
s_client
等 OpenSSL 命令,我认为从 1.1 版本开始,选项-no-CAfile
和-no-CApath
。这些允许您在一个命令的持续时间内分别忽略此文件和目录中的证书。 (我无法重现这个,因为我仍在使用版本 1.0.2,并且它缺少这些选项。)The path you are looking for is the "Directory for OpenSSL files". As @tnbt answered,
openssl version -d
(or-a
) gives you the path to this directory. OpenSSL looks here for a file namedcert.pem
and a subdirectorycerts/
. Certificates it finds there are treated as trusted byopenssl s_client
andopenssl verify
(source: the article, What certificate authorities does OpenSSL recognize?).It turns out that the installer which installed OpenSSL on my system also installed
cert.pem
as a symlink to a bundle of Certificate Authority certificates from the toolcUrl
. Those in turn came from Mozilla.You might have nothing installed in this file or directory, or you might have a different set of certificates. This will affect which server certificates OpenSSL verifies.
OpenSSL commands like
s_client
support, I think since version 1.1, options-no-CAfile
and-no-CApath
. These let you ignore the certificates in this file and directory respectively, for the duration of one command. (I can't reproduce this because I am still using version 1.0.2, and it lacks those options.)你不能。默认情况下,OpenSSL 不信任任何内容,并且它不会寻找证书。你必须指示它信任什么。甚至还有一个常见问题解答主题涵盖了它:为什么
因证书验证错误而失败?:Caf 的答案是正确的,但 OpenSSL 不使用它,并且那里什么也没有...
在上面,请注意它没有命中
apps/
目录中的任何内容。apps/
是所有 OpenSSL 示例和实用程序所在的位置,例如openssl req
、openssl rsa
、openssl dsa
、openssl x509
、openssl sign
、openssl verify
等。然后:
最后:
就像我说的,它没有被使用,那里什么也没有。
You can't. OpenSSL trusts nothing by default, and it does not go looking for certs. You have to instruct it what to trust. There's even a FAQ topic covering it: Why does
<SSL program>
fail with a certificate verify error?:Caf's answer is kind of correct, but OpenSSL does not use it and there's nothing there...
In the above, notice it does not hit on anything in the
apps/
directory.apps/
is where all the OpenSSL samples and utilities are, likeopenssl req
,openssl rsa
,openssl dsa
,openssl x509
,openssl sign
,openssl verify
, etc.Then:
And finally:
Like I said, its not used and there's nothing there.