【发布时间】:2021-12-11 14:46:46
【问题描述】:
我正在开发 CloudFlare 背后的 API,我想完全验证连接以扩展安全性。我现在使用的平台是 Windows 10。
首先我下载了一些在 CloudFlare 网站上找到的 CA(Cloudflare_CA.pem、origin_ca_rsa_root.pem、origin_ca_ecc_root.pem),然后尝试在 CURL 中设置好所需的选项后联系 API:
struct curl_blob blob;
std::string cf_pem = ...;
blob.data = cf_pem.data();
blob.len = cf_pem.size();
blob.flags = CURL_BLOB_COPY;
curl_easy_setopt(pcurl, CURLOPT_CAINFO_BLOB, &blob);
/* Set the default value: strict certificate check please */
curl_easy_setopt(pcurl, CURLOPT_SSL_VERIFYPEER, 1L);
/* Set the default value: strict name check please */
curl_easy_setopt(pcurl, CURLOPT_SSL_VERIFYHOST, 2L);
全部失败,出现 PEER 验证错误。然后我用openssl测试了以下内容:
openssl s_client -connect website:443
结果是:
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 256 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 20 (unable to get local issuer certificate)
后来我发现了一个非常好的命令,它基本上从给定的网站“提取”了 CA:
openssl s_client -showcerts -servername website -connect website:443 > cacert.pem
最后我还是收到了:
Verify return code: 20 (unable to get local issuer certificate)
但是,cacert.pem 是在其中创建了一些内容。我在 -----BEGIN CERTIFICATE-----/-----END CERTIFICATE----- 之间获取了第一个证书,并将其放入代码中。
验证成功,CURL 不再抱怨。但是,我无法联系 CloudFlare 下的其他主机,这意味着此 CA 不“正常”。
所以我的问题是,该怎么办?如何为 CloudFlare 找到正确的 CA?
请指教,我相信其他开发者也可能面临同样的问题。
【问题讨论】: