Skip to content

X.509憑證格式

X.509 是一種廣泛使用的憑證標準格式,主要用於定义金鑰憑證的結構。在 [[TLS]] 及 [[PKI]] (Public Key Infrastructure) 環境中,它通常採用 Base-64 編碼,常見的副檔名包含 .CER.CRT 以及 .PEM^[600-developer__tools__security__CA.md]。

結構與內容

X.509 憑證包含多個欄位,用於記錄憑證本身的元數據與所屬實體的資訊。一個標準的憑證資料通常包含以下項目^[600-developer__tools__security__CA.md]:

  • Version (版本):憑證格式版本(例如 Version 3)。
  • Serial Number (序號):憑證的唯一識別碼。
  • Signature Algorithm (簽章演算法):簽發機構使用的簽名演算法(如 sha256WithRSAEncryption)。
  • Issuer (簽發者):簽發此憑證的機構名稱(例如 CA 的 Distinguished Name)。
  • Validity (有效期間)
    • Not Before:憑證生效日期。
    • Not After:憑證過期日期。
  • Subject (主體):憑證持有者的資訊,如國家 (C)、地區 (ST)、組織 (O)、通用名稱 (CN) 等。
  • Subject Public Key Info (公鑰資訊):包含公鑰演算法及公鑰內容。
  • X509v3 Extensions:額外的擴展欄位。

常見擴展功能

X.509 v3 版本透過擴展欄位提供了更豐富的功能特性^[600-developer__tools__security__CA.md]:

  • Basic Constraints:用於定義憑證是否為 CA (Certificate Authority)。此欄位若標記為 critical 且設定 CA:TRUE,表示該憑證具有簽發其他憑證的權限^[600-developer__tools__security__CA.md]。
  • Subject Key Identifier:標識該憑證所包含的公鑰。
  • Authority Key Identifier:標識簽發者憑證(CA)的公鑰。
  • Key Usage:定義公鑰的用途,例如數位簽章 (Digital Signature)、憑證簽發 (Certificate Sign) 或 CRL 簽發 (CRL Sign)^[600-developer__tools__security__CA.md]。
  • Subject Alternative Name (SAN):允許指定額外的身份識別資訊,如域名 (DNS)、IP 地址或電子郵件。

資料檢視

由於 X.509 憑證通常為編碼後的文字格式(如 Base-64),人類無法直接閱讀。通常使用 openssl 工具來解析並閱讀憑證內容^[600-developer__tools__security__CA.md]。

例如,要查看憑證的詳細資訊,可以使用以下指令^[600-developer__tools__security__CA.md]:

openssl x509 -in <filename>.crt -text -noout

此指令會將上述的 Version、Issuer、Validity 及 Extensions 等資訊以明文格式列印出來^[600-developer__tools__security__CA.md]。

Sources