Harden signed feeds and RelWithDebInfo releases
Modular container CI / release-build (push) Has been cancelled
Modular container CI / release-build (push) Has been cancelled
This commit is contained in:
21 files changed
+243
-40
No files matched your search
@@ -45,6 +45,19 @@ def canonical(document: Any) -> bytes:
|
||||
)
|
||||
|
||||
|
||||
def readable(document: Any) -> bytes:
|
||||
return (
|
||||
json.dumps(
|
||||
document,
|
||||
ensure_ascii=False,
|
||||
allow_nan=False,
|
||||
sort_keys=True,
|
||||
indent=2,
|
||||
).encode("utf-8")
|
||||
+ b"\n"
|
||||
)
|
||||
|
||||
|
||||
def load_object(path: Path, label: str) -> dict[str, Any]:
|
||||
try:
|
||||
document = json.loads(path.read_text(encoding="utf-8"))
|
||||
@@ -154,11 +167,12 @@ class Signer:
|
||||
signature = signature_path.read_bytes()
|
||||
if len(signature) != 64:
|
||||
fail("OpenSSL returned a non-Ed25519 signature")
|
||||
return canonical(
|
||||
return readable(
|
||||
{
|
||||
"schemaVersion": 2,
|
||||
"schemaVersion": 3,
|
||||
"keyId": self.key_id,
|
||||
"payload": base64.urlsafe_b64encode(payload_bytes)
|
||||
"document": payload,
|
||||
"signedPayload": base64.urlsafe_b64encode(payload_bytes)
|
||||
.rstrip(b"=")
|
||||
.decode("ascii"),
|
||||
"signature": base64.urlsafe_b64encode(signature)
|
||||
@@ -170,8 +184,19 @@ class Signer:
|
||||
def verify(self, envelope_bytes: bytes, label: str) -> dict[str, Any]:
|
||||
try:
|
||||
envelope = json.loads(envelope_bytes)
|
||||
schema = envelope.get("schemaVersion")
|
||||
if schema == 2:
|
||||
encoded_payload = envelope["payload"]
|
||||
displayed_document = None
|
||||
elif schema == 3:
|
||||
encoded_payload = envelope["signedPayload"]
|
||||
displayed_document = envelope["document"]
|
||||
if not isinstance(displayed_document, dict):
|
||||
raise TypeError("document is not an object")
|
||||
else:
|
||||
raise ValueError("unsupported envelope schema")
|
||||
payload = base64.urlsafe_b64decode(
|
||||
str(envelope["payload"]) + "=" * (-len(envelope["payload"]) % 4)
|
||||
str(encoded_payload) + "=" * (-len(encoded_payload) % 4)
|
||||
)
|
||||
signature = base64.urlsafe_b64decode(
|
||||
str(envelope["signature"])
|
||||
@@ -180,11 +205,12 @@ class Signer:
|
||||
except (KeyError, ValueError, TypeError, json.JSONDecodeError) as error:
|
||||
fail(f"invalid existing {label}: {error}")
|
||||
if (
|
||||
envelope.get("schemaVersion") != 2
|
||||
or envelope.get("keyId") != self.key_id
|
||||
envelope.get("keyId") != self.key_id
|
||||
or len(signature) != 64
|
||||
):
|
||||
fail(f"existing {label} has the wrong schema, key, or signature")
|
||||
if displayed_document is not None and canonical(displayed_document) != payload:
|
||||
fail(f"existing {label} readable document differs from signed payload")
|
||||
payload_path = self.directory / "verify-payload.json"
|
||||
signature_path = self.directory / "verify-signature.bin"
|
||||
payload_path.write_bytes(payload)
|
||||
@@ -335,6 +361,7 @@ def load_packages(
|
||||
],
|
||||
"platform": "linux",
|
||||
"architecture": "x86_64",
|
||||
"buildType": "RelWithDebInfo",
|
||||
}
|
||||
for field, value in expected.items():
|
||||
if manifest.get(field) != value:
|
||||
@@ -520,6 +547,7 @@ def main() -> None:
|
||||
"activation": definition["activation"],
|
||||
"platform": manifest["platform"],
|
||||
"architecture": manifest["architecture"],
|
||||
"buildType": manifest["buildType"],
|
||||
"toolchainContract": manifest["toolchainContract"],
|
||||
"dependencies": definition["dependencies"],
|
||||
"artifact": artifact,
|
||||
@@ -541,6 +569,7 @@ def main() -> None:
|
||||
"activation",
|
||||
"platform",
|
||||
"architecture",
|
||||
"buildType",
|
||||
"toolchainContract",
|
||||
"dependencies",
|
||||
"artifact",
|
||||
|
||||
Reference in new issue
Block a user