def _get_raw_key(self, key_id):
        if key_id in self.config.valid_key_ids:
            return WrappingKey(
                wrapping_algorithm=WrappingAlgorithm.
                AES_256_GCM_IV12_TAG16_NO_PADDING,
                wrapping_key=_EDK_MAP[key_id]["wrapping_key"],
                wrapping_key_type=EncryptionKeyType.SYMMETRIC,
            )

        raise InvalidKeyIdError("Unknown key id")
Exemplo n.º 2
0
    def _new_master_key(self, key_id):
        """Returns self as master key instance.

        :param bytes key_id: ID of key to return
        :returns: self
        :raises InvalidKeyIdError: if key_id is not ID for self
        """
        if key_id != self.key_id:
            raise InvalidKeyIdError(
                "MasterKeys can only provide themselves.  Requested {requested} but only {key} is available"
                .format(requested=key_id, key=self.key_id))
        return self
Exemplo n.º 3
0
 def _get_raw_key(self, key_id):
     """"""
     try:
         algorithm, key_bits, padding_algorithm, padding_hash = key_id.upper(
         ).split('.', 3)
         key_bits = int(key_bits)
         key_type = _KEY_TYPES_MAP[algorithm]
         wrapping_algorithm = _WRAPPING_ALGORITHM_MAP[algorithm][key_bits][
             padding_algorithm][padding_hash]
         static_key = _STATIC_KEYS[algorithm][key_bits]
         return WrappingKey(wrapping_algorithm=wrapping_algorithm,
                            wrapping_key=static_key,
                            wrapping_key_type=key_type)
     except KeyError:
         _LOGGER.exception('Unknown Key ID: {}'.format(key_id))
         raise InvalidKeyIdError('Unknown Key ID: {}'.format(key_id))