首页 > 解决方案 > 如何在 python 中使用 pyopenssl 模块将证书链转储到 PEM 文件中

问题描述

我想将完整的证书链转储到 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 信任库。但是,X509 类中没有方法可以执行诸如将链转储到 .pem 文件之类的操作以及类似的操作。

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

从 Visual Studio 代码 调试 从 Visual Studio 代码调试

标签: pythonopensslpyopenssl

解决方案


推荐阅读