當前位置: 首頁>>代碼示例>>Python>>正文


Python ServerConf.getPublicKey方法代碼示例

本文整理匯總了Python中cpc.util.conf.server_conf.ServerConf.getPublicKey方法的典型用法代碼示例。如果您正苦於以下問題:Python ServerConf.getPublicKey方法的具體用法?Python ServerConf.getPublicKey怎麽用?Python ServerConf.getPublicKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cpc.util.conf.server_conf.ServerConf的用法示例。


在下文中一共展示了ServerConf.getPublicKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: OpenSSL

# 需要導入模塊: from cpc.util.conf.server_conf import ServerConf [as 別名]
# 或者: from cpc.util.conf.server_conf.ServerConf import getPublicKey [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.getPublicKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。