linux

如何用OpenSSL检查证书有效性

小樊
51
2025-04-15 19:36:08
栏目: 云计算

使用OpenSSL检查证书有效性的步骤如下:

1. 检查证书有效期

openssl x509 -in certificate.crt -noout -dates

这个命令会显示证书的有效期,包括开始日期和结束日期。

2. 检查证书是否被吊销

openssl x509 -in certificate.crt -noout -CApath /etc/ssl/certs -CAfile /etc/ssl/certs/ca-certificates.crt -checkend 0

这个命令会检查证书是否在CA证书列表中被吊销。-checkend 0 表示检查证书是否在当前时间点有效。

3. 检查证书的签名算法和密钥长度

openssl x509 -in certificate.crt -noout -text | grep "Signature Algorithm"
openssl x509 -in certificate.crt -noout -text | grep "Public Key"

这些命令会显示证书的签名算法和公钥信息,包括密钥长度。

4. 检查证书的颁发者和主题

openssl x509 -in certificate.crt -noout -subject
openssl x509 -in certificate.crt -noout -issuer

这些命令会显示证书的主题(Subject)和颁发者(Issuer)信息。

5. 检查证书的序列号

openssl x509 -in certificate.crt -noout -serial

这个命令会显示证书的序列号。

6. 检查证书的扩展信息

openssl x509 -in certificate.crt -noout -ext

这个命令会显示证书的所有扩展信息,包括基本约束、密钥用法、主题替代名称等。

7. 检查证书的链完整性

如果你有一个证书链,可以使用以下命令来检查整个链的完整性:

openssl verify -CAfile ca-certificates.crt certificate.crt

这个命令会验证证书是否由指定的CA签发,并且链中的所有证书都是有效的。

注意事项

通过这些步骤,你可以全面检查证书的有效性和安全性。

0
看了该问题的人还看了