tls_handshake.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:ooniprobe-debian 作者: TheTorProject 项目源码 文件源码
def getPeerCert(connection, get_chain=False):
        """Get the PEM-encoded certificate or cert chain of the remote host.

        :param connection: A :class:`OpenSSL.SSL.Connection <Connection>`.
        :param bool get_chain: If True, get the all certificates in the
            chain. Otherwise, only get the remote host's certificate.
        :returns: A PEM-encoded x509 certificate. If
            :param:`getPeerCert.get_chain <get_chain>` is True, returns a list
            of PEM-encoded x509 certificates.
        """
        if not get_chain:
            x509_cert = connection.get_peer_certificate()
            pem_cert = crypto.dump_certificate(crypto.FILETYPE_PEM, x509_cert)
            return pem_cert
        else:
            cert_chain = []
            x509_cert_chain = connection.get_peer_cert_chain()
            for x509_cert in x509_cert_chain:
                pem_cert = crypto.dump_certificate(crypto.FILETYPE_PEM,
                                                   x509_cert)
                cert_chain.append(pem_cert)
            return cert_chain
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号