openssl 指令

產生 private key 私密金鑰 及 憑證 cert (365 天, 1024 bits)

openssl req -new -x509 -keyout server.key -out server.crt -days 3650 -newkey rsa:1024

   -nodes : 可以不加密碼

   -subj '/C=TW/ST=Taiwan/L=Taipei/CN=ssorc.tw/emailAddress=cross@ssorc.tw' : 個人資訊,加的話不會出用提示的方式


產生私密金鑰(private key) & 憑證要求(certificate signing request = csr)

   openssl req -new -keyout server.key -out server.csr -days 365 -newkey rsa:1024

   如果要引用已有 private key 了來產生憑證要求

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

   openssl x509 -in cacert.pem -out cacert.der -outform DER

產生 public key

openssl rsa -in server.key -pubout

產生 rsa key

openssl genrsa
openssl genrsa 1024
openssl genrsa 1024 -out server.rsa.key

文件加密、解密

   明文文件(plain text)  :test.txt
   密文文件(cipher text):test.msg


   文件加密

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

   驗證簽章(Verify Signature)

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:993
openssl s_client -connect remote.host:25 -starttls smtp
openssl s_time -connect remote_host:443

Benchmark

openssl speed
openssl speed rsa


ref: http://www.madboa.com/geek/openssl/
ref: http://www.ascc.net/nl/91/1819/02.txt
ref: http://www.study-area.org/tips/certs/certs.html

標籤: ssl openssl
評論: 2 | 引用: 0 | 閱讀: 6171 | 列印 | 文件 | 轉發

  • 1 
瘦河馬 [ 2011-02-14 16:45 網址 | 回覆 | 編輯 刪除 ]
感謝您的教學
  • 1 
發表評論
暱 稱: 密 碼:
網 址: E - mail:
驗證碼: 驗證碼圖片 選 項:
頭 像:
內 容:
  • 粗體
  • 斜體
  • 底線
  • 插入圖片
  • 超連結
  • 電子郵件
  • 插入引用
  • 表情符號