tba-runtime-identity-authoring 0.4.0.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tba_runtime_identity_authoring/__init__.py +37 -0
- tba_runtime_identity_authoring/py.typed +0 -0
- tba_runtime_identity_authoring/release_signing/__init__.py +35 -0
- tba_runtime_identity_authoring/release_signing/attestations.py +118 -0
- tba_runtime_identity_authoring/release_signing/keys.py +76 -0
- tba_runtime_identity_authoring/release_signing/models.py +80 -0
- tba_runtime_identity_authoring/release_signing/utils.py +48 -0
- tba_runtime_identity_authoring/release_signing/verification.py +136 -0
- tba_runtime_identity_authoring-0.4.0.dev2.dist-info/METADATA +58 -0
- tba_runtime_identity_authoring-0.4.0.dev2.dist-info/RECORD +11 -0
- tba_runtime_identity_authoring-0.4.0.dev2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Release authoring and provenance helpers for the TBA identity package suite."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .release_signing import (
|
|
6
|
+
DEFAULT_SIGNER_ID,
|
|
7
|
+
LoadedSigner,
|
|
8
|
+
SignerIdentity,
|
|
9
|
+
VerificationResult,
|
|
10
|
+
build_contract_set_manifest,
|
|
11
|
+
load_signer,
|
|
12
|
+
sha256_bytes,
|
|
13
|
+
sha256_file,
|
|
14
|
+
verify_bundle_attestations,
|
|
15
|
+
verify_statement,
|
|
16
|
+
write_artifact_attestation,
|
|
17
|
+
write_attestation,
|
|
18
|
+
write_bundle_attestation,
|
|
19
|
+
write_public_key_artifacts,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"DEFAULT_SIGNER_ID",
|
|
24
|
+
"LoadedSigner",
|
|
25
|
+
"SignerIdentity",
|
|
26
|
+
"VerificationResult",
|
|
27
|
+
"build_contract_set_manifest",
|
|
28
|
+
"load_signer",
|
|
29
|
+
"sha256_bytes",
|
|
30
|
+
"sha256_file",
|
|
31
|
+
"verify_bundle_attestations",
|
|
32
|
+
"verify_statement",
|
|
33
|
+
"write_artifact_attestation",
|
|
34
|
+
"write_attestation",
|
|
35
|
+
"write_bundle_attestation",
|
|
36
|
+
"write_public_key_artifacts",
|
|
37
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .attestations import (
|
|
4
|
+
build_contract_set_manifest,
|
|
5
|
+
write_artifact_attestation,
|
|
6
|
+
write_attestation,
|
|
7
|
+
write_bundle_attestation,
|
|
8
|
+
)
|
|
9
|
+
from .keys import load_signer, write_public_key_artifacts
|
|
10
|
+
from .models import LoadedSigner, SignerIdentity, VerificationResult
|
|
11
|
+
from .utils import (
|
|
12
|
+
DEFAULT_SIGNER_ID,
|
|
13
|
+
_canonical_json,
|
|
14
|
+
sha256_bytes,
|
|
15
|
+
sha256_file,
|
|
16
|
+
sha256_text,
|
|
17
|
+
)
|
|
18
|
+
from .verification import verify_bundle_attestations, verify_statement
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
'DEFAULT_SIGNER_ID',
|
|
22
|
+
'LoadedSigner',
|
|
23
|
+
'SignerIdentity',
|
|
24
|
+
'VerificationResult',
|
|
25
|
+
'build_contract_set_manifest',
|
|
26
|
+
'load_signer',
|
|
27
|
+
'sha256_bytes',
|
|
28
|
+
'sha256_file',
|
|
29
|
+
'verify_bundle_attestations',
|
|
30
|
+
'verify_statement',
|
|
31
|
+
'write_artifact_attestation',
|
|
32
|
+
'write_attestation',
|
|
33
|
+
'write_bundle_attestation',
|
|
34
|
+
'write_public_key_artifacts',
|
|
35
|
+
]
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Iterable
|
|
6
|
+
|
|
7
|
+
from .models import LoadedSigner
|
|
8
|
+
from .utils import STATEMENT_TYPE_ARTIFACT, STATEMENT_TYPE_BUNDLE, STATEMENT_VERSION, sha256_file
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_contract_set_manifest(bundle_root: Path) -> dict[str, Any]:
|
|
12
|
+
entries: list[dict[str, Any]] = []
|
|
13
|
+
for path in sorted((bundle_root / "specs").rglob("*")):
|
|
14
|
+
if not path.is_file():
|
|
15
|
+
continue
|
|
16
|
+
rel = str(path.relative_to(bundle_root)).replace("\\", "/")
|
|
17
|
+
entries.append({
|
|
18
|
+
"path": rel,
|
|
19
|
+
"sha256": sha256_file(path),
|
|
20
|
+
"bytes": path.stat().st_size,
|
|
21
|
+
})
|
|
22
|
+
return {
|
|
23
|
+
"schema_version": STATEMENT_VERSION,
|
|
24
|
+
"kind": "contract-set",
|
|
25
|
+
"contract_count": len(entries),
|
|
26
|
+
"contracts": entries,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _write_json(path: Path, payload: Any) -> None:
|
|
31
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
32
|
+
path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def write_attestation(path: Path, attestation: dict[str, Any]) -> None:
|
|
36
|
+
_write_json(path, attestation)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _artifact_subject(
|
|
40
|
+
*,
|
|
41
|
+
label: str,
|
|
42
|
+
artifact_path: str,
|
|
43
|
+
artifact_sha256: str,
|
|
44
|
+
package: str,
|
|
45
|
+
version: str,
|
|
46
|
+
profile: str,
|
|
47
|
+
artifact_kind: str,
|
|
48
|
+
media_type: str,
|
|
49
|
+
) -> dict[str, Any]:
|
|
50
|
+
return {
|
|
51
|
+
"package": package,
|
|
52
|
+
"version": version,
|
|
53
|
+
"profile": profile,
|
|
54
|
+
"artifact_label": label,
|
|
55
|
+
"artifact_kind": artifact_kind,
|
|
56
|
+
"artifact_path": artifact_path,
|
|
57
|
+
"artifact_sha256": artifact_sha256,
|
|
58
|
+
"media_type": media_type,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def write_artifact_attestation(
|
|
63
|
+
bundle_root: Path,
|
|
64
|
+
*,
|
|
65
|
+
signer: LoadedSigner,
|
|
66
|
+
label: str,
|
|
67
|
+
artifact_rel_path: str,
|
|
68
|
+
package: str,
|
|
69
|
+
version: str,
|
|
70
|
+
profile: str,
|
|
71
|
+
artifact_kind: str,
|
|
72
|
+
media_type: str,
|
|
73
|
+
) -> dict[str, Any]:
|
|
74
|
+
artifact_path = bundle_root / artifact_rel_path
|
|
75
|
+
subject = _artifact_subject(
|
|
76
|
+
label=label,
|
|
77
|
+
artifact_path=artifact_rel_path,
|
|
78
|
+
artifact_sha256=sha256_file(artifact_path),
|
|
79
|
+
package=package,
|
|
80
|
+
version=version,
|
|
81
|
+
profile=profile,
|
|
82
|
+
artifact_kind=artifact_kind,
|
|
83
|
+
media_type=media_type,
|
|
84
|
+
)
|
|
85
|
+
statement = signer.sign_statement(STATEMENT_TYPE_ARTIFACT, subject)
|
|
86
|
+
attestation_path = bundle_root / "attestations" / f"{label}.attestation.json"
|
|
87
|
+
write_attestation(attestation_path, statement)
|
|
88
|
+
return {
|
|
89
|
+
"label": label,
|
|
90
|
+
"artifact_path": artifact_rel_path,
|
|
91
|
+
"artifact_sha256": subject["artifact_sha256"],
|
|
92
|
+
"attestation_path": str(attestation_path.relative_to(bundle_root)).replace("\\", "/"),
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def write_bundle_attestation(
|
|
97
|
+
bundle_root: Path,
|
|
98
|
+
*,
|
|
99
|
+
signer: LoadedSigner,
|
|
100
|
+
package: str,
|
|
101
|
+
version: str,
|
|
102
|
+
profile: str,
|
|
103
|
+
signed_artifacts: Iterable[dict[str, Any]],
|
|
104
|
+
) -> dict[str, Any]:
|
|
105
|
+
subject = {
|
|
106
|
+
"package": package,
|
|
107
|
+
"version": version,
|
|
108
|
+
"profile": profile,
|
|
109
|
+
"bundle_root": str(bundle_root.name),
|
|
110
|
+
"signed_artifacts": list(signed_artifacts),
|
|
111
|
+
}
|
|
112
|
+
statement = signer.sign_statement(STATEMENT_TYPE_BUNDLE, subject)
|
|
113
|
+
attestation_path = bundle_root / "attestations" / "release-attestation.json"
|
|
114
|
+
write_attestation(attestation_path, statement)
|
|
115
|
+
return {
|
|
116
|
+
"attestation_path": str(attestation_path.relative_to(bundle_root)).replace("\\", "/"),
|
|
117
|
+
"statement": statement,
|
|
118
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
|
9
|
+
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, load_pem_private_key
|
|
10
|
+
|
|
11
|
+
from .models import LoadedSigner, SignerIdentity
|
|
12
|
+
from .utils import DEFAULT_SIGNER_ID, sha256_text
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _public_key_manifest(private_key: Ed25519PrivateKey, *, signer_id: str, source: str) -> SignerIdentity:
|
|
16
|
+
public_key = private_key.public_key()
|
|
17
|
+
public_pem = public_key.public_bytes(Encoding.PEM, PublicFormat.SubjectPublicKeyInfo).decode("utf-8")
|
|
18
|
+
public_sha = sha256_text(public_pem)
|
|
19
|
+
key_id = f"ed25519:{public_sha[:24]}"
|
|
20
|
+
return SignerIdentity(
|
|
21
|
+
signer_id=signer_id,
|
|
22
|
+
key_id=key_id,
|
|
23
|
+
public_key_pem=public_pem,
|
|
24
|
+
public_key_sha256=public_sha,
|
|
25
|
+
source=source,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _load_private_key_from_pem(pem: str) -> Ed25519PrivateKey:
|
|
30
|
+
key = load_pem_private_key(pem.encode("utf-8"), password=None)
|
|
31
|
+
if not isinstance(key, Ed25519PrivateKey):
|
|
32
|
+
raise TypeError("release signing key must be an Ed25519 private key")
|
|
33
|
+
return key
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _private_key_from_material(signing_key: str | None) -> tuple[Ed25519PrivateKey, str]:
|
|
37
|
+
env_file = os.environ.get("TBA_AUTH_RELEASE_SIGNING_KEY_FILE")
|
|
38
|
+
env_pem = os.environ.get("TBA_AUTH_RELEASE_SIGNING_KEY_PEM")
|
|
39
|
+
env_seed = os.environ.get("TBA_AUTH_RELEASE_SIGNING_SEED")
|
|
40
|
+
material = signing_key or env_pem
|
|
41
|
+
if env_file and not signing_key and not env_pem:
|
|
42
|
+
pem = Path(env_file).read_text(encoding="utf-8")
|
|
43
|
+
return _load_private_key_from_pem(pem), f"file:{env_file}"
|
|
44
|
+
if material:
|
|
45
|
+
if "BEGIN PRIVATE KEY" in material:
|
|
46
|
+
return _load_private_key_from_pem(material), "inline-pem"
|
|
47
|
+
maybe_path = Path(material)
|
|
48
|
+
if maybe_path.exists() and maybe_path.is_file():
|
|
49
|
+
pem = maybe_path.read_text(encoding="utf-8")
|
|
50
|
+
return _load_private_key_from_pem(pem), f"file:{maybe_path}"
|
|
51
|
+
seed = hashlib.sha256(material.encode("utf-8")).digest()
|
|
52
|
+
return Ed25519PrivateKey.from_private_bytes(seed), "derived-inline-secret"
|
|
53
|
+
if env_seed:
|
|
54
|
+
seed = hashlib.sha256(env_seed.encode("utf-8")).digest()
|
|
55
|
+
return Ed25519PrivateKey.from_private_bytes(seed), "derived-env-seed"
|
|
56
|
+
return Ed25519PrivateKey.generate(), "generated-ephemeral-checkpoint-key"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def load_signer(*, signing_key: str | None = None, signer_id: str | None = None) -> LoadedSigner:
|
|
60
|
+
private_key, source = _private_key_from_material(signing_key)
|
|
61
|
+
identity = _public_key_manifest(private_key, signer_id=signer_id or os.environ.get("TBA_AUTH_RELEASE_SIGNER_ID", DEFAULT_SIGNER_ID), source=source)
|
|
62
|
+
return LoadedSigner(private_key=private_key, identity=identity)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def write_public_key_artifacts(bundle_root: Path, signer: LoadedSigner) -> dict[str, str]:
|
|
66
|
+
attest_root = bundle_root / "attestations"
|
|
67
|
+
key_dir = attest_root / "keys"
|
|
68
|
+
key_dir.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
public_key_path = key_dir / f"{signer.identity.key_id.replace(':', '-')}.pub.pem"
|
|
70
|
+
public_key_path.write_text(signer.identity.public_key_pem, encoding="utf-8")
|
|
71
|
+
signer_identity_path = attest_root / "signer-identity.json"
|
|
72
|
+
signer_identity_path.write_text(json.dumps(signer.identity.to_manifest(), indent=2) + "\n", encoding="utf-8")
|
|
73
|
+
return {
|
|
74
|
+
"public_key_path": str(public_key_path.relative_to(bundle_root)).replace("\\", "/"),
|
|
75
|
+
"signer_identity_path": str(signer_identity_path.relative_to(bundle_root)).replace("\\", "/"),
|
|
76
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
|
7
|
+
from cryptography.hazmat.primitives.serialization import Encoding, NoEncryption, PrivateFormat
|
|
8
|
+
|
|
9
|
+
from .utils import STATEMENT_VERSION, _b64url_encode, _canonical_json, _utc_now, sha256_bytes
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(slots=True)
|
|
13
|
+
class SignerIdentity:
|
|
14
|
+
signer_id: str
|
|
15
|
+
key_id: str
|
|
16
|
+
public_key_pem: str
|
|
17
|
+
public_key_sha256: str
|
|
18
|
+
source: str
|
|
19
|
+
algorithm: str = "Ed25519"
|
|
20
|
+
identity_kind: str = "repository-release-attestor"
|
|
21
|
+
|
|
22
|
+
def to_manifest(self) -> dict[str, Any]:
|
|
23
|
+
return {
|
|
24
|
+
"signer_id": self.signer_id,
|
|
25
|
+
"key_id": self.key_id,
|
|
26
|
+
"algorithm": self.algorithm,
|
|
27
|
+
"identity_kind": self.identity_kind,
|
|
28
|
+
"public_key_pem": self.public_key_pem,
|
|
29
|
+
"public_key_sha256": self.public_key_sha256,
|
|
30
|
+
"source": self.source,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(slots=True)
|
|
35
|
+
class LoadedSigner:
|
|
36
|
+
private_key: Ed25519PrivateKey
|
|
37
|
+
identity: SignerIdentity
|
|
38
|
+
|
|
39
|
+
def private_key_pem(self) -> str:
|
|
40
|
+
return self.private_key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()).decode("utf-8")
|
|
41
|
+
|
|
42
|
+
def sign_payload(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
43
|
+
raw = _canonical_json(payload)
|
|
44
|
+
signature = self.private_key.sign(raw)
|
|
45
|
+
return {
|
|
46
|
+
"algorithm": self.identity.algorithm,
|
|
47
|
+
"encoding": "base64url",
|
|
48
|
+
"value": _b64url_encode(signature),
|
|
49
|
+
"payload_sha256": sha256_bytes(raw),
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
def sign_statement(self, statement_type: str, subject: dict[str, Any], *, issued_at: str | None = None) -> dict[str, Any]:
|
|
53
|
+
payload = {
|
|
54
|
+
"schema_version": STATEMENT_VERSION,
|
|
55
|
+
"statement_type": statement_type,
|
|
56
|
+
"issued_at": issued_at or _utc_now(),
|
|
57
|
+
"signer": self.identity.to_manifest(),
|
|
58
|
+
"subject": subject,
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
"schema_version": STATEMENT_VERSION,
|
|
62
|
+
"payload": payload,
|
|
63
|
+
"signature": self.sign_payload(payload),
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(slots=True)
|
|
68
|
+
class VerificationResult:
|
|
69
|
+
passed: bool
|
|
70
|
+
failures: list[str]
|
|
71
|
+
warnings: list[str]
|
|
72
|
+
details: dict[str, Any]
|
|
73
|
+
|
|
74
|
+
def to_manifest(self) -> dict[str, Any]:
|
|
75
|
+
return {
|
|
76
|
+
"passed": self.passed,
|
|
77
|
+
"failures": list(self.failures),
|
|
78
|
+
"warnings": list(self.warnings),
|
|
79
|
+
"details": dict(self.details),
|
|
80
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
STATEMENT_VERSION = 1
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
STATEMENT_TYPE_ARTIFACT = "https://tigrbl.dev/attestations/release-artifact/v1"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
STATEMENT_TYPE_BUNDLE = "https://tigrbl.dev/attestations/release-bundle/v1"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
DEFAULT_SIGNER_ID = "tba_auth.checkpoint.attestor"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _utc_now() -> str:
|
|
23
|
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _canonical_json(payload: Any) -> bytes:
|
|
27
|
+
return json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _b64url_encode(data: bytes) -> str:
|
|
31
|
+
return base64.urlsafe_b64encode(data).rstrip(b"=").decode("ascii")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _b64url_decode(text: str) -> bytes:
|
|
35
|
+
padding = "=" * ((4 - len(text) % 4) % 4)
|
|
36
|
+
return base64.urlsafe_b64decode((text + padding).encode("ascii"))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def sha256_bytes(payload: bytes) -> str:
|
|
40
|
+
return hashlib.sha256(payload).hexdigest()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def sha256_text(payload: str) -> str:
|
|
44
|
+
return sha256_bytes(payload.encode("utf-8"))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def sha256_file(path: Path) -> str:
|
|
48
|
+
return sha256_bytes(path.read_bytes())
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
|
|
8
|
+
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
|
9
|
+
|
|
10
|
+
from .models import VerificationResult
|
|
11
|
+
from .utils import _b64url_decode, _canonical_json, sha256_bytes, sha256_file, sha256_text
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def verify_statement(statement: dict[str, Any], *, public_key_pem: str | None = None) -> VerificationResult:
|
|
15
|
+
failures: list[str] = []
|
|
16
|
+
warnings: list[str] = []
|
|
17
|
+
payload = statement.get("payload") if isinstance(statement, dict) else None
|
|
18
|
+
signature_block = statement.get("signature") if isinstance(statement, dict) else None
|
|
19
|
+
if not isinstance(payload, dict):
|
|
20
|
+
failures.append("Statement missing payload object")
|
|
21
|
+
return VerificationResult(False, failures, warnings, {})
|
|
22
|
+
if not isinstance(signature_block, dict):
|
|
23
|
+
failures.append("Statement missing signature block")
|
|
24
|
+
return VerificationResult(False, failures, warnings, {})
|
|
25
|
+
signer = payload.get("signer") if isinstance(payload.get("signer"), dict) else {}
|
|
26
|
+
pem = public_key_pem or signer.get("public_key_pem")
|
|
27
|
+
if not isinstance(pem, str) or not pem.strip():
|
|
28
|
+
failures.append("Statement missing public key PEM")
|
|
29
|
+
return VerificationResult(False, failures, warnings, {})
|
|
30
|
+
key = load_pem_public_key(pem.encode("utf-8"))
|
|
31
|
+
if not isinstance(key, Ed25519PublicKey):
|
|
32
|
+
failures.append("Statement public key is not Ed25519")
|
|
33
|
+
return VerificationResult(False, failures, warnings, {})
|
|
34
|
+
sig_value = signature_block.get("value")
|
|
35
|
+
if not isinstance(sig_value, str) or not sig_value:
|
|
36
|
+
failures.append("Statement signature value is missing")
|
|
37
|
+
return VerificationResult(False, failures, warnings, {})
|
|
38
|
+
try:
|
|
39
|
+
key.verify(_b64url_decode(sig_value), _canonical_json(payload))
|
|
40
|
+
except Exception as exc: # noqa: BLE001
|
|
41
|
+
failures.append(f"Signature verification failed: {exc}")
|
|
42
|
+
return VerificationResult(False, failures, warnings, {})
|
|
43
|
+
payload_sha = signature_block.get("payload_sha256")
|
|
44
|
+
actual_sha = sha256_bytes(_canonical_json(payload))
|
|
45
|
+
if payload_sha != actual_sha:
|
|
46
|
+
failures.append("Statement payload digest does not match signature block")
|
|
47
|
+
embedded_sha = signer.get("public_key_sha256")
|
|
48
|
+
if embedded_sha and embedded_sha != sha256_text(pem):
|
|
49
|
+
failures.append("Embedded public key SHA-256 does not match public key PEM")
|
|
50
|
+
details = {
|
|
51
|
+
"statement_type": payload.get("statement_type"),
|
|
52
|
+
"artifact_label": payload.get("subject", {}).get("artifact_label") if isinstance(payload.get("subject"), dict) else None,
|
|
53
|
+
"key_id": signer.get("key_id"),
|
|
54
|
+
"issued_at": payload.get("issued_at"),
|
|
55
|
+
}
|
|
56
|
+
return VerificationResult(not failures, failures, warnings, details)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def verify_bundle_attestations(bundle_root: Path) -> VerificationResult:
|
|
60
|
+
bundle_root = bundle_root.resolve()
|
|
61
|
+
failures: list[str] = []
|
|
62
|
+
warnings: list[str] = []
|
|
63
|
+
attest_root = bundle_root / "attestations"
|
|
64
|
+
if not attest_root.exists():
|
|
65
|
+
failures.append("Missing attestations directory")
|
|
66
|
+
return VerificationResult(False, failures, warnings, {})
|
|
67
|
+
summary_path = bundle_root / "signature.json"
|
|
68
|
+
if not summary_path.exists():
|
|
69
|
+
failures.append("Missing signature.json summary")
|
|
70
|
+
return VerificationResult(False, failures, warnings, {})
|
|
71
|
+
summary = json.loads(summary_path.read_text(encoding="utf-8"))
|
|
72
|
+
signed_artifacts = summary.get("signed_artifacts", [])
|
|
73
|
+
if not isinstance(signed_artifacts, list) or not signed_artifacts:
|
|
74
|
+
failures.append("signature.json does not list signed artifacts")
|
|
75
|
+
return VerificationResult(False, failures, warnings, {})
|
|
76
|
+
verified_labels: list[str] = []
|
|
77
|
+
key_ids: set[str] = set()
|
|
78
|
+
for item in signed_artifacts:
|
|
79
|
+
label = str(item.get("label"))
|
|
80
|
+
artifact_rel_path = str(item.get("artifact_path"))
|
|
81
|
+
attestation_rel_path = str(item.get("attestation_path"))
|
|
82
|
+
artifact_path = bundle_root / artifact_rel_path
|
|
83
|
+
attestation_path = bundle_root / attestation_rel_path
|
|
84
|
+
if not artifact_path.exists():
|
|
85
|
+
failures.append(f"Signed artifact missing: {artifact_rel_path}")
|
|
86
|
+
continue
|
|
87
|
+
if not attestation_path.exists():
|
|
88
|
+
failures.append(f"Attestation missing for {label}: {attestation_rel_path}")
|
|
89
|
+
continue
|
|
90
|
+
statement = json.loads(attestation_path.read_text(encoding="utf-8"))
|
|
91
|
+
result = verify_statement(statement)
|
|
92
|
+
failures.extend(result.failures)
|
|
93
|
+
warnings.extend(result.warnings)
|
|
94
|
+
if not result.passed:
|
|
95
|
+
continue
|
|
96
|
+
payload = statement["payload"]
|
|
97
|
+
subject = payload.get("subject", {}) if isinstance(payload.get("subject"), dict) else {}
|
|
98
|
+
if subject.get("artifact_sha256") != sha256_file(artifact_path):
|
|
99
|
+
failures.append(f"Artifact digest mismatch for {label}: {artifact_rel_path}")
|
|
100
|
+
continue
|
|
101
|
+
if subject.get("artifact_path") != artifact_rel_path:
|
|
102
|
+
failures.append(f"Artifact path mismatch for {label}: {artifact_rel_path}")
|
|
103
|
+
continue
|
|
104
|
+
signer = payload.get("signer", {}) if isinstance(payload.get("signer"), dict) else {}
|
|
105
|
+
if signer.get("key_id"):
|
|
106
|
+
key_ids.add(str(signer.get("key_id")))
|
|
107
|
+
verified_labels.append(label)
|
|
108
|
+
release_attestation_path = attest_root / "release-attestation.json"
|
|
109
|
+
if not release_attestation_path.exists():
|
|
110
|
+
failures.append("Missing release-attestation.json")
|
|
111
|
+
else:
|
|
112
|
+
bundle_statement = json.loads(release_attestation_path.read_text(encoding="utf-8"))
|
|
113
|
+
result = verify_statement(bundle_statement)
|
|
114
|
+
failures.extend(result.failures)
|
|
115
|
+
warnings.extend(result.warnings)
|
|
116
|
+
if result.passed:
|
|
117
|
+
subject = bundle_statement["payload"].get("subject", {})
|
|
118
|
+
bundle_items = subject.get("signed_artifacts", []) if isinstance(subject, dict) else []
|
|
119
|
+
if len(bundle_items) != len(signed_artifacts):
|
|
120
|
+
failures.append("Release attestation signed_artifacts count does not match signature.json")
|
|
121
|
+
for item in bundle_items:
|
|
122
|
+
label = str(item.get("label"))
|
|
123
|
+
if label not in verified_labels:
|
|
124
|
+
failures.append(f"Release attestation references unverified artifact: {label}")
|
|
125
|
+
signer = bundle_statement["payload"].get("signer", {})
|
|
126
|
+
if isinstance(signer, dict) and signer.get("key_id"):
|
|
127
|
+
key_ids.add(str(signer.get("key_id")))
|
|
128
|
+
if len(key_ids) > 1:
|
|
129
|
+
failures.append("Multiple signing identities were used within one release bundle")
|
|
130
|
+
details = {
|
|
131
|
+
"bundle_root": str(bundle_root),
|
|
132
|
+
"verified_artifact_count": len(verified_labels),
|
|
133
|
+
"signing_key_id": sorted(key_ids)[0] if len(key_ids) == 1 else None,
|
|
134
|
+
"artifact_labels": verified_labels,
|
|
135
|
+
}
|
|
136
|
+
return VerificationResult(not failures, failures, warnings, details)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-runtime-identity-authoring
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Release artifact authoring, signing, attestation, and verification helpers for the TBA identity suite.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Keywords: tigrbl,identity,release,attestation,provenance,signing,evidence
|
|
7
|
+
Requires-Python: >=3.10,<3.15
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Dist: cryptography (>=45.0.0)
|
|
22
|
+
Project-URL: Homepage, https://github.com/tigrbl/tigrbl_auth
|
|
23
|
+
Project-URL: PyPI, https://pypi.org/project/tba-runtime-identity-authoring/
|
|
24
|
+
Project-URL: Repository, https://github.com/tigrbl/tigrbl_auth
|
|
25
|
+
Project-URL: Source, https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/60-runtime/tba-runtime-identity-authoring
|
|
26
|
+
Project-URL: SSOT, https://github.com/tigrbl/tigrbl_auth/blob/master/.ssot/registry.json
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# tba-runtime-identity-authoring
|
|
30
|
+
|
|
31
|
+
[](https://github.com/tigrbl/tigrbl_auth/blob/master/.ssot/registry.json)
|
|
32
|
+
|
|
33
|
+
tba-runtime-identity-authoring owns release artifact authoring, signing, attestation, and verification helpers for the TBA identity package suite.
|
|
34
|
+
|
|
35
|
+
## AEO Summary
|
|
36
|
+
|
|
37
|
+
- Package: `tba-runtime-identity-authoring`
|
|
38
|
+
- Import root: `tba_runtime_identity_authoring`
|
|
39
|
+
- Component kind: Runtime support package
|
|
40
|
+
- Use it for release bundle signing, artifact attestations, and release provenance verification.
|
|
41
|
+
- It is not request-path runtime token behavior.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from tba_runtime_identity_authoring.release_signing import sha256_bytes
|
|
47
|
+
|
|
48
|
+
digest = sha256_bytes(b"identity-release-evidence")
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Package Boundary
|
|
52
|
+
|
|
53
|
+
- Release bundle artifact hashing
|
|
54
|
+
- Signed artifact attestations
|
|
55
|
+
- Signed release-bundle attestations
|
|
56
|
+
- Public signing-key artifact generation
|
|
57
|
+
- Release signing verification helpers
|
|
58
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
tba_runtime_identity_authoring/__init__.py,sha256=p_tTQ13a1OcK3w2MCIWrwk5bjRwyJiz0OcpH320NSN4,878
|
|
2
|
+
tba_runtime_identity_authoring/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
tba_runtime_identity_authoring/release_signing/__init__.py,sha256=9YQ1sovDbpfS-dNuTC3dadyqocY_-ErMYhJ3484IJlI,885
|
|
4
|
+
tba_runtime_identity_authoring/release_signing/attestations.py,sha256=Dig5b-xrehAHfXCphA5o0X-L_MtXR1rpaRa92J0ncSg,3447
|
|
5
|
+
tba_runtime_identity_authoring/release_signing/keys.py,sha256=h0cj3vo1X0aBiXWU10XcmgNjYSuk8Xz_uD-rPTg3hww,3585
|
|
6
|
+
tba_runtime_identity_authoring/release_signing/models.py,sha256=7Rnwaa-mJU-SQR27nwBCK6BNzsRccEGvng2lZUM3gZk,2543
|
|
7
|
+
tba_runtime_identity_authoring/release_signing/utils.py,sha256=AJnaIloiN-XQj6yKRSjDcoPwkYcZNHM5PgDvr-mmgYU,1205
|
|
8
|
+
tba_runtime_identity_authoring/release_signing/verification.py,sha256=fVn3gVMCYXs26uHP3diLgkJwmNy_aya0RkoYNLa5OAk,7058
|
|
9
|
+
tba_runtime_identity_authoring-0.4.0.dev2.dist-info/METADATA,sha256=nTX3spo8fCR6JS5kaIGbjhtfhGMhwcFiBZ0J2srmcAc,2433
|
|
10
|
+
tba_runtime_identity_authoring-0.4.0.dev2.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
11
|
+
tba_runtime_identity_authoring-0.4.0.dev2.dist-info/RECORD,,
|