正在尝试提取 Python 中的证书信息

Trying to extract Certificate information in Python

我是 python 的新手,似乎不知道如何完成这项任务。我想连接到一个网站并提取证书信息,例如颁发者和到期日期。

我已经查看了所有地方,尝试了各种步骤,但因为我是新手,所以我迷失在套接字、包装器等方面。

更糟糕的是,我处于代理环境中,这似乎让事情变得很复杂。

有谁知道我如何在代理后面连接和提取信息?

this 中所述 答案:

You can still the server certificate with the ssl.get_server_certificate() function, but it returns it in PEM format.

import ssl
print ssl.get_server_certificate(('server.test.com', 443))

From here, I would use M2Crypto or OpenSSL to read the cert and get values:

# M2Crypto
cert = ssl.get_server_certificate(('www.google.com', 443))
x509 = M2Crypto.X509.load_cert_string(cert)
x509.get_subject().as_text()
 # 'C=US, ST=California, L=Mountain View, O=Google Inc, CN=www.google.com'

Python SSL 库不处理代理。