def _savePkeyTo(self, pkey, *paths): path = self.getPathJoin(*paths) if os.path.isfile(path): raise s_common.DupFileName(path=path) with s_common.genfile(path) as fd: fd.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)) return path
def _saveCertTo(self, cert, *paths): path = self.getPathJoin(*paths) if os.path.isfile(path): raise s_common.DupFileName(path=path) with s_common.genfile(path) as fd: fd.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) return path
def _saveP12To(self, cert, *paths): path = self.getPathJoin(*paths) if os.path.isfile(path): raise s_common.DupFileName(path=path) with s_common.genfile(path) as fd: fd.write(cert.export()) return path
def _genPkeyCsr(self, name, mode, outp=None): pkey = crypto.PKey() pkey.generate_key(crypto.TYPE_RSA, self.crypto_numbits) xcsr = crypto.X509Req() xcsr.get_subject().CN = name xcsr.set_pubkey(pkey) xcsr.sign(pkey, 'sha256') keypath = self._savePkeyTo(pkey, mode, '%s.key' % name) if outp is not None: outp.printf('key saved: %s' % (keypath,)) csrpath = self.getPathJoin(mode, '%s.csr' % name) if os.path.isfile(csrpath): raise s_common.DupFileName(path=csrpath) with s_common.genfile(csrpath) as fd: fd.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, xcsr)) if outp is not None: outp.printf('csr saved: %s' % (csrpath,))
def _checkDupFile(self, path): if os.path.isfile(path): raise s_common.DupFileName(path=path)