如何从证书文件本身 (.p12) 确定 SSL 证书过期日期

How to determine SSL cert expire date from the cert file itself(.p12)

如果我在 Mac 中有实际文件 (.p12) 和 Bash shell,我如何提取证书和密钥文件以及证书到期日期?假设我有 csr(.p12),密钥文件。

提前致谢!

您可以使用 openssl 使用以下命令将证书从 .p12 文件提取到 .pem 文件:

openssl pkcs12 -in certificate.p12 -out certificate.pem -nodes

然后,您可以使用以下命令从 .pem 文件中的证书中提取到期日期:

cat certificate.pem | openssl x509 -noout -enddate

您可以在不使用中间文件的情况下将第一个答案设为一行:

openssl pkcs12 -in certificate.p12 -nodes | openssl x509 -noout -enddate

pkcs12 文件中提取 client 证书并打印其结束日期:

openssl pkcs12 -in certificate.p12 -clcerts -nodes | openssl x509 -noout -enddate

如果您不包括 -clcerts 选项,您可能会从 CA certificate instead of from your own certificate. Several CA certificates are usually included within the file as part of the chain of trust.

中获取结束日期

以下是您在 Windows 上的操作方式:

certutil -dump "file.pfx"

P.S。我知道这个问题特别提到了 Mac,这是为了以防万一 Google 把你送到这里(就像它送给我的一样)。