本文整理汇总了Python中cpc.util.conf.server_conf.ServerConf.getCADir方法的典型用法代码示例。如果您正苦于以下问题:Python ServerConf.getCADir方法的具体用法?Python ServerConf.getCADir怎么用?Python ServerConf.getCADir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cpc.util.conf.server_conf.ServerConf
的用法示例。
在下文中一共展示了ServerConf.getCADir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OpenSSL
# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getCADir [as 别名]
#.........这里部分代码省略.........
"-out", certFile,
"-outform", "PEM"]
subprocess.call(args)
def _generateRootCert(self):
'''
generates a root certificate. This is required to sign new certificates
'''
args = ["openssl", "req", "-outform", "PEM", "-config", \
self.conf.getCaConfigFile(), "-new", "-key", \
self.conf.getCAPrivateKey(), "-out", \
self.conf.getCertRequestFile()]
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if p.returncode == 1:
raise SetupError(
"An error occured while generating a root certificate request\n openssl returned the following error:\n" % stderr)
args = ["openssl", "x509", "-req", "-days", "365", "-in", \
self.conf.getCertRequestFile(), "-signkey", \
self.conf.getCAPrivateKey(), "-out", self.conf.getCACertFile()]
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if p.returncode == 1:
raise SetupError(
"An error occured while generating a root certificate \n openssl returned the following error:\n" % stderr)
#cleanup
os.remove(self.conf.getCertRequestFile())
def _generateCaConf(self):
template = Template(self.conf.getCaConfTemplate())
conf = template.safe_substitute(COMMON_NAME=self.cn,
CA_DIR=self.conf.getCADir())
confFile = open(self.conf.getCaConfigFile(), 'w')
confFile.write(conf)
confFile.close()
def _generateCertReqConf(self, distinguished_cn, certReqConfigFile=None):
if certReqConfigFile == None:
certReqConfigFile = self.conf.getCertReqConfigFile()
template = self.conf.getCertReqConfigTemplate()
conf = re.sub("COMMON_NAME",
"%s_%d" % (distinguished_cn, int(time.time())), template)
confFile = open(certReqConfigFile, 'w')
confFile.write(conf)
confFile.close()
def _generateKeyPair(self, privKeyFile=None, pubKeyFile=None):
if privKeyFile == None:
privKeyFile = self.conf.getPrivateKey()
if pubKeyFile == None:
pubKeyFile = self.conf.getPublicKey()
if (not os.path.isfile(privKeyFile)):
args = ["openssl", "genrsa", "-out", privKeyFile, "2048"]
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if p.returncode == 1:
raise SetupError(
"An error occured while generating a private key \n openssl returned the following error:\n" % stderr)
if (not os.path.isfile(pubKeyFile)):
args = ["openssl", "rsa", "-in", privKeyFile, "-pubout", \
"-out", pubKeyFile]
p = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
if p.returncode == 1:
raise SetupError(
"An error occured while generating a public key\n openssl returned the following error:\n" % stderr)
def _createDefaultLogConfig(self):
file = open(LogConf.getLogConfFile(),"w")
file.write(LogConf.getDefaultConfigString())
file.close()
#@input String certfile
def addCa(self, certfile):
file = open(self.conf.getCaChainFile(), "a")
file.write(certfile)
file.close()