跳转至

憑證鏈(Certificate Chain)的建立

以產生中繼憑證(Intermediate CA)為例

生成中繼憑證的私鑰 (Private Key)

為這個中繼 CA 產生一把專屬的私鑰。

openssl genrsa -out intermediate.key.pem 4096

建立憑證簽署請求 (CSR)

使用剛才生成的私鑰來建立一個 CSR。 在這個過程中,你需要填寫組織資訊(DN),最重要的資訊是 Common Name (CN),通常會命名為如 "Company Intermediate CA"。

openssl req -new -sha256 -key intermediate.key.pem -out intermediate.csr.pem

編寫擴充設定檔 (Extension Config)

根憑證、中繼憑證與一般憑證最大的不同在於它的擴充欄位必須聲明它是「一個可以簽發別人的憑證」。 你通常會準備一個 intermediate.cnf 檔案

  1. basicConstraints = critical, CA:true: 這行告訴系統這是一個 CA 憑證。\
  2. keyUsage = critical, digitalSignature, cRLSign, keyCertSign: 聲明它可以簽署憑證和吊銷清單(CRL)。

使用根憑證 (Root CA) 簽署

由更高一級的根憑證(Root CA)對這個 CSR 進行簽署,並套用上述的擴充設定。 一般憑證透過中繼憑證

openssl x509 -req -days 3650 -sha256 \
  -in intermediate.csr.pem \
  -CA root.cert.pem \
  -CAkey root.key.pem \
  -CAcreateserial \
  -out intermediate.cert.pem \
  -extfile intermediate.cnf