예제 #1
0
    def keygen(keyname, keytype, bits, passphrase):

        """ Generates a private/public keypair and returns it.
        """

        # Initialisations and sanity checks

        retval = {"generation_messages": "", "generation_status": "success"}

        if keytype not in ['rsa', 'dsa']:
            retval["generation_messages"] = _("Invalid keytype: %s" % keytype)
            retval["generation_status"] = "error"

        if bits not in [1024, 2048, 3072, 4096]:
            retval["generation_messages"] = \
                _("Invalid number of bits: %s" % bits)
            retval["generation_status"] = "error"

        if keytype == "dsa" and bits != 1024:
            retval["generation_messages"] = _("DSA only supports 1024 bits.")
            retval["generation_status"] = "error"

        if retval["generation_status"] == "success":

            # Generate private key

            if keytype == "rsa":

                key = RSAKey.generate(bits=bits)
                typestring = "ssh-rss "

            else:

                key = DSSKey.generate(bits=bits)
                typestring = "ssh-dss "

            # Format public key

            keystring = "%s %s %s" % (
                typestring,
                key.get_base64(),
                keyname
            )

            retval["public_key"] = keystring

            tmp = StringIO.StringIO()

            if passphrase == "":
                passphrase = None

            key.write_private_key(tmp, passphrase)

            retval["private_key"] = tmp.getvalue()

        return retval
예제 #2
0
파일: database.py 프로젝트: llou/panopticon
 def testRSAKey(self):
     with self.get_session() as session:
         rpkey = pRSAKey.generate(256)
         rkey = Key.build_from_paramiko_key('rsa', rpkey)
         nrkey = rkey.get_paramiko_key()
         self.assertEqual(rpkey.e, nrkey.e)
         self.assertEqual(rpkey.n, nrkey.n)
         self.assertEqual(nrkey, rpkey)
         dpkey = DSSKey.generate(1024)
         dkey = Key.build_from_paramiko_key('dsa', dpkey)
         self.assertEqual(dpkey, dkey.get_paramiko_key())
         session.add(rkey)
         session.add(dkey)
         session.commit()
         qrkey = session.query(Key).filter(Key.name=='rsa')[0]
         self.assertTrue(isinstance(qrkey,RSAKey))
         pepe = session.query(Computer).filter_by(name='test_computer')[0]
         pepe.key = qrkey
         session.commit()
         pepe = session.query(Computer).filter_by(name='test_computer')[0]
         self.assertEqual(pepe.key.get_paramiko_key(), rpkey)
예제 #3
0
 def test_B_generate_dss(self):
     key = DSSKey.generate(1024)
     msg = key.sign_ssh_data(b"jerri blank")
     msg.rewind()
     self.assertTrue(key.verify_ssh_sig(b"jerri blank", msg))
예제 #4
0
 def test_B_generate_dss(self):
     key = DSSKey.generate(1024)
     msg = key.sign_ssh_data(rng, 'jerri blank')
     msg.rewind()
     self.assert_(key.verify_ssh_sig('jerri blank', msg))
예제 #5
0
 def test_B_generate_dss(self):
     key = DSSKey.generate(1024)
     msg = key.sign_ssh_data(randpool, 'jerri blank')
     msg.rewind()
     self.assert_(key.verify_ssh_sig('jerri blank', msg))
예제 #6
0
 def test_B_generate_dss(self):
     key = DSSKey.generate(1024)
     msg = key.sign_ssh_data(b"jerri blank")
     msg.rewind()
     self.assertTrue(key.verify_ssh_sig(b"jerri blank", msg))