使用 libcurl 固定 SSL 证书

2023-12-30

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

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

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

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

Thanks.


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

See commit aeff8a6 https://github.com/git/git/commit/aeff8a61216bf6e0d663c08c583bc8552fa3c344 (15 Feb 2016) by Christoph Egger (siccegge) https://github.com/siccegge.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit e79112d https://github.com/git/git/commit/e79112d21024beb997951381db21a70b087d459d, 24 Feb 2016)

http:实施公钥固定

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

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

The git config手册页 https://github.com/git/git/blob/aeff8a61216bf6e0d663c08c583bc8552fa3c344/Documentation/config.txt#L1682-L1688提到:

http.pinnedpubkey:

https 服务的公钥。
它可以是 PEM 或 DER 编码的公钥文件的文件名,也可以是以 ' 开头的字符串sha256//' 后面是公钥的 Base64 编码 sha256 哈希值。 也可以看看libcurl 'CURLOPT_PINNEDPUBLICKEY' https://curl.haxx.se/libcurl/c/CURLOPT_PINNEDPUBLICKEY.html.
如果设置了此选项但 cURL 不支持,git 将退出并出现错误。


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

See commit 3e8084f https://github.com/git/git/commit/3e8084f1884ffea25b80f76b7a1bd0e5b3200c8a (24 Sep 2021) by Ævar Arnfjörð Bjarmason (avar) https://github.com/avar.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 97492aa https://github.com/git/git/commit/97492aacffee48dd217164f6af4b9d1db1aa6646, 11 Oct 2021)

http https://github.com/git/git/commit/3e8084f1884ffea25b80f76b7a1bd0e5b3200c8a: check CURLE_SSL_PINNEDPUBKEYNOTMATCH当发出错误时

Signed-off-by: Ævar Arnfjörð Bjarmason

更改出现错误时显示的错误http.pinnedPubKey不匹配指向http.pinnedPubKey变量添加到aeff8a6 https://github.com/git/git/commit/aeff8a61216bf6e0d663c08c583bc8552fa3c344 ("http:实现公钥固定”,2016-02-15,Git v2.8.0-rc0 --merge https://github.com/git/git/commit/e79112d21024beb997951381db21a70b087d459d列于batch #8 https://github.com/git/git/commit/56f37fda511e1615dc6df86c68f3b841711a7828), e.g.:

git -c http.pinnedPubKey=sha256/someNonMatchingKey ls-remote https://github.com/git/git.git
fatal: unable to access 'https://github.com/git/git.git/' with http.pinnedPubkey configuration: SSL: public key does not match pinned public key!

在此之前,我们会发出完全相同的东西,而不需要“with http.pinnedPubkey configuration".
这样做的好处是我们将收到翻译后的消息(“”之后的所有内容):“ 是用英语硬编码的libcurl),并且我们已经得到了对git-specific导致错误的配置变量。

不幸的是,我们无法轻松测试这一点,因为没有任何测试需要https://在测试套件中,以及t/lib-httpd.sh不知道如何设置此类测试。
See 这个线程 https://lore.kernel.org/git/YUonS1uoZlZEt+Yd@coredump.intra.peff.net/开始讨论如何才能产生分歧”t/lib-httpd/apache.conf“测试设置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 libcurl 固定 SSL 证书 的相关文章

随机推荐