【发布时间】:2021-02-19 01:35:45
【问题描述】:
我正在尝试编写一个 Python3 程序,它将向我显示公钥证书中包含的所有信息,类似于以下 linux 命令:
openssl x509 -in website.com.pem -text
这将返回类似于
的结果Certificate:
Data:
Version: 3 (0x2)
Serial Number:
04:7a:f7:95:47:c0:7d:0f:ef:80:a5:b2:1f:51:e3:63
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Domain Validation Secure Server CA
Validity
Not Before: Mar 12 00:00:00 2018 GMT
Not After : Mar 11 23:59:59 2020 GMT
Subject: OU = Domain Control Validated, OU = PositiveSSL, CN = acs.cdroutertest.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
如以下网站所示:https://support.qacafe.com/knowledge-base/how-do-i-display-the-contents-of-a-ssl-certificate/
我已经在 python3 中尝试了 Cryptography 或 pyopenssl 模块,并且能够导入证书并显示例如公钥。但是我没有找到一种方法来浏览所有可用信息并仅显示它们,而不必为证书中可能或可能不可用的每个字段编写 print() 语句。
有人知道如何将我推向正确的方向吗?
感谢,谢谢!
【问题讨论】:
-
...无需为每个字段编写 print() 语句... 嗯,这正是您必须做的。或者你可以使用
subprocess.run()在python中运行你的openssl命令。
标签: python-3.x certificate x509certificate public-key pem