forked from kenzuya/unshackle
feat(vaults): report bad keys to the vault that served them
This commit is contained in:
@@ -4369,9 +4369,17 @@ async def session_bad_key_handler(
|
||||
raise APIError(APIErrorCode.INVALID_INPUT, "This session was not served that KID:KEY pair")
|
||||
|
||||
vaults = load_server_vaults(session.service_instance.__class__.__name__)
|
||||
for vault in vaults.vaults:
|
||||
if vault.local:
|
||||
vault.flag_bad_key(vaults.service, UUID(hex=kid), served_key, source)
|
||||
|
||||
def flag() -> None:
|
||||
for vault in vaults.vaults:
|
||||
if not vault.local and vault.name != source:
|
||||
continue
|
||||
try:
|
||||
vault.flag_bad_key(vaults.service, UUID(hex=kid), served_key, source)
|
||||
except Exception as e:
|
||||
log.debug(f"Could not flag {kid} as bad in vault {sanitize_log(vault.name)}: {e!r}")
|
||||
|
||||
await asyncio.to_thread(flag)
|
||||
session.served_keys.pop(kid, None)
|
||||
log.warning(
|
||||
f"Client proved {kid}:{served_key} from vault {sanitize_log(source)} wrong, flagged in the server vaults"
|
||||
|
||||
@@ -1856,9 +1856,9 @@ async def session_bad_key(request: web.Request) -> web.Response:
|
||||
summary: Report a bad content key
|
||||
description: >-
|
||||
The client decrypted with a content key the server took from its vault and the output did
|
||||
not decode. The server flags the pair in its local vaults, so the next licence for that KID
|
||||
reaches the CDM when a local vault stores the flag. The server accepts only a pair it served
|
||||
to this remote session.
|
||||
not decode. The server flags the pair in its local vaults and reports it to the vault that
|
||||
served it, so the next licence for that KID reaches the CDM. The server accepts only a pair
|
||||
it served to this remote session.
|
||||
parameters:
|
||||
- name: session_id
|
||||
in: path
|
||||
|
||||
@@ -148,19 +148,31 @@ class Vaults:
|
||||
return key if found else None
|
||||
|
||||
def flag_bad_key(self, kid: Union[UUID, str], key: str) -> None:
|
||||
"""Flag a KID:KEY that failed decryption in every local Vault, naming the Vault it came from."""
|
||||
"""Flag a KID:KEY that failed decryption, naming the Vault it came from.
|
||||
|
||||
Every local vault records it. A remote vault is told only when it served the pair,
|
||||
so it stops serving it too, and a vault that never held it is not bothered. A vault
|
||||
that cannot take the flag is skipped with a debug line: the local flag already
|
||||
protects this run, and a vault without the route is not a fault.
|
||||
"""
|
||||
self.flagged.add((kid, key))
|
||||
source = self.sources.pop(kid, None)
|
||||
for vault in self.vaults:
|
||||
if vault.local:
|
||||
if not vault.local and (source is None or vault is not source[1]):
|
||||
continue
|
||||
try:
|
||||
vault.flag_bad_key(self.service, kid, key, source[1].name if source else "unknown")
|
||||
except Exception as e:
|
||||
log.debug(f"Could not flag {key} as bad in Vault '{vault.name}': {e!r}")
|
||||
|
||||
def unflag_bad_key(self, kid: Union[UUID, str], key: str) -> None:
|
||||
"""Remove a flag from every local Vault."""
|
||||
"""Remove a flag from every Vault."""
|
||||
self.flagged.discard((kid, key))
|
||||
for vault in self.vaults:
|
||||
if vault.local:
|
||||
try:
|
||||
vault.unflag_bad_key(kid, key)
|
||||
except Exception as e:
|
||||
log.debug(f"Could not unflag {key} in Vault '{vault.name}': {e!r}")
|
||||
|
||||
def add_key(self, kid: Union[UUID, str], key: str, excluding: Optional[Vault] = None) -> int:
|
||||
"""Add a KID:KEY to all Vaults, optionally with an exclusion.
|
||||
|
||||
Reference in New Issue
Block a user