差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
tech:curl_ssl [2008/08/22 10:38] – jonathan | tech:curl_ssl [2021/06/13 09:43] (目前版本) – [參考網頁] jonathan | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== cURL 讀取雙向 ssl 認證 Web Server 網頁方式 ====== | ||
+ | * Server 端的 RootCA 是 RootCA.crt | ||
+ | * Server 端測試網址 : https:// | ||
+ | * Client 端的憑證是 ClientCA.crt | ||
+ | * Client 端的密鑰是 ClientCA.key | ||
+ | * 產生 Client 端 pem 格式含有密鑰的憑證檔 <code sh> | ||
+ | cat ClientCA.crt > ClientCA.pem | ||
+ | cat ClientCA.key >> ClientCA.pem | ||
+ | </ | ||
+ | ===== 使用 cURL 語法 ===== | ||
+ | <code sh> | ||
+ | curl --cacert RootCA.crt --cert ClientCA.pem https:// | ||
+ | </ | ||
+ | ++++看產生結果| | ||
+ | < | ||
+ | [jonathan@pd920 ca]$ curl --cacert RootCA.crt --cert ClientCA.pem https:// | ||
+ | Enter PEM pass phrase: <-- 輸入 ClientCA 的密碼 | ||
+ | test | ||
+ | </ | ||
+ | ++++ | ||
+ | * 也可以將 RootCA.crt 加入 CA cert bundle (/ | ||
+ | openssl x509 -inform PEM -in RootCA.crt -out RootCA.pem -text | ||
+ | cat RootCA.pem >> / | ||
+ | </ | ||
+ | |||
+ | * 如果出現 ServerCA 的 CN 定義與網址不符,或是 ServerCA 過期等問題,也可以改用 --insecure 來取消 cURL 檢驗 ServerCA 憑證有效性< | ||
+ | curl --cert ClientCA.pem https:// | ||
+ | curl --insecure --cert ClientCA.pem https:// | ||
+ | </ | ||
+ | ++++看產生結果| | ||
+ | < | ||
+ | [jonathan@pd920 ca]$ curl --cert ClientCA.pem https:// | ||
+ | Enter PEM pass phrase: <-- 輸入 ClientCA 的密碼 | ||
+ | curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: | ||
+ | error: | ||
+ | More details here: http:// | ||
+ | |||
+ | curl performs SSL certificate verification by default, using a " | ||
+ | of Certificate Authority (CA) public keys (CA certs). The default | ||
+ | | ||
+ | using the --cacert option. | ||
+ | If this HTTPS server uses a certificate signed by a CA represented in | ||
+ | the bundle, the certificate verification probably failed due to a | ||
+ | | ||
+ | not match the domain name in the URL). | ||
+ | If you'd like to turn off curl's verification of the certificate, | ||
+ | the -k (or --insecure) option. | ||
+ | [jonathan@pd920 ca]$ | ||
+ | </ | ||
+ | < | ||
+ | [jonathan@pd920 ca]$ curl --insecure --cert ClientCA.pem https:// | ||
+ | Enter PEM pass phrase: <-- 輸入 ClientCA 的密碼 | ||
+ | test | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | * 如果不想因為輸入 ClientCA 密碼中斷自動執行的程序,也可以改寫成 --cert ClientCA.pem**: | ||
+ | curl --insecure --cert ClientCA.pem: | ||
+ | </ | ||
+ | ++++看產生結果| | ||
+ | < | ||
+ | [jonathan@pd920 ca]$ curl --insecure --cert ClientCA.pem: | ||
+ | test | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | * 如果擔心這樣將 ClientCA 密碼暴露在外,也可直接在簽發 ClientCA 時就不設定密碼,或者改用 curl 指定參數檔方式提供, | ||
+ | curl --cacert RootCA.crt --cert ClientCA.pem: | ||
+ | </ | ||
+ | * testcurl.conf 內容就定義為< | ||
+ | cacert = " | ||
+ | cert = " | ||
+ | url = " | ||
+ | </ | ||
+ | * 將 testcurl.conf 定義只有自己可以讀寫的權限< | ||
+ | chmod 600 testcurl.conf | ||
+ | </ | ||
+ | * 使用 cURL config 語法為< | ||
+ | curl --conf testcurl.conf | ||
+ | </ | ||
+ | ++++加上 -v 可看到完整的傳輸訊息| | ||
+ | < | ||
+ | [jonathan@pd920 jonathan]$ curl --conf testcurl.conf -v | ||
+ | * About to connect() to mail.ichiayi.com port 443 | ||
+ | * | ||
+ | * Connected to mail.ichiayi.com (220.130.131.239) port 443 | ||
+ | * successfully set certificate verify locations: | ||
+ | * | ||
+ | CApath: none | ||
+ | * SSLv2, Client hello (1): | ||
+ | SSLv3, TLS handshake, Server hello (2): | ||
+ | SSLv3, TLS handshake, CERT (11): | ||
+ | SSLv3, TLS handshake, Server key exchange (12): | ||
+ | SSLv3, TLS handshake, Request CERT (13): | ||
+ | SSLv3, TLS handshake, Server finished (14): | ||
+ | SSLv3, TLS handshake, CERT (11): | ||
+ | SSLv3, TLS handshake, Client key exchange (16): | ||
+ | SSLv3, TLS handshake, CERT verify (15): | ||
+ | SSLv3, TLS change cipher, Client hello (1): | ||
+ | SSLv3, TLS handshake, Finished (20): | ||
+ | SSLv3, TLS change cipher, Client hello (1): | ||
+ | SSLv3, TLS handshake, Finished (20): | ||
+ | SSL connection using DHE-RSA-AES256-SHA | ||
+ | * Server certificate: | ||
+ | * subject: / | ||
+ | * start date: 2008-08-19 09:15:22 GMT | ||
+ | * expire date: 2010-08-19 09:15:22 GMT | ||
+ | * common name: mail.ichiayi.com (matched) | ||
+ | * issuer: / | ||
+ | * SSL certificate verify ok. | ||
+ | > GET /t.txt HTTP/1.1 | ||
+ | > User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/ | ||
+ | > Host: mail.ichiayi.com | ||
+ | > Accept: */* | ||
+ | > | ||
+ | < HTTP/1.1 200 OK | ||
+ | < Date: Fri, 22 Aug 2008 02:04:49 GMT | ||
+ | < Server: Apache/ | ||
+ | < Last-Modified: | ||
+ | < ETag: " | ||
+ | < Accept-Ranges: | ||
+ | < Content-Length: | ||
+ | < Vary: Accept-Encoding | ||
+ | < Connection: close | ||
+ | < Content-Type: | ||
+ | test | ||
+ | * Closing connection #0 | ||
+ | * SSLv3, TLS alert, Client hello (1): | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ===== 參考網頁 ===== | ||
+ | * [[tech: | ||
+ | * [[tech: | ||
+ | * http:// | ||
+ | * http:// | ||
+ | * https:// | ||
+ | |||
+ | {{tag> |