V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-01-19 12:32:15 +08:00 via Android · 1740 次点击
    这是一个创建于 2655 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2017-01-19 14:37:47 +08:00
    sylecn
        1
    sylecn  
       2017-01-19 14:07:19 +08:00 via Android
    你理解有问题吧。证书里面 cn 字段和中国没有半毛钱关系。网站用的证书 cn 需要设置为域名或者泛域名。

    这里测试证书直接把 cn 字段默认值设置成*,作者希望不会有人去信任它。仅此而已。
    wwqgtxx
        2
    wwqgtxx  
       2017-01-19 14:10:56 +08:00
    CN (Common Name)
    不要自己臆想
    noobsheldon
        3
    noobsheldon  
    OP
       2017-01-19 14:37:47 +08:00 via Android
    @wwqgtxx
    @sylecn 受教了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   931 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:27 · PVG 06:27 · LAX 15:27 · JFK 18:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.