示例#1
0
    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
示例#2
0
    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
示例#3
0
    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
示例#4
0
    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,))
示例#5
0
 def _checkDupFile(self, path):
     if os.path.isfile(path):
         raise s_common.DupFileName(path=path)