简体   繁体   English

自签名认证 SSL 证书的问题

[英]Issue with self-signed certified SSL certificate

I followed this guide to install certified self-signed SSL certificate on localhost and all works fine in Chrome (no longer any warning, everything is green if https is used on localhost pages):我按照本指南在 localhost 上安装了经过认证的自签名 SSL 证书,并且在 Chrome 中一切正常(不再有任何警告,如果在 localhost 页面上使用 https,一切都是绿色的):

Getting Chrome to accept self-signed localhost certificate 让 Chrome 接受自签名的本地主机证书

However, if I'm running same requests on Ubuntu console via CURL I'm getting unable to get local issuer certificate :但是,如果我通过 CURL 在 Ubuntu 控制台上运行相同的请求,我将无法获得本地颁发者证书

aherne@home-NUC8i7INH:~$ curl https://localhost
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

This issue reproduces in PHP using certificate from https://curl.haxx.se/ca/cacert.pem :此问题使用https://curl.haxx.se/ca/cacert.pem 中的证书在 PHP 中重现:

$ch = curl_init("https://localhost");
curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
if ($body===false) {
    throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);

On further verification, issue reproduces using openssl command:在进一步验证后,使用 openssl 命令重现问题:

aherne@home:~$ openssl s_client -connect localhost:443\\n CONNECTED(00000005) depth=0 C = RO, ST = Bucharest, L = Bucharest, O = Home, OU = Home, CN = localhost verify error:num=20: unable to get local issuer certificate verify return:1 depth=0 C = RO, ST = Bucharest, L = Bucharest, O = Home, OU = Home, CN = localhost verify error:num=21:unable to verify the first certificate verify return:1 aherne@home:~$ openssl s_client -connect localhost:443\\n CONNECTED(00000005) depth=0 C = RO, ST = Bucharest, L = Bucharest, O = Home, OU = Home, CN = localhost verify error:num= 20:无法获得本地颁发者证书验证返回:1 depth=0 C = RO, ST = Bucharest, L = Bucharest, O = Home, OU = Home, CN = localhost verify error:num=21:unable to verify the first证书验证返回:1


Is there any way to trick CURL in accepting my certificate as well as my authority that certified it (same way as Chrome)?有什么方法可以欺骗 CURL 接受我的证书以及我的认证机构(与 Chrome 相同)? Making cURL skip SSL verification is a non-solution!使 cURL 跳过 SSL 验证是一个非解决方案!

I believe the possible ways to have curl accept your certificate authority are located here:我相信让 curl 接受您的证书颁发机构的可能方法位于此处:

https://curl.haxx.se/docs/sslcerts.html https://curl.haxx.se/docs/sslcerts.html

I suspect this would be the easiest approach:我怀疑这将是最简单的方法:

If you're using the curl command line tool, you can specify your own CA cert file by setting the environment variable CURL_CA_BUNDLE to the path of your choice.如果您使用 curl 命令行工具,则可以通过将环境变量 CURL_CA_BUNDLE 设置为您选择的路径来指定您自己的 CA 证书文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM