这是一个创建于 2818 天前的主题,其中的信息可能已经有所发展或是发生改变。
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
|
|
1
sylecn 2017-01-19 14:07:19 +08:00 via Android
你理解有问题吧。证书里面 cn 字段和中国没有半毛钱关系。网站用的证书 cn 需要设置为域名或者泛域名。
这里测试证书直接把 cn 字段默认值设置成*,作者希望不会有人去信任它。仅此而已。
|
|
|
2
wwqgtxx 2017-01-19 14:10:56 +08:00
CN (Common Name) 不要自己臆想
|