mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
fix(drm): send a bridged licence key to the server vault only after its decode check decodes it
This commit is contained in:
@@ -127,6 +127,9 @@ def decrypt(
|
||||
track: Any = "track",
|
||||
flagged: dict | None = None,
|
||||
licence: Any = None,
|
||||
bridged: bool = False,
|
||||
decrypting: bool = True,
|
||||
unnamed: dict | None = None,
|
||||
) -> list:
|
||||
"""Decrypt a track that holds a licence key, a vault key and a null key; return what reached the server vault."""
|
||||
monkeypatch.setattr(key_resolution.binaries, "FFMPEG", ffmpeg)
|
||||
@@ -146,21 +149,34 @@ def decrypt(
|
||||
vaults.flag_bad_key(kid, key)
|
||||
path = tmp_path / "video.mp4"
|
||||
path.write_bytes(b"cipher")
|
||||
content_keys = {LICENSED: KEY, VAULTED: OTHER_KEY, NULL: "0" * 32, **(flagged or {})}
|
||||
drm = SimpleNamespace(content_keys=content_keys, decrypt=lambda path: None)
|
||||
named = {LICENSED: KEY, VAULTED: OTHER_KEY, NULL: "0" * 32, **(flagged or {})}
|
||||
content_keys = {**named, **(unnamed or {})}
|
||||
drm = SimpleNamespace(content_keys=content_keys, kids=list(named), bridged=bridged, decrypt=lambda path: None)
|
||||
try:
|
||||
keys.decrypt_verified(drm, path, licence, LICENSED, track=track)
|
||||
keys.decrypt_verified(drm, path, licence, LICENSED, decrypting, track=track)
|
||||
finally:
|
||||
keys.wait_vault_writes()
|
||||
return pushed
|
||||
|
||||
|
||||
def test_a_passed_decode_sends_the_licence_keys_and_the_checked_vault_keys(tmp_path, monkeypatch) -> None:
|
||||
assert decrypt(tmp_path, monkeypatch, "ffmpeg") == [({LICENSED: KEY, VAULTED: OTHER_KEY}, "track")]
|
||||
@pytest.mark.parametrize("bridged", [False, True], ids=["licence", "bridged-licence"])
|
||||
def test_a_passed_decode_sends_the_licence_keys_and_the_checked_vault_keys(tmp_path, monkeypatch, bridged) -> None:
|
||||
pushed = decrypt(tmp_path, monkeypatch, "ffmpeg", bridged=bridged)
|
||||
assert pushed == [({LICENSED: KEY, VAULTED: OTHER_KEY}, "track")]
|
||||
|
||||
|
||||
def test_without_ffmpeg_a_vault_key_is_not_sent(tmp_path, monkeypatch) -> None:
|
||||
assert decrypt(tmp_path, monkeypatch, None) == [({LICENSED: KEY}, "track")]
|
||||
@pytest.mark.parametrize("decrypting", [True, False], ids=["decrypt", "decrypted-in-place"])
|
||||
@pytest.mark.parametrize("bridged", [False, True], ids=["licence", "bridged-licence"])
|
||||
def test_without_ffmpeg_no_vault_key_and_no_bridged_licence_key_is_sent(
|
||||
tmp_path, monkeypatch, bridged, decrypting
|
||||
) -> None:
|
||||
pushed = decrypt(tmp_path, monkeypatch, None, bridged=bridged, decrypting=decrypting)
|
||||
assert pushed == ([] if bridged else [({LICENSED: KEY}, "track")])
|
||||
|
||||
|
||||
def test_a_bridged_licence_key_the_check_did_not_decode_is_not_sent(tmp_path, monkeypatch) -> None:
|
||||
pushed = decrypt(tmp_path, monkeypatch, "ffmpeg", bridged=True, unnamed={UNNAMED: KEY})
|
||||
assert pushed == [({LICENSED: KEY, VAULTED: OTHER_KEY}, "track")]
|
||||
|
||||
|
||||
def test_a_failed_decode_sends_nothing(tmp_path, monkeypatch) -> None:
|
||||
|
||||
Reference in New Issue
Block a user