簡體   English   中英

自簽名認證 SSL 證書的問題

[英]Issue with self-signed certified SSL certificate

我按照本指南在 localhost 上安裝了經過認證的自簽名 SSL 證書,並且在 Chrome 中一切正常(不再有任何警告,如果在 localhost 頁面上使用 https,一切都是綠色的):

讓 Chrome 接受自簽名的本地主機證書

但是,如果我通過 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

此問題使用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);

在進一步驗證后,使用 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:無法獲得本地頒發者證書驗證返回: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


有什么方法可以欺騙 CURL 接受我的證書以及我的認證機構(與 Chrome 相同)? 使 cURL 跳過 SSL 驗證是一個非解決方案!

我相信讓 curl 接受您的證書頒發機構的可能方法位於此處:

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

我懷疑這將是最簡單的方法:

如果您使用 curl 命令行工具,則可以通過將環境變量 CURL_CA_BUNDLE 設置為您選擇的路徑來指定您自己的 CA 證書文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM