推荐学习书目
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 · 6822 views
    This topic created in 3474 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
        1
    bxb100  
       Dec 21, 2016 via Android
    好像自带库里有,没用过,我也不清楚,帮
    vvoody
        3
    vvoody  
       Dec 21, 2016
    PyOpenSSL

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

    使用 pyOpenSSL:

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