|
@@ -11,7 +11,7 @@ from ..crypto.key import AEADKeyBase
|
|
|
from ..crypto.key import AESOCBRepoKey, AESOCBKeyfileKey, CHPORepoKey, CHPOKeyfileKey
|
|
|
from ..crypto.key import Blake2AESOCBRepoKey, Blake2AESOCBKeyfileKey, Blake2CHPORepoKey, Blake2CHPOKeyfileKey
|
|
|
from ..crypto.key import ID_HMAC_SHA_256, ID_BLAKE2b_256
|
|
|
-from ..crypto.key import TAMRequiredError, TAMInvalid, TAMUnsupportedSuiteError, ArchiveTAMInvalid
|
|
|
+from ..crypto.key import TAMRequiredError, TAMInvalid, TAMUnsupportedSuiteError
|
|
|
from ..crypto.key import UnsupportedManifestError, UnsupportedKeyFormatError
|
|
|
from ..crypto.key import identify_key
|
|
|
from ..crypto.low_level import IntegrityError as IntegrityErrorBase
|
|
@@ -276,15 +276,11 @@ class TestTAM:
|
|
|
blob = msgpack.packb({})
|
|
|
with pytest.raises(TAMRequiredError):
|
|
|
key.unpack_and_verify_manifest(blob)
|
|
|
- with pytest.raises(TAMRequiredError):
|
|
|
- key.unpack_and_verify_archive(blob)
|
|
|
|
|
|
def test_unknown_type(self, key):
|
|
|
blob = msgpack.packb({"tam": {"type": "HMAC_VOLLBIT"}})
|
|
|
with pytest.raises(TAMUnsupportedSuiteError):
|
|
|
key.unpack_and_verify_manifest(blob)
|
|
|
- with pytest.raises(TAMUnsupportedSuiteError):
|
|
|
- key.unpack_and_verify_archive(blob)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
"tam, exc",
|
|
@@ -300,20 +296,6 @@ class TestTAM:
|
|
|
with pytest.raises(exc):
|
|
|
key.unpack_and_verify_manifest(blob)
|
|
|
|
|
|
- @pytest.mark.parametrize(
|
|
|
- "tam, exc",
|
|
|
- (
|
|
|
- ({}, TAMUnsupportedSuiteError),
|
|
|
- ({"type": b"\xff"}, TAMUnsupportedSuiteError),
|
|
|
- (None, ArchiveTAMInvalid),
|
|
|
- (1234, ArchiveTAMInvalid),
|
|
|
- ),
|
|
|
- )
|
|
|
- def test_invalid_archive(self, key, tam, exc):
|
|
|
- blob = msgpack.packb({"tam": tam})
|
|
|
- with pytest.raises(exc):
|
|
|
- key.unpack_and_verify_archive(blob)
|
|
|
-
|
|
|
@pytest.mark.parametrize(
|
|
|
"hmac, salt",
|
|
|
(({}, bytes(64)), (bytes(64), {}), (None, bytes(64)), (bytes(64), None)),
|
|
@@ -329,8 +311,6 @@ class TestTAM:
|
|
|
blob = msgpack.packb(data)
|
|
|
with pytest.raises(TAMInvalid):
|
|
|
key.unpack_and_verify_manifest(blob)
|
|
|
- with pytest.raises(ArchiveTAMInvalid):
|
|
|
- key.unpack_and_verify_archive(blob)
|
|
|
|
|
|
def test_round_trip_manifest(self, key):
|
|
|
data = {"foo": "bar"}
|
|
@@ -346,15 +326,10 @@ class TestTAM:
|
|
|
|
|
|
def test_round_trip_archive(self, key):
|
|
|
data = {"foo": "bar"}
|
|
|
- blob = key.pack_and_authenticate_metadata(data, context=b"archive")
|
|
|
- assert blob.startswith(b"\x82")
|
|
|
-
|
|
|
- unpacked = msgpack.unpackb(blob)
|
|
|
- assert unpacked["tam"]["type"] == "HKDF_HMAC_SHA512"
|
|
|
-
|
|
|
- unpacked, _ = key.unpack_and_verify_archive(blob)
|
|
|
+ blob = key.pack_metadata(data)
|
|
|
+ unpacked = key.unpack_archive(blob)
|
|
|
assert unpacked["foo"] == "bar"
|
|
|
- assert "tam" not in unpacked
|
|
|
+ assert "tam" not in unpacked # legacy
|
|
|
|
|
|
@pytest.mark.parametrize("which", ("hmac", "salt"))
|
|
|
def test_tampered_manifest(self, key, which):
|
|
@@ -371,21 +346,6 @@ class TestTAM:
|
|
|
with pytest.raises(TAMInvalid):
|
|
|
key.unpack_and_verify_manifest(blob)
|
|
|
|
|
|
- @pytest.mark.parametrize("which", ("hmac", "salt"))
|
|
|
- def test_tampered_archive(self, key, which):
|
|
|
- data = {"foo": "bar"}
|
|
|
- blob = key.pack_and_authenticate_metadata(data, context=b"archive")
|
|
|
- assert blob.startswith(b"\x82")
|
|
|
-
|
|
|
- unpacked = msgpack.unpackb(blob, object_hook=StableDict)
|
|
|
- assert len(unpacked["tam"][which]) == 64
|
|
|
- unpacked["tam"][which] = unpacked["tam"][which][0:32] + bytes(32)
|
|
|
- assert len(unpacked["tam"][which]) == 64
|
|
|
- blob = msgpack.packb(unpacked)
|
|
|
-
|
|
|
- with pytest.raises(ArchiveTAMInvalid):
|
|
|
- key.unpack_and_verify_archive(blob)
|
|
|
-
|
|
|
|
|
|
def test_decrypt_key_file_unsupported_algorithm():
|
|
|
"""We will add more algorithms in the future. We should raise a helpful error."""
|