我正在嘗試實作場景要求客戶端標識自己(雙向 TLS),這在https://github.com/Hakky54/mutual-tls-ssl#require-the-client-to-identify-itself上進行了描述-雙向 tls。
API 服務器是使用https://quarkus.io/以及密鑰庫和信任庫創建的。密鑰庫包含證書和私鑰,而信任庫包含用于客戶端標識的客戶端證書。
現在,我想通過curljava rest 客戶端向 API 服務器發出請求。
我發現,也許是https://stackoverflow.com/a/58920225/1743843上的解決方案,命令如下:
curl --key client.key --cert client.crt --cacert bundle.pem -X GET -v https://x.x.x.x:xxxx/folder/endpoint
該選項--cacert需要通過。但是,我想做Require the client to identify itself (two-way TLS) not Two way TLS based on trusting the Certificate Authority。問題是,我是否可以通過選項--cert服務器證書而不是 CA 證書,或者還有其他選項。
我想不用自簽名證書。
uj5u.com熱心網友回復:
是的,您可以通過該--cert選項,但是您需要提供 Base64 編碼的私鑰對檔案。在該教程中使用密鑰庫檔案jks,您首先需要將其轉換為 curl 可以理解的內容,在本例中為 pem 檔案。你需要做的是:
- 將密鑰庫轉換為 p12 檔案
- 將 p12 檔案轉換為 pem 檔案
- 使用 pem 檔案運行 curl 命令
將密鑰庫轉換為 p12 檔案
keytool -importkeystore -srckeystore truststore.jks -destkeystore truststore.p12 -srcstoretype JKS -deststoretype PKCS12
keytool -importkeystore -srckeystore identity.jks -destkeystore identity.p12 -srcstoretype JKS -deststoretype PKCS12
將 p12 檔案轉換為 pem 檔案
openssl pkcs12 -in truststore.p12 -out trusted-certificates.pem
openssl pkcs12 -in identity.p12 -out identity.pem
使用 pem 檔案運行 curl 命令
curl --cert identity.pem --cacert trusted-certificates.pem https://localhost:8443/api/hello
這些步驟也可以在這里找到:GitHub Gist - Curl with Java KeyStore
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/489587.html
上一篇:如何正確決議curl中的yml?
