• <i id='eXsfr'><tr id='eXsfr'><dt id='eXsfr'><q id='eXsfr'><span id='eXsfr'><b id='eXsfr'><form id='eXsfr'><ins id='eXsfr'></ins><ul id='eXsfr'></ul><sub id='eXsfr'></sub></form><legend id='eXsfr'></legend><bdo id='eXsfr'><pre id='eXsfr'><center id='eXsfr'></center></pre></bdo></b><th id='eXsfr'></th></span></q></dt></tr></i><div id='eXsfr'><tfoot id='eXsfr'></tfoot><dl id='eXsfr'><fieldset id='eXsfr'></fieldset></dl></div>

    1. <small id='eXsfr'></small><noframes id='eXsfr'>

    2. <tfoot id='eXsfr'></tfoot>
          <bdo id='eXsfr'></bdo><ul id='eXsfr'></ul>
        <legend id='eXsfr'><style id='eXsfr'><dir id='eXsfr'><q id='eXsfr'></q></dir></style></legend>

        如何使用 python 下载 x509 证书

        时间:2023-11-08
        • <i id='5q2vk'><tr id='5q2vk'><dt id='5q2vk'><q id='5q2vk'><span id='5q2vk'><b id='5q2vk'><form id='5q2vk'><ins id='5q2vk'></ins><ul id='5q2vk'></ul><sub id='5q2vk'></sub></form><legend id='5q2vk'></legend><bdo id='5q2vk'><pre id='5q2vk'><center id='5q2vk'></center></pre></bdo></b><th id='5q2vk'></th></span></q></dt></tr></i><div id='5q2vk'><tfoot id='5q2vk'></tfoot><dl id='5q2vk'><fieldset id='5q2vk'></fieldset></dl></div>
            <bdo id='5q2vk'></bdo><ul id='5q2vk'></ul>

                  <tbody id='5q2vk'></tbody>

                <small id='5q2vk'></small><noframes id='5q2vk'>

                <tfoot id='5q2vk'></tfoot>

              1. <legend id='5q2vk'><style id='5q2vk'><dir id='5q2vk'><q id='5q2vk'></q></dir></style></legend>
                  本文介绍了如何使用 python 下载 x509 证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要将服务器证书下载为 DER 文件.我正在使用python.我可以使用此脚本连接到服务器,但我需要将证书下载到本地硬盘中,以便在下一阶段解析它.

                  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 disk so I can parse it in the next stage.

                  import socket, ssl
                  import OpenSSL
                  
                  hostname='www.google.com'
                  port=443
                  
                  context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
                  
                  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                  ssl_sock = context.wrap_socket(s, server_hostname=hostname)
                  ssl_sock.connect((hostname, port))
                  ssl_sock.close()
                  print("ssl connection Done")
                  
                  cert = ssl.get_server_certificate((hostname, port))
                  
                  # OpenSSL
                  x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
                  

                  推荐答案

                  您可以通过几个中间转换来保存 DER 文件:

                  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)
                  

                  这篇关于如何使用 python 下载 x509 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python AWS Lambda 证书 下一篇:可以“list_display"在 Django ModelAdmin 中显示 ForeignKey 字段的属

                  相关文章

                  <i id='f7KHQ'><tr id='f7KHQ'><dt id='f7KHQ'><q id='f7KHQ'><span id='f7KHQ'><b id='f7KHQ'><form id='f7KHQ'><ins id='f7KHQ'></ins><ul id='f7KHQ'></ul><sub id='f7KHQ'></sub></form><legend id='f7KHQ'></legend><bdo id='f7KHQ'><pre id='f7KHQ'><center id='f7KHQ'></center></pre></bdo></b><th id='f7KHQ'></th></span></q></dt></tr></i><div id='f7KHQ'><tfoot id='f7KHQ'></tfoot><dl id='f7KHQ'><fieldset id='f7KHQ'></fieldset></dl></div>
                  • <bdo id='f7KHQ'></bdo><ul id='f7KHQ'></ul>

                1. <tfoot id='f7KHQ'></tfoot>

                  <legend id='f7KHQ'><style id='f7KHQ'><dir id='f7KHQ'><q id='f7KHQ'></q></dir></style></legend>

                  1. <small id='f7KHQ'></small><noframes id='f7KHQ'>