
我正在使用下面的命令
curl --insecure --cert 'cert.p12:password' -X GET https://serverUrl -H 'Content-Type: application/json'
curl --insecure --cert-type P12 --cert 'cert.p12:password' -X GET https://serverUrl -H 'Content-Type: application/json'
它在 Ubuntu 16.04.4 LTS \n \l (AWS Lightsail) 中不起作用並給出以下錯誤
curl:(35)讀取 X.509 潛在加密金鑰檔案時發生錯誤:解析錯誤。
但在 Ubuntu 18.04.3 LTS \n \l (本地系統)工作
答案1
由於 Ubuntu 16.04.4 LTS P12 檔案不支持,所以我們可以使用以下命令
PKCS#1 私鑰
openssl pkcs12 -in cert.p12 -nocerts -out privateKey.pem
證書:
openssl pkcs12 -in cert.p12 -clcerts -nokeys -out publicCert.pem
我們可以使用下面的命令來呼叫API
curl -k --cert ./publicCert.pem --cert-type PEM --key ./privateKey.pem --key-type PEM --pass password -X GET https://serverUrl -H 'Content-Type: application/json'