如何使用python中的pyopenssl模块将证书链转储到PEM文件中

2024-10-02 04:28:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将完整的证书链转储到PEM文件中。目前,我正在使用pyOpenSSL模块进行尝试,因为ssl模块没有提供获取证书链的方法(只有服务器证书下载可用)

import OpenSSL

def get_cert_chain(address, port=443):
    context = Context(SSLv23_METHOD)
    client = socket()
    client.connect((address, port))
    clientSSL = Connection(context, client)
    clientSSL.set_connect_state()
    clientSSL.do_handshake()
    return clientSSL.get_peer_cert_chain()

#The below certificate_chain variable contains the stack of X509 certificates
certificate_chain = get_cert_chain('www.google.com')

目的:我想导入完整的目标IP链,并通过.pem文件运行keytool导入,以添加到Wildfly truststore中。但是,X509类中没有方法执行像将链转储到.pem文件或类似的操作

为相同的-(调试点)添加了下面的屏幕截图

debug from visual studio codedebug from visual studio code


Tags: 模块文件方法clientchaingetcertport

热门问题