推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
master13
V2EX  ›  Python

如何用 Python 解析 ssl 证书文件?

  •  1
     
  •   master13 · Dec 21, 2016 · 7107 views
    This topic created in 3607 days ago, the information mentioned may be changed or developed.
    现在有一堆 SSL 证书,需要提取其中的 Issuer 、 Subject 等信息吧,就是 windows 下双击这个证书里能看到的颁发者、使用时间啥的。之前用 C#的 System.Security.Cryptography.X509Certificates 包来做的,现在开发环境换 python 了,也没找到比较好用的库。

    求老司机引导一下……
    Supplement 1  ·  Dec 21, 2016
    补充一下, SSL 证书都是离线的,不能再次与远程站点建立连接。
    9 replies  •  2016-12-22 08:22:32 +08:00
    bxb100
    bxb100
    Dec 21, 2016 via Android
    1
    好像自带库里有,没用过,我也不清楚,帮
    vvoody
    vvoody
    Dec 21, 2016
    3
    PyOpenSSL

    OpenSSL.SSL.Connection()
    get_peer_certificate()
    get_peer_cert_chain()
    BOYPT
    BOYPT
    Dec 21, 2016❤️1
    4
    import os
    os.system("openssl x509 -text -noout -in cert.crt")
    est
    est
    Dec 21, 2016
    5
    @BOYPT 我喜欢这个方式。
    jinfeng333
    jinfeng333
    Dec 21, 2016
    6
    @est
    @BOYPT 简单粗暴
    master13
    master13
    OP
    Dec 21, 2016
    7
    @BOYPT 啊这也能叫用 python 来解决……你赢了
    master13
    master13
    OP
    Dec 21, 2016
    8
    @way2exp 感谢。我没有说清楚,证书是离线的,无法再次与服务器建立连接。
    已补充到题目。
    master13
    master13
    OP
    Dec 22, 2016
    9
    好,自问自答一波

    使用 pyOpenSSL:

    OpenSSL.crypto.load_certificate(type, buffer)
    get_subject()
    get_issuer()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1467 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 16:50 · PVG 00:50 · LAX 08:50 · JFK 11:50
    ♥ Do have faith in what you're doing.