Example #1
0
    def test_store_key(self):
        secret_key = array.array('B', ('0' * 64).decode('hex')).tolist()
        _key = keymgr_key.SymmetricKey('AES', secret_key)
        key_id = self.key_mgr.store_key(self.ctxt, _key)

        actual_key = self.key_mgr.get_key(self.ctxt, key_id)
        self.assertEqual(_key, actual_key)
Example #2
0
    def get_key(self,
                ctxt,
                key_id,
                payload_content_type='application/octet-stream'):
        """Retrieves the specified key.

        :param ctxt: contains information of the user and the environment for
                     the request (patron/context.py)
        :param key_id: the UUID of the key to retrieve
        :param payload_content_type: The format/type of the secret data

        :return: SymmetricKey representation of the key
        :raises Exception: if key retrieval fails
        """
        try:
            secret = self._get_secret(ctxt, key_id)
            secret_data = self._get_secret_data(secret, payload_content_type)
            if payload_content_type == 'application/octet-stream':
                # convert decoded string to list of unsigned ints for each byte
                key_data = array.array('B',
                                       base64.b64decode(secret_data)).tolist()
            else:
                key_data = secret_data
            key = keymgr_key.SymmetricKey(secret.algorithm, key_data)
            return key
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Error getting key: %s"), e)
Example #3
0
    def copy_key(self, ctxt, key_id):
        """Copies (i.e., clones) a key stored by barbican.

        :param ctxt: contains information of the user and the environment for
                     the request (patron/context.py)
        :param key_id: the UUID of the key to copy
        :return: the UUID of the key copy
        :raises Exception: if key copying fails
        """

        try:
            secret = self._get_secret(ctxt, key_id)
            con_type = secret.content_types['default']
            secret_data = self._get_secret_data(secret,
                                                payload_content_type=con_type)
            key = keymgr_key.SymmetricKey(secret.algorithm, secret_data)
            copy_uuid = self.store_key(ctxt, key, secret.expiration,
                                       secret.name, con_type, 'base64',
                                       secret.algorithm, secret.bit_length,
                                       secret.mode, True)
            return copy_uuid
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(_LE("Error copying key: %s"), e)
Example #4
0
 def _generate_key(self, **kwargs):
     _hex = self._generate_hex_key(**kwargs)
     return key.SymmetricKey('AES',
                             array.array('B', _hex.decode('hex')).tolist())
Example #5
0
    def setUp(self):
        super(SingleKeyManagerTestCase, self).setUp()

        self.key_id = '00000000-0000-0000-0000-000000000000'
        encoded = array.array('B', ('0' * 64).decode('hex')).tolist()
        self.key = key.SymmetricKey('AES', encoded)
Example #6
0
 def _create_key(self):
     return key.SymmetricKey(self.algorithm, self.encoded)
Example #7
0
    def setUp(self):
        super(ConfKeyManagerTestCase, self).setUp()

        encoded_key = array.array('B', self._hex_key.decode('hex')).tolist()
        self.key = key.SymmetricKey('AES', encoded_key)
Example #8
0
def fake__get_key(context):
    raw = array.array('B', ('0' * 64).decode('hex')).tolist()

    symmetric_key = key.SymmetricKey('AES', raw)
    return symmetric_key