簡體   English   中英

curl 無法在命令提示符下導入證書文件 client.crt,Powershell 在 gitbash 上工作正常

[英]curl Failed to import cert file client.crt on command prompt and Powershell works fine on gitbash

我正在使用 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 中運行?

curl.exe 的 Windows 版本未配置為與 openssl 一起使用,但 git 的是。

因此,為了確保每當我在命令提示符中鍵入“curl”時,它使用的是 git 的 curl 版本,我在系統環境變量中添加了 git 的 curl (C:\Program Files\Git\mingw64\bin) 的路徑並將其向右移動到頂部……所以它在找到窗口的 curl 之前先找到 git 的 curl。

然后重新啟動命令提示符,它解決了問題。

您提供的客戶端證書格式錯誤。 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 格式或包含整個證書鏈而不是您的單個客戶端證書。

在 curl 的聯機幫助頁中,描述了在 Windows 上,它默認使用 schannel 提供程序(它本身使用 windows 商店)。 我現在在做同樣的事情:-) 試圖找到一種從命令行和本地文件傳遞證書的方法。

也許嘗試將證書導入 Windows 商店。

在我們的 Windows 2019 服務器上,我們有兩個 curl.exe。 默認情況下,調用版本 7.83.1。 通過使用版本 7.54.1 並添加訪問它的完整路徑解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM