def initializeCryptoEngine(self): if(self.platform == PlatformUtils.LINUX): LOG.debug("Loading certificates...") try: pfx = crypto.load_pkcs12(file(os.path.join(self.pfxFile), 'rb').read(), self.pfxPasswd) self.loadCAFromPFX(pfx) self.clientCert = pfx.get_certificate() self.clientKey = pfx.get_privatekey() serverCert = crypto.load_certificate(crypto.FILETYPE_ASN1, file(self.serverCertFile, 'rb').read()) serverPubKey = serverCert.get_pubkey() serializedClientPrivKey = crypto.dump_privatekey(crypto.FILETYPE_PEM, self.clientKey) serializedServerPubKey = crypto.dump_publickey(crypto.FILETYPE_PEM, serverPubKey) return CryptoEngine(serializedClientPrivKey, serializedServerPubKey, certUtil=self) except: LOG.error("Failed to load certificates!") sys.exit("Failed to load certificates!")
def convertPEMtoDER(self, key): return crypto.dump_publickey(crypto.FILETYPE_ASN1, crypto.load_publickey(crypto.FILETYPE_PEM, key))
def convertDERtoPEM(self, key): return crypto.dump_publickey(crypto.FILETYPE_PEM, crypto.load_publickey(crypto.FILETYPE_ASN1, key))