差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
| tech:openssl_tips [2008/08/22 13:05] – jonathan | tech:openssl_tips [2018/12/31 23:56] (目前版本) – Jonathan Tsai | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== OpenSSL 常用語法整理 ====== | ||
| + | |||
| + | ===== - 直接看憑證檔內容 ==== | ||
| + | <code sh> | ||
| + | openssl x509 -in cert.pem -text -noout | ||
| + | </ | ||
| + | ++++看結果訊息| | ||
| + | < | ||
| + | [root@pve-ms ichiayi.com]# | ||
| + | Certificate: | ||
| + | Data: | ||
| + | Version: 3 (0x2) | ||
| + | Serial Number: | ||
| + | 03: | ||
| + | Signature Algorithm: sha256WithRSAEncryption | ||
| + | Issuer: C=US, O=Let' | ||
| + | Validity | ||
| + | Not Before: Dec 31 14:20:07 2018 GMT | ||
| + | Not After : Mar 31 14:20:07 2019 GMT | ||
| + | Subject: CN=ichiayi.com | ||
| + | Subject Public Key Info: | ||
| + | Public Key Algorithm: rsaEncryption | ||
| + | Public-Key: (2048 bit) | ||
| + | Modulus: | ||
| + | 00: | ||
| + | 26: | ||
| + | 60: | ||
| + | 86: | ||
| + | 07: | ||
| + | ca: | ||
| + | 5d: | ||
| + | a2: | ||
| + | 12: | ||
| + | 6c: | ||
| + | e9: | ||
| + | 66: | ||
| + | ff: | ||
| + | d3: | ||
| + | 7e: | ||
| + | 71: | ||
| + | 0c: | ||
| + | ca:d1 | ||
| + | Exponent: 65537 (0x10001) | ||
| + | X509v3 extensions: | ||
| + | X509v3 Key Usage: critical | ||
| + | Digital Signature, Key Encipherment | ||
| + | X509v3 Extended Key Usage: | ||
| + | TLS Web Server Authentication, | ||
| + | X509v3 Basic Constraints: | ||
| + | CA:FALSE | ||
| + | X509v3 Subject Key Identifier: | ||
| + | 2E: | ||
| + | [root@pve-ms ichiayi.com]# | ||
| + | Certificate: | ||
| + | Data: | ||
| + | Version: 3 (0x2) | ||
| + | Serial Number: | ||
| + | 03: | ||
| + | Signature Algorithm: sha256WithRSAEncryption | ||
| + | Issuer: C=US, O=Let' | ||
| + | Validity | ||
| + | Not Before: Dec 31 14:20:07 2018 GMT | ||
| + | Not After : Mar 31 14:20:07 2019 GMT | ||
| + | Subject: CN=ichiayi.com | ||
| + | Subject Public Key Info: | ||
| + | Public Key Algorithm: rsaEncryption | ||
| + | Public-Key: (2048 bit) | ||
| + | Modulus: | ||
| + | 00: | ||
| + | 26: | ||
| + | 60: | ||
| + | 86: | ||
| + | 07: | ||
| + | ca: | ||
| + | 5d: | ||
| + | a2: | ||
| + | 12: | ||
| + | 6c: | ||
| + | e9: | ||
| + | 66: | ||
| + | ff: | ||
| + | d3: | ||
| + | 7e: | ||
| + | 71: | ||
| + | 0c: | ||
| + | ca:d1 | ||
| + | Exponent: 65537 (0x10001) | ||
| + | X509v3 extensions: | ||
| + | X509v3 Key Usage: critical | ||
| + | Digital Signature, Key Encipherment | ||
| + | X509v3 Extended Key Usage: | ||
| + | TLS Web Server Authentication, | ||
| + | X509v3 Basic Constraints: | ||
| + | CA:FALSE | ||
| + | X509v3 Subject Key Identifier: | ||
| + | 2E: | ||
| + | X509v3 Authority Key Identifier: | ||
| + | keyid: | ||
| + | |||
| + | Authority Information Access: | ||
| + | OCSP - URI: | ||
| + | CA Issuers - URI: | ||
| + | |||
| + | X509v3 Subject Alternative Name: | ||
| + | DNS: | ||
| + | X509v3 Certificate Policies: | ||
| + | Policy: 2.23.140.1.2.1 | ||
| + | Policy: 1.3.6.1.4.1.44947.1.1.1 | ||
| + | CPS: http:// | ||
| + | |||
| + | CT Precertificate SCTs: | ||
| + | Signed Certificate Timestamp: | ||
| + | Version | ||
| + | Log ID : E2: | ||
| + | 3E: | ||
| + | Timestamp : Dec 31 15: | ||
| + | Extensions: none | ||
| + | Signature : ecdsa-with-SHA256 | ||
| + | 30: | ||
| + | 81: | ||
| + | 35: | ||
| + | CD: | ||
| + | CC: | ||
| + | Signed Certificate Timestamp: | ||
| + | Version | ||
| + | Log ID : 29: | ||
| + | 6F: | ||
| + | Timestamp : Dec 31 15: | ||
| + | Extensions: none | ||
| + | Signature : ecdsa-with-SHA256 | ||
| + | 30: | ||
| + | 90: | ||
| + | 99: | ||
| + | 0A: | ||
| + | 26: | ||
| + | Signature Algorithm: sha256WithRSAEncryption | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | ===== - 將憑證 PEM 格式轉成 DER 格式 ===== | ||
| + | <code sh> | ||
| + | openssl x509 -inform PEM -outform DER -in ClientCA.crt -out ClientCA.cer | ||
| + | </ | ||
| + | ++++看結果訊息| | ||
| + | < | ||
| + | [jonathan@pd920 certs]$ openssl x509 -inform PEM -outform DER -in ClientCA.crt -out ClientCA.cer | ||
| + | </ | ||
| + | | {{: | ||
| + | ++++ | ||
| + | |||
| + | ===== - 將憑證 DER 格式轉成 PEM 格式 ===== | ||
| + | <code sh> | ||
| + | openssl x509 -inform DER -in GCA.cer -out GCA.crt | ||
| + | </ | ||
| + | ++++看結果訊息| | ||
| + | < | ||
| + | [jonathan@pd920 gca]$ openssl x509 -inform DER -in GCA.cer -out GCA.crt | ||
| + | </ | ||
| + | | {{: | ||
| + | ++++ | ||
| + | |||
| + | ===== - 將 CRL 檔由 PEM 格式轉成 DER 格式 ===== | ||
| + | <code sh> | ||
| + | openssl crl -in trysoft.crl -outform DER -out trysoft_der.crl | ||
| + | </ | ||
| + | |||
| + | ===== - 檢驗 CRL 檔並將 DER 格式轉成文字格式 ===== | ||
| + | <code sh> | ||
| + | wget http:// | ||
| + | wget http:// | ||
| + | |||
| + | openssl crl -inform DER -in complete.crl -text -CAfile GCA.crt -out gca_crl.txt | ||
| + | </ | ||
| + | ++++結果訊息| | ||
| + | < | ||
| + | [jonathan@pd920 gca]$ openssl crl -inform DER -in complete.crl -text -CAfile GCA.crt -out gca_crl.txt | ||
| + | verify OK | ||
| + | [jonathan@pd920 gca]$ more gca_crl.txt | ||
| + | Certificate Revocation List (CRL): | ||
| + | Version 2 (0x1) | ||
| + | Signature Algorithm: sha1WithRSAEncryption | ||
| + | Issuer: / | ||
| + | \xE8\xAD\x89\xE7\xAE\xA1\xE7\x90\x86\xE4\xB8\xAD\xE5\xBF\x83 | ||
| + | Last Update: Aug 21 16:00:00 2008 GMT | ||
| + | Next Update: Sep 21 16:00:00 2008 GMT | ||
| + | CRL extensions: | ||
| + | : | ||
| + | : | ||
| + | </ | ||
| + | ++++ | ||
| + | ===== - 驗 ClientCA.cer 憑證的方式 ===== | ||
| + | - 要先取得該憑證的 root 憑證 RootCA.crt 與廢止清冊 CRL.crt | ||
| + | - 如果有中繼憑證簽發,也必須取得所有中繼憑證 Exp. Mid1CA.crt , Mid2CA.crt | ||
| + | - 依據順序產生憑證 chain 檔 chain.crt (PEM 格式) ++語法|< | ||
| + | cat RootCA.crt > chain.crt | ||
| + | cat Mid1CA.crt >> chain.crt | ||
| + | cat Mid2CA.crt >> chain.crt | ||
| + | cat CRL.crt >> chain.crt | ||
| + | </ | ||
| + | - 將 ClientCA.cer 由 DER 轉成 PEM 格式 ++語法|< | ||
| + | openssl x509 -inform DER -in ClientCA.cer -out ClientCA.crt | ||
| + | </ | ||
| + | - 執行以下語法來檢驗憑證 ++語法|< | ||
| + | openssl verify -CAfile chain.crt -crl_check ClientCA.crt | ||
| + | </ | ||
| + | - 如果沒問題會++出現|< | ||
| + | [jonathan@pd920 certs]$ openssl verify -CAfile chain.crt -crl_check ClientCA.crt | ||
| + | ClientCA.crt: | ||
| + | </ | ||
| + | - 如果憑證存在廢止清冊內會++出現|< | ||
| + | [jonathan@pd920 certs]$ openssl verify -CAfile chain.crt -crl_check ClientCA.crt | ||
| + | ClientCA.crt: | ||
| + | error 23 at 0 depth lookup: | ||
| + | </ | ||
| + | ===== 相關參考網址 ===== | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | 產生 private key 私密金鑰 及 憑證 cert (365 天, 1024 bits) | ||
| + | openssl req -new -x509 -keyout server.key -out server.crt -days 3650 -newkey rsa:1024 | ||
| + | | ||
| + | |||
| + | -subj '/ | ||
| + | |||
| + | 產生私密金鑰(private key) & 憑證要求(certificate signing request = csr) | ||
| + | | ||
| + | | ||
| + | openssl req -new -key server.key -out server.csr | ||
| + | 簽署 csr 產生 crt | ||
| + | openssl x509 -in server.csr -out server.crt -req -text -signkey server.key | ||
| + | CA 簽發 | ||
| + | openssl ca -policy policy_anything -out server.crt -infiles server.csr | ||
| + | 檢查簽署 | ||
| + | openssl req -in server.csr -noout -verify -key server.key | ||
| + | 檢查憑證 | ||
| + | openssl verify server.crt | ||
| + | 查看 csr 內容 | ||
| + | openssl req -in server.csr -noout -text | ||
| + | -noout : 不輸出BEGIN CERTIFICATE REQUEST | ||
| + | |||
| + | 查看 csr 內容並檢查 | ||
| + | openssl req -in server.csr -noout -text -verify | ||
| + | 查看 crt 內容 | ||
| + | openssl x509 -in server.crt -text | ||
| + | 其它查看的參數 | ||
| + | -issuer | ||
| + | -subject | ||
| + | -dates | ||
| + | |||
| + | 產生 Windows用的 p12 | ||
| + | openssl pkcs12 -export -in server.crt -inkey server.key -out windows.p12 | ||
| + | | ||
| + | openssl pkcs12 -in windows.p12 -out server.crt | ||
| + | windows DER | ||
| + | | ||
| + | 產生 public key | ||
| + | openssl rsa -in server.key -pubout | ||
| + | 產生 rsa key | ||
| + | openssl genrsa | ||
| + | openssl genrsa 1024 | ||
| + | openssl genrsa 1024 -out server.rsa.key | ||
| + | 文件加密、解密 | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | echo "this is a test file" > test.txt | ||
| + | openssl smime -encrypt -in test.txt -out test.msg cert.pem | ||
| + | | ||
| + | openssl smime -decrypt -in test.msg -recip cert.pem -inkey key.pem | ||
| + | | ||
| + | openssl smime -sign -inkey key.pem -signer cert.pem -in test.txt -out test.sig | ||
| + | openssl smime -verif -in test.sig -signer cert.pem -out test2.txt -CAfile cacert.pem | ||
| + | 測試 TLS | ||
| + | openssl s_client -CAfile cacert.pem -connect localhost: | ||
| + | openssl s_client -connect remote.host: | ||
| + | openssl s_time -connect remote_host: | ||
| + | Benchmark | ||
| + | openssl speed | ||
| + | openssl speed rsa | ||
| + | |||
| + | ref: http:// | ||
| + | ref: http:// | ||
| + | ref: http:// | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||