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

tquggr8v  于 2023-01-20  发布在  Shell
关注(0)|答案(4)|浏览(436)

我正在使用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中工作?

vyu0f0g1

vyu0f0g11#

Windows版本的curl.exe没有配置为使用openssl,但git的配置为使用openssl。
因此,为了确保每当我在命令提示符中输入'curl'时,它使用的是git版本的curl,我在系统环境变量中添加了git的curl的路径(C:\Program Files\Git\mingw64\bin),并将其移到顶部...这样它就能在找到window的curl之前找到git的curl。
然后重新启动命令提示符,问题解决。

lsmepo6l

lsmepo6l2#

您提供的客户端证书格式错误。curl需要PEM格式的证书(source):

-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格式,或者包含整个证书链而不是单个客户端证书。

wf82jlnq

wf82jlnq3#

在curl的手册页中,描述了在Windows上,它默认使用schannel provider(它本身使用Windows Store)。我现在也在做同样的差事:-)试图找到一种方法,从命令行和本地文件传递证书。
也许可以尝试将证书导入Windows应用商店。

zujrkrfu

zujrkrfu4#

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

相关问题