gpt4 book ai didi

c++ - 无法在 libcurl 中获取证书位置

转载 作者:行者123 更新时间:2023-11-30 04:49:27 28 4
gpt4 key购买 nike

我在用 C++ 编写的客户端应用程序中使用 libcurl,以使用 HTTPS 连接到远程系统。客户端证书进一步保护连接。连接后,我收到以下消息:

Cert file: 'C:\my-certs\client.crt'.
Key file: 'C:\my-certs\client.key'.
CURL (0): Trying <ipaddress>...
CURL (0): TCP_NODELAY set
CURL (0): Connected to <hostname> (<ipaddress>) port 443 (#0)
CURL (0): schannel: SSL/TLS connection with <hostname> port 443 (step 1/3)
CURL (0): schannel: disabled server certificate revocation checks
CURL (0): schannel: verifyhost setting prevents Schannel from comparing the supplied target name with the subject names in server certificates.
CURL (0): schannel: Failed to get certificate location for C:\my-certs\client.crt
The connection to <hostname> was closed.

我确定 .crt 和 .key 文件存在于指定位置,并且是可读的。我在 CURL 中设置了以下与 SSL 相关的选项:

CURLOPT_SSLCERT: C:\my-certs\client.crt
CURLOPT_SSLKEY: C:\my-certs\client.key
CURLOPT_SSL_VERIFYHOST: 0
CURLOPT_SSL_VERIFYPEER: 0

消息“无法获取证书位置”是什么意思,我应该怎么做?

我正在使用 libcurl/7.61.1-DEV WinSSL zlib/1.2.11,取自 vcpkg,并在 Windows 7 上运行。该应用程序在禁用客户端证书的情况下运行良好;只有当我添加 SSLCERT 和 SSLKEY 选项时它才会失败。

最佳答案

如果 libcurl 是使用 Windows 上的 schannel 构建的( native TLS API),您似乎无法指定证书文件的路径。您需要在系统存储中指定证书的路径,如 docs 中所述:

(仅限 Schannel)客户端证书必须由证书库的路径表达式指定。 (不支持加载 PFX;您可以先将其导入商店)。您可以使用 <store location><store name><thumbprint>引用系统证书存储中的证书,例如 "CurrentUser\MY\934a7ac6f8a5d579285a74fa61e19f23ddfe8d7a" .指纹通常是一个 SHA-1 十六进制字符串,您可以在证书详细信息中看到它。支持以下存储位置:CurrentUser、LocalMachine、CurrentService、Services、CurrentUserGroupPolicy、LocalMachineGroupPolicy、LocalMachineEnterprise。

您也可以在 libcurl 源代码中查看它,查看函数 schannel_connect_step1get_cert_location在文件中 lib/vtls/schannel.c

关于c++ - 无法在 libcurl 中获取证书位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55386742/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com