• <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 证书

        How to download x509 certificate using python(如何使用 python 下载 x509 证书)
        • <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 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  <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>

                    • <tfoot id='f7KHQ'></tfoot>

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

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