使用 libcurl 固定 SSL 证书

SP *_*ner 5 ssl curl ssl-certificate pinning

我想知道这个示例是否足以使用 libcurl 提供证书固定: http://curl.haxx.se/libcurl/c/cacertinmem.html

因为我发现curl也允许http://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html

由于我将使用自签名证书并且只信任它,所以我不知道是否真的有必要固定它。

恢复:如果我只将我的证书(自签名)添加到 x509 证书存储(如示例所示),连接是否会受到损害?我需要添加额外的检查吗?我需要使用 CURLOPT_PINNEDPUBLICKEY 选项吗?

谢谢。

Von*_*onC 1

您可以在 git 2.8(2016 年 3 月)中新的 curl 选项的实现中找到另一个示例:

\n

请参阅Christoph Egger提交的 aeff8a6(2016 年 2 月 15 日) ( )。\n (由Junio C Hamano 合并 -- --提交 e79112d中,2016 年 2 月 24 日)siccegge
gitster

\n
\n

http:实施公钥固定

\n

添加http.pinnedpubkey公钥固定的配置选项。它允许由libcurl--base64(sha256(pubkey))filename完整公钥支持的任何字符串。

\n

如果 cURL 不支持固定(太旧),则会向用户输出警告。

\n
\n

手册git config提到:

\n
http.pinnedpubkey:\n
Run Code Online (Sandbox Code Playgroud)\n
\n

https 服务的公钥。
\n它可以是 PEM 或 DER 编码的公钥文件的文件名,也可以是以 \' sha256//\' 开头的字符串,后跟公钥的 base64 编码的 sha256 哈希值。\n另请参阅libcurl \'CURLOPT_PINNEDPUBLICKEY\'
如果设置了此选项但 cURL 不支持,\ngit 将退出并出现错误。

\n
\n
\n

在 Git 2.34(2021 年第 4 季度)中,涉及 SSL 证书固定时,HTTPS 错误处理已更新:

\n

请参阅\xc3\x86var Arnfj\xc3\xb6r\xc3\xb0 Bjarmason ( )的提交 3e8084f(2021 年 9 月 24 日)。\n (由Junio C Hamano 合并 -- --提交 97492aa中,2021 年 10 月 11 日)avar
gitster

\n
\n

httpCURLE_SSL_PINNEDPUBKEYNOTMATCH:发出错误时检查

\n

签署人:\xc3\x86var Arnfj\xc3\xb6r\xc3\xb0 Bjarmason

\n
\n
\n

http.pinnedPubKey将 a不匹配时显示的错误更改为指向aeff8a6http.pinnedPubKey中添加的变量(“ :实现公钥固定”,2016-02-15,Git v2.8.0-rc0 -合并在批次 #8中列出),例如:http

\n
git -c http.pinnedPubKey=sha256/someNonMatchingKey ls-remote https://github.com/git/git.git\nfatal: unable to access \'https://github.com/git/git.git/\' with http.pinnedPubkey configuration: SSL: public key does not match pinned public key!\n
Run Code Online (Sandbox Code Playgroud)\n

在此之前,我们会发出完全相同的内容,但不带“ with http.pinnedPubkey configuration”。
\n这样做的好处是我们将得到一条翻译后的消息(“ :”之后的所有内容都在 中用英语硬编码),并且我们获得了对导致错误的配置变量的libcurl引用。git-specific

\n

不幸的是,我们无法轻松测试这一点,因为https://测试套件中没有需要的测试,并且t/lib-httpd.sh不知道如何设置此类测试。
\n请参阅此线程以开始讨论如何产生分歧”t/lib-httpd/apache.conf ”测试设置。

\n
\n