推荐学习书目
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
noobsheldon
V2EX  ›  Python

werkzeug 中 serving 中的一段代码,注释好像有亮点。。。。

  •  
  •   noobsheldon · Jan 19, 2017 via Android · 2259 views
    This topic created in 3425 days ago, the information mentioned may be changed or developed.
    def generate_adhoc_ssl_pair(cn=None):
    from random import random
    crypto = _get_openssl_crypto_module()

    # pretty damn sure that this is not actually accepted by anyone
    if cn is None:
    cn = '*'

    cert = crypto.X509()
    cert.set_serial_number(int(random() * sys.maxsize))
    cert.gmtime_adj_notBefore(0)
    cert.gmtime_adj_notAfter(60 * 60 * 24 * 365)

    subject = cert.get_subject()
    subject.CN = cn
    subject.O = 'Dummy Certificate'

    issuer = cert.get_issuer()
    issuer.CN = 'Untrusted Authority'
    issuer.O = 'Self-Signed'

    pkey = crypto.PKey()
    pkey.generate_key(crypto.TYPE_RSA, 2048)
    cert.set_pubkey(pkey)
    cert.sign(pkey, 'sha256')

    return cert, pkey
    3 replies    2017-01-19 14:37:47 +08:00
    sylecn
        1
    sylecn  
       Jan 19, 2017 via Android
    你理解有问题吧。证书里面 cn 字段和中国没有半毛钱关系。网站用的证书 cn 需要设置为域名或者泛域名。

    这里测试证书直接把 cn 字段默认值设置成*,作者希望不会有人去信任它。仅此而已。
    wwqgtxx
        2
    wwqgtxx  
       Jan 19, 2017
    CN (Common Name)
    不要自己臆想
    noobsheldon
        3
    noobsheldon  
    OP
       Jan 19, 2017 via Android
    @wwqgtxx
    @sylecn 受教了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2872 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 14:02 · PVG 22:02 · LAX 07:02 · JFK 10:02
    ♥ Do have faith in what you're doing.