答案1
安装 CA
将您的证书以 PEM 格式(其中包含的格式----BEGIN CERTIFICATE----
)复制到其中/usr/local/share/ca-certificates
,并使用文件扩展名命名.crt
。
然后运行sudo update-ca-certificates
。
注意事项:此安装仅影响使用此证书存储的产品。某些产品可能使用其他证书存储;如果您使用这些产品,您还需要将此 CA 证书添加到其他证书存储中。(Firefox 说明,Chrome 说明,Java 说明)
测试CA
您可以通过查找刚刚添加的证书/etc/ssl/certs/ca-certificates.crt
(这只是所有受信任的 CA 连接在一起的长列表)来验证这是否有效。
您还可以使用 OpenSSL 的 s_client 尝试连接到您知道正在使用您刚刚安装的 CA 签名的证书的服务器。
$ openssl s_client -connect foo.whatever.com:443 -CApath /etc/ssl/certs
CONNECTED(00000003)
depth=1 C = US, ST = Virginia, O = "Whatever, Inc.", CN = whatever.com, emailAddress = [email protected]
verify return:1
depth=0 C = US, ST = Virginia, L = Arlington, O = "Whatever, Inc.", CN = foo.whatever.com
verify return:1
---
Certificate chain
0 s:/C=US/ST=Virginia/L=Arlington/O=Whatever, Inc./CN=foo.whatever.com
i:/C=US/ST=Virginia/O=Whatever, Inc./CN=whatever.com/[email protected]
... snip lots of output ...
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1392837700
Timeout : 300 (sec)
Verify return code: 0 (ok)
首先要查找的是输出顶部附近的证书链。这应该显示 CA 为颁发者(旁边i:
)。这告诉您服务器正在提供由您正在安装的 CA 签名的证书。
其次,查找verify return code
末尾的要设置为的0 (ok)
。
答案2
update-ca-certificates is a program that updates the directory /etc/ssl/certs to hold SSL
certificates and generates ca-certificates.crt, a concatenated single-file list of
certificates.
It reads the file /etc/ca-certificates.conf. Each line gives a pathname of a CA
certificate under /usr/share/ca-certificates that should be trusted. Lines that begin
with "#" are comment lines and thus ignored. Lines that begin with "!" are deselected,
causing the deactivation of the CA certificate in question. Certificates must have a .crt
extension in order to be included by update-ca-certificates.
Furthermore all certificates with a .crt extension found below /usr/local/share/ca-
certificates are also included as implicitly trusted.
从以上内容可以推断,将本地证书文件放入受信任存储的首选方法是将其放入/usr/local/share/ca-certificates
,然后运行update-ca-certificates
。您无需/etc/ssl/certs
直接触摸。
答案3
对于从系统证书存储中读取的应用程序,其他答案update-ca-certificates
都是正确的。对于 Chrome 和 Firefox,可能还有其他一些浏览器,证书必须放在 nssdb 中,即 Mozilla NSS 库的后端。
从 https://code.google.com/p/chromium/wiki/LinuxCertManagement:
例如,要信任根 CA 证书来颁发 SSL 服务器证书,请使用
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n <证书昵称> -i <证书文件名>
其中<certificate nickname>
是任意的,并且<certificate filename>
是您的 .pem 或 .crt 文件。
其他有用的参考资料:
答案4
对于基于 Debian 的较新版本,您可能需要运行:
sudo dpkg-reconfigure ca-certificates
注意:sudo dpkg-reconfigure ca-certificates 内部调用 update-ca-certificates
当然,在执行任何操作之前,您仍然需要将证书(.crt 文件)复制到 /usr/share/ca-certificates :)