在Linux上使用OpenSSL進行數字證書驗證的步驟如下:
首先,確保你的Linux系統上已經安裝了OpenSSL。大多數Linux發行版默認已經安裝了OpenSSL,但如果沒有,可以使用以下命令進行安裝:
sudo apt-get update
sudo apt-get install openssl
假設你已經有一個證書文件(例如 certificate.crt
),你可以使用以下命令查看證書的詳細信息:
openssl x509 -in certificate.crt -text -noout
如果你的證書是由中間證書簽發的,你需要驗證整個證書鏈。假設你有以下文件:
certificate.crt
:你的證書intermediate.crt
:中間證書root.crt
:根證書你可以使用以下命令將這些證書合并到一個文件中,然后進行驗證:
cat certificate.crt intermediate.crt root.crt > fullchain.crt
openssl verify -CAfile root.crt fullchain.crt
如果證書鏈驗證成功,你會看到類似以下的輸出:
fullchain.crt: OK
你可以使用以下命令檢查證書的有效期:
openssl x509 -in certificate.crt -noout -dates
輸出示例:
notBefore=Jan 1 12:00:00 2020 GMT
notAfter=Dec 31 23:59:59 2020 GMT
你可以使用以下命令驗證證書的簽名:
openssl x509 -in certificate.crt -noout -modulus | openssl md5
openssl rsa -in certificate.key -noout -modulus | openssl md5
如果兩個命令的輸出相同,說明證書的簽名是有效的。
如果你需要檢查證書是否被吊銷,可以使用OCSP(Online Certificate Status Protocol)或CRL(Certificate Revocation List)。以下是使用OCSP的示例:
openssl ocsp -issuer issuer.crt -cert certificate.crt -url http://ocsp.example.com
如果證書未被吊銷,你會看到類似以下的輸出:
OCSP response: success
你可以使用以下命令檢查證書的主題和頒發者:
openssl x509 -in certificate.crt -noout -subject
openssl x509 -in certificate.crt -noout -issuer
輸出示例:
subject=CN=example.com
issuer=CN=Root CA,O=Example Org,C=US
通過以上步驟,你可以在Linux上使用OpenSSL對數字證書進行全面的驗證。