Example #1
0
 def test_load_public_key_success(self):
     ''' load_public_key should succeed and return the public key '''
     random_string = ''.join(
         random.SystemRandom().choice(string.ascii_uppercase +
                                      string.digits) for _ in range(10))
     privkey_file = os.path.join('/tmp/', random_string + '.priv')
     pubkey_file = os.path.join('/tmp/', random_string + '.pub')
     privkey = crypto.generate_rsa_key()
     pubkey_generated = privkey.public_key()
     crypto.store_keys(privkey=privkey,
                       privkey_file=privkey_file,
                       pubkey_file=pubkey_file)
     pubkey_loaded = crypto.load_public_key(pubkey_file)
     os.remove(privkey_file)
     os.remove(pubkey_file)
     self.assertIsNotNone(pubkey_loaded)
     self.assertEqual(crypto.serialize_public_key(pubkey_generated),
                      crypto.serialize_public_key(pubkey_loaded))
Example #2
0
 def privkey(self, value):
     try:
         validation.validate_privkey(value)
         getattr(self, '_privkey')
         raise exceptions.BadParametersException(
             'private key modification not allowed')
     except AttributeError:
         self._privkey = value
         self._pubkey = value.public_key()
         self._serialized_pubkey = crypto.serialize_public_key(self._pubkey)
         self._printable_pubkey = crypto.get_printable_pubkey(self._pubkey)
     except TypeError:
         raise exceptions.BadParametersException('Invalid private key')
Example #3
0
 def test_serialize_public_key_success(self):
     ''' serialize_public_key should succeed if we pass a valid public key '''
     privkey = crypto.generate_rsa_key()
     pubkey = privkey.public_key()
     self.assertIsNotNone(crypto.serialize_public_key(pubkey))
Example #4
0
 def test_serialize_public_key_failure_private_key_passed(self):
     ''' serialize_public_key should fail if key parameter is not the public key but the private one '''
     privkey = crypto.generate_rsa_key()
     with self.assertRaises(AttributeError) as cm:
         crypto.serialize_public_key(privkey)
Example #5
0
 def test_serialize_public_key_failure_invalid_key(self):
     ''' serialize_public_key should fail if key parameter is not a valid public key '''
     key = 'invalid_key'
     with self.assertRaises(AttributeError) as cm:
         crypto.serialize_public_key(key)