curl 无法在命令提示符下导入证书文件 client.crt,并且 Powershell 在 gitbash 上运行正常

问题描述 投票:0回答:5

我使用的是 Windows...

当我通过 gitbash 运行以下curl 命令时,它工作正常:

curl --cacert ca.crt --key client.key --cert client.crt "https://myurl"

但是,如果我尝试在命令提示符或 Powershell 中运行相同的命令,则会收到此错误:

curl: (58) schannel: Failed to import cert file client.crt, last error is 0x80092002

我需要做什么才能让命令在命令提示符或 Powershell 中运行?

powershell curl
5个回答
14
投票

Windows 版本的curl.exe 未配置为与openssl 一起使用,但git 可以。

因此,为了确保每当我在命令提示符中输入“curl”时,它都使用 git 版本的curl,我在系统环境变量中添加了 git 的curl 的路径(C:\Program Files\Git\mingw64 in)并将其移动一直到顶部……所以它会先找到 git 的卷曲,然后再找到窗口的卷曲。

然后重新启动命令提示符即可解决问题。


0
投票

您提供的客户端证书格式错误。

curl
需要PEM格式的证书(来源):

-E/--cert <certificate[:password]>
     (SSL) Tells curl to use the specified certificate file when getting a file with 
     HTTPS or FTPS. The certificate must be in PEM format. If the optional password 
     isn't specified, it will be queried for on the terminal. Note that this option 
     assumes a "certificate" file that is the private key and the private 
     certificate concatenated! See --cert and --key to specify them independently.

     If curl is built against the NSS SSL library then this option can tell curl the 
     nickname of the certificate to use within the NSS database defined by the 
     environment variable SSL_DIR (or by default /etc/pki/nssdb). If the NSS PEM 
     PKCS#11 module (libnsspem.so) is available then PEM files may be loaded. If you 
     want to use a file from the current directory, please precede it with "./" 
     prefix, in order to avoid confusion with a nickname.

     If this option is used several times, the last one will be used.

您的证书可能采用 DER 格式或包含整个证书链,而不是单个客户端证书。


0
投票

在我们的 Windows 2019 服务器上,我们有两个curl.exe。 默认调用7.83.1版本。 通过使用版本 7.54.1 并添加访问它的完整路径解决了该问题。


0
投票

我遇到了同样的问题,windows curl 和 mingw(git) 的版本都是 8.4.0 我从这里下载了curl 8.6.0 https://curl.se/windows/它解决了这个问题


-1
投票

在curl的手册页中,描述了在Windows上,它默认使用schannel提供程序(它本身使用Windows商店)。我现在正在执行同样的任务:-)试图找到一种从命令行和本地文件传递证书的方法。

也许尝试将证书导入 Windows 商店。

© www.soinside.com 2019 - 2024. All rights reserved.