How to download x509 certificate using python

前端 未结 2 1590
情书的邮戳
情书的邮戳 2021-01-22 23:16

I need to download servers certificates as DER file. I am using python. I could connect to the server using this script but I need to download the certificate locally in my hard

2条回答
  •  耶瑟儿~
    2021-01-22 23:33

    You can save the DER file with a couple of intermediate transformations:

    cert = ssl.get_server_certificate((hostname, port))
    x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    der = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, x509)
    with open('/tmp/google.der', 'wb') as f: f.write(der)
    

提交回复
热议问题