【发布时间】:2010-11-09 20:18:01
【问题描述】:
如何找出我的 OpenSSL 安装在哪里寻找已安装(可信)的证书?
有时是/etc/ssl/cert,但我有一个新系统,它不适用于这条路径。
【问题讨论】:
-
尝试在此页面上查找您的系统类型:gagravarr.org/writing/openssl-certs/others.shtml
标签: certificate openssl
如何找出我的 OpenSSL 安装在哪里寻找已安装(可信)的证书?
有时是/etc/ssl/cert,但我有一个新系统,它不适用于这条路径。
【问题讨论】:
标签: certificate openssl
在每个平台上查找证书的默认路径可能不同。您可以使用以下命令查找系统配置:
$ openssl version -d
OPENSSLDIR: "/etc/pki/tls"
【讨论】:
这个针对 OpenSSL 编译的 C sn-p 会告诉你:
#include <stdlib.h>
#include <stdio.h>
#include <openssl/x509.h>
int main()
{
const char *dir;
dir = getenv(X509_get_default_cert_dir_env());
if (!dir)
dir = X509_get_default_cert_dir();
puts(dir);
return 0;
}
【讨论】:
您要查找的路径是“OpenSSL 文件目录”。正如@tnbt answered、openssl version -d(或-a)为您提供该目录的路径。 OpenSSL 在此处查找名为 cert.pem 的文件和子目录 certs/。它发现的证书被openssl s_client 和openssl verify 视为受信任的证书(来源:文章,What certificate authorities does OpenSSL recognize?)。
% openssl version -d
OPENSSLDIR: "/opt/local/etc/openssl"
% ls -l /opt/local/etc/openssl/cert*
lrwxr-xr-x 1 root admin 40 29 Nov 02:05 /opt/local/etc/openssl/cert.pem -> /opt/local/share/curl/curl-ca-bundle.crt
% head -10 /opt/local/etc/openssl/cert.pem
##
## Bundle of CA Root Certificates
##
## Certificate data from Mozilla as of: Fri Nov 24 08:00:26 2017 GMT
##
## This is a bundle of X.509 certificates of public Certificate Authorities
## (CA). These were automatically extracted from Mozilla's root certificates
## file (certdata.txt). This file can be found in the mozilla source tree:
## https://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt
##
...[rest of file omitted]...
事实证明,在我的系统上安装 OpenSSL 的安装程序还安装了 cert.pem 作为来自工具 cUrl 的证书颁发机构证书包的符号链接。这些反过来来自 Mozilla。
您可能没有在此文件或目录中安装任何内容,或者您可能有一组不同的证书。这将影响 OpenSSL 验证的服务器证书。
像s_client 这样的OpenSSL 命令支持,我认为从1.1 版开始,选项-no-CAfile 和-no-CApath。这些使您可以在一个命令的持续时间内分别忽略此文件和目录中的证书。 (我无法重现这一点,因为我仍在使用 1.0.2 版,并且缺少这些选项。)
【讨论】:
我怎样才能知道我安装的 openssl 在哪里寻找已安装的证书(受信任)?
你不能。默认情况下,OpenSSL 不信任任何内容,并且它不会去寻找证书。你必须指示它信任什么。甚至还有一个常见问题解答主题:Why does <SSL program> fail with a certificate verify error?:
此问题通常由日志消息指示 像“无法获得本地颁发者证书”或“自签名” 证书”。验证证书时,其根 CA 必须是 OpenSSL“信任”这通常意味着 CA 证书必须 放置在目录或文件中并配置相关程序 阅读它。 OpenSSL 程序“验证”的行为方式类似,并且 发出类似的错误消息:检查 verify(1) 程序手册页 了解更多信息。
Caf 的回答有点正确,但是 OpenSSL 没有使用它,而且那里什么都没有……
$ grep -R X509_get_default_cert_dir *
...
crypto/x509/x509_def.c:const char *X509_get_default_cert_dir(void)
...
在上面,请注意它确实没有命中apps/ 目录中的任何内容。 apps/ 是所有 OpenSSL 示例和实用程序所在的位置,例如 openssl req、openssl rsa、openssl dsa、openssl x509、openssl sign、openssl verify 等。
然后:
$ cat crypto/x509/x509_def.c
...
const char *X509_get_default_cert_dir(void)
{ return(X509_CERT_DIR); }
...
$ grep -R X509_CERT_DIR *
crypto/cryptlib.h:#define X509_CERT_DIR OPENSSLDIR "/certs"
最后:
$ ls /usr/local/ssl/certs/
$
就像我说的,它没有用过,那里什么也没有。
【讨论】:
cert.pem 的文件或子目录certs/ 中找到的任何证书。来源:What certificate authorities does OpenSSL recognize?。现在,可能是您的安装在此目录中没有任何内容,但我的安装有一个 cert.pem 符号链接到根证书颁发机构证书的集合,因此我的安装“自动”信任许多站点。