Hello! 欢迎来到小浪云!


OpenSSL在Linux上如何进行数字证书验证


OpenSSL在Linux上如何进行数字证书验证

本文介绍在Linux系统上利用OpenSSL验证数字证书的完整流程。

第一步:安装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。 请将 http://ocsp.example.com 替换为实际的OCSP URL。

第七步:验证证书主题和颁发者

检查证书的主题和颁发者信息:

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环境下全面验证数字证书的有效性和安全性。 请注意替换示例中的文件名和URL为你的实际值。

相关阅读