当前位置: 首页>>代码示例>>Python>>正文


Python ServerConf.getCaConfTemplate方法代码示例

本文整理汇总了Python中cpc.util.conf.server_conf.ServerConf.getCaConfTemplate方法的典型用法代码示例。如果您正苦于以下问题:Python ServerConf.getCaConfTemplate方法的具体用法?Python ServerConf.getCaConfTemplate怎么用?Python ServerConf.getCaConfTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cpc.util.conf.server_conf.ServerConf的用法示例。


在下文中一共展示了ServerConf.getCaConfTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OpenSSL

# 需要导入模块: from cpc.util.conf.server_conf import ServerConf [as 别名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getCaConfTemplate [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()
开发者ID:abhirathb,项目名称:copernicus,代码行数:104,代码来源:openssl.py


注:本文中的cpc.util.conf.server_conf.ServerConf.getCaConfTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。