Ejemplo n.º 1
0
 def test_get_keys_bad_passphrase(self):
     """
     Ensures that an invalid passphrase results in a ValueError.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     with self.assertRaises(ValueError):
         get_keys('incorrect_passphrase', out_priv, out_pub)
Ejemplo n.º 2
0
 def test_get_keys_bad_passphrase(self):
     """
     Ensures that an invalid passphrase results in a ValueError.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     with self.assertRaises(ValueError):
         get_keys('incorrect_passphrase', out_priv, out_pub)
Ejemplo n.º 3
0
 def test_get_keys_good_keys(self):
     """
     Ensures that good keys are recovered from the default locations in
     the filesystem. The keys are byte representations of pkcs1.
     """
     tmp = tempfile.gettempdir()
     passphrase = 'foobarbaz'
     with mock.patch('drogulus.commands.utils.data_dir', return_value=tmp):
         # create and save something to test
         (pub, priv) = rsa.newkeys(512)
         private_key = priv.save_pkcs1()
         public_key = pub.save_pkcs1()
         out_priv = os.path.join(tmp, '{}.scrypt'.format(APPNAME))
         out_pub = os.path.join(tmp, '{}.pub'.format(APPNAME))
         save_keys(private_key, public_key, passphrase, out_priv, out_pub)
         actual_private, actual_public = get_keys(passphrase)
         self.assertEqual(private_key, actual_private)
         self.assertEqual(public_key, actual_public)
Ejemplo n.º 4
0
 def test_get_keys_good_keys(self):
     """
     Ensures that good keys are recovered from the default locations in
     the filesystem. The keys are byte representations of pkcs1.
     """
     tmp = tempfile.gettempdir()
     passphrase = 'foobarbaz'
     with mock.patch('drogulus.commands.utils.data_dir',
                     return_value=tmp):
         # create and save something to test
         (pub, priv) = rsa.newkeys(512)
         private_key = priv.save_pkcs1()
         public_key = pub.save_pkcs1()
         out_priv = os.path.join(tmp, '{}.scrypt'.format(APPNAME))
         out_pub = os.path.join(tmp, '{}.pub'.format(APPNAME))
         save_keys(private_key, public_key, passphrase, out_priv, out_pub)
         actual_private, actual_public = get_keys(passphrase)
         self.assertEqual(private_key, actual_private)
         self.assertEqual(public_key, actual_public)
Ejemplo n.º 5
0
 def test_get_keys_with_file_paths(self):
     """
     Ensure that the function attempts to read from from passed in file
     paths.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     actual_private, actual_public = get_keys(passphrase, out_priv, out_pub)
     self.assertEqual(private_key, actual_private)
     self.assertEqual(public_key, actual_public)
Ejemplo n.º 6
0
 def test_get_keys_with_file_paths(self):
     """
     Ensure that the function attempts to read from from passed in file
     paths.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     actual_private, actual_public = get_keys(passphrase, out_priv,
                                              out_pub)
     self.assertEqual(private_key, actual_private)
     self.assertEqual(public_key, actual_public)
Ejemplo n.º 7
0
 def test_save_keys(self):
     """
     Ensures that both the public and privte RSA keys are appropriately
     stored on the filesystem in the expected places. Furthermore, the
     private key is saved using the scrypt module that is protected by a
     passphrase.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     actual_private, actual_public = get_keys(passphrase, out_priv, out_pub)
     self.assertEqual(private_key, actual_private)
     self.assertEqual(public_key, actual_public)
Ejemplo n.º 8
0
 def test_save_keys(self):
     """
     Ensures that both the public and privte RSA keys are appropriately
     stored on the filesystem in the expected places. Furthermore, the
     private key is saved using the scrypt module that is protected by a
     passphrase.
     """
     tmp = tempfile.gettempdir()
     filename = str(uuid.uuid4())
     out_priv = os.path.join(tmp, '{}.scrypt'.format(filename))
     out_pub = os.path.join(tmp, '{}.pub'.format(filename))
     passphrase = 'foobarbaz'
     (pub, priv) = rsa.newkeys(512)
     private_key = priv.save_pkcs1()
     public_key = pub.save_pkcs1()
     save_keys(private_key, public_key, passphrase, out_priv, out_pub)
     self.assertTrue(os.path.exists(out_priv))
     self.assertTrue(os.path.exists(out_pub))
     actual_private, actual_public = get_keys(passphrase, out_priv,
                                              out_pub)
     self.assertEqual(private_key, actual_private)
     self.assertEqual(public_key, actual_public)