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

2017-01-19 12:32:15 +08:00
 noobsheldon
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
1742 次点击
所在节点    Python
3 条回复
sylecn
2017-01-19 14:07:19 +08:00
你理解有问题吧。证书里面 cn 字段和中国没有半毛钱关系。网站用的证书 cn 需要设置为域名或者泛域名。

这里测试证书直接把 cn 字段默认值设置成*,作者希望不会有人去信任它。仅此而已。
wwqgtxx
2017-01-19 14:10:56 +08:00
CN (Common Name)
不要自己臆想
noobsheldon
2017-01-19 14:37:47 +08:00
@wwqgtxx
@sylecn 受教了!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/335578

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX