Skip to content

OpenSSL憑證簽署指令

OpenSSL憑證簽署指令 是指利用 OpenSSL 工具組建立憑證頒發機構(CA),並使用該機構的金鑰對伺服器憑證進行簽署的一系列操作。此流程常用於建立自建 CA 中心以簽發憑證^[600-developer__tools__security__CA.md]。

憑證簽署指令

要使用 CA 金鑰對伺服器憑證進行簽名,核心指令為 openssl ca。此指令會讀取憑證簽署請求(CSR),並使用 CA 的私鑰產生並簽署最終的憑證^[600-developer__tools__security__CA.md]。

openssl ca -in tempreq.pem -out server_crt.pem
  • -in: 指定輸入的憑證簽署請求檔案(如 tempreq.pem)。
  • -out: 指定輸出的簽署後憑證檔案(如 server_crt.pem)^[600-developer__tools__security__CA.md]。

相關前置步驟

在使用上述簽署指令前,通常需要先建立 CA 私鑰與自簽憑證。以下為常見的準備工作:

  1. 產生 CA 私鑰(無密碼保護)^[600-developer__tools__security__CA.md]:
    openssl genrsa -out ca.key 2048
    
  2. 產生 CA 自簽憑證 (X.509)^[600-developer__tools__security__CA.md]:
    openssl req -x509 -key ca.key -out ca.crt -days 3650
    
    • -x509: 表示產生自我簽署的憑證。
    • -days: 設定憑證有效期限(例如 3650 天)。
    • 此過程中會要求輸入 Distinguished Name (DN) 資訊,如國家、地區、組織與 Common Name (域名)^[600-developer__tools__security__CA.md]。
  3. 讀取憑證資料^[600-developer__tools__security__CA.md]:
    openssl x509 -in ca.crt -text -noout
    

相關概念

Sources

^[600-developer__tools__security__CA.md]