- def get_cert(commonname, sans=[]):
- #如果是二级域名并且域名长度大于4,则生成的文件前加.
- if commonname.count('.') >= 2 and len(commonname.split('.')[-2]) > 4:
- commonname = '.'+commonname.partition('.')[-1]
- certfile = os.path.join(CertUtil.ca_certdir, commonname + '.crt')
- if os.path.exists(certfile):
- return certfile
- elif OpenSSL is None:
- return CertUtil.ca_keyfile
- else:
- #如果证书不存在则创建
- with CertUtil.ca_lock:
- if os.path.exists(certfile):
- return certfile
- return CertUtil._get_cert(commonname, sans)
- @staticmethod
- #该片段来自于http://www.codesnippet.cn/detail/101220137886.html
来源: http://www.codesnippet.cn/detail/101220137886.html