我在用 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_step1
和get_cert_location
在文件lib/vtls/schannel.c
中
关于c++ - 无法获取 libcurl 中的证书位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55386742/