trproof 0.1.0__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.
@@ -0,0 +1 @@
1
+ """Graph package (Phase 3+)."""
trproof/graph/edges.py ADDED
@@ -0,0 +1,219 @@
1
+ """In-memory attack graph and BFS shortest-path finder (Phase 4)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections import defaultdict, deque
6
+ from typing import Any, Dict, List, Set, Tuple
7
+
8
+ from trproof.models import AttackPath, PrincipalNode, ScanBundle
9
+
10
+
11
+ CROWN_JEWEL_NAMES = {
12
+ "Domain Admins",
13
+ "Enterprise Admins",
14
+ "Administrators",
15
+ "Global Administrator",
16
+ "Privileged Role Administrator",
17
+ }
18
+
19
+ ENTRY_RELATIONS = {
20
+ "has_MFA_gap",
21
+ "is_kerberoastable",
22
+ "is_kerberoastable_with_admin_equiv",
23
+ "has_asrep_roast",
24
+ "has_weak_delegation",
25
+ "member_of",
26
+ "can_reset_password",
27
+ "consented_risky_app",
28
+ "privileged_guest",
29
+ }
30
+
31
+ CRITICAL_EDGE_RELATIONS = {
32
+ "has_MFA_gap",
33
+ "is_kerberoastable_with_admin_equiv",
34
+ "has_weak_delegation",
35
+ "can_reset_password",
36
+ }
37
+
38
+ CROWN_SINGULAR = {
39
+ "Domain Admins": "Domain Admin",
40
+ "Enterprise Admins": "Enterprise Admin",
41
+ "Administrators": "Administrator",
42
+ "Global Administrator": "Global Admin",
43
+ "Privileged Role Administrator": "Privileged Role Admin",
44
+ }
45
+
46
+
47
+ def _is_phishing_resistant(node: PrincipalNode) -> bool:
48
+ metadata = node.metadata or {}
49
+ if metadata.get("phishing_resistant_mfa") is False:
50
+ return False
51
+ mfa = str(metadata.get("mfa", "")).strip().lower()
52
+ if mfa in {"none", "sms only", "sms-only"}:
53
+ return False
54
+ return True
55
+
56
+
57
+ def _edge_phrase(edge_relation: str, source: str, target: str) -> str:
58
+ if edge_relation == "member_of":
59
+ if target in CROWN_SINGULAR:
60
+ return f"{source} is {CROWN_SINGULAR[target]}"
61
+ return f"member of '{target}'"
62
+ if edge_relation == "can_reset_password":
63
+ return f"{source} can reset passwords of '{target}'"
64
+ if edge_relation == "has_MFA_gap":
65
+ return f"{source} has no phishing-resistant MFA"
66
+ if edge_relation == "is_kerberoastable":
67
+ return f"{source} is Kerberoastable"
68
+ if edge_relation == "is_kerberoastable_with_admin_equiv":
69
+ return f"{source} is Kerberoastable with admin-equivalent rights"
70
+ if edge_relation == "has_asrep_roast":
71
+ return f"{source} is AS-REP roastable"
72
+ if edge_relation == "has_weak_delegation":
73
+ return f"{source} has weak delegation"
74
+ if edge_relation == "consented_risky_app":
75
+ return f"{source} consented a risky app"
76
+ if edge_relation == "privileged_guest":
77
+ return f"{source} is a privileged guest"
78
+ return f"{source} -> {target} ({edge_relation})"
79
+
80
+
81
+ class AttackGraph:
82
+ """Directed in-memory graph used for shortest attack-path discovery."""
83
+
84
+ def __init__(self, bundle: ScanBundle) -> None:
85
+ self.bundle = bundle
86
+ self.nodes: Dict[str, PrincipalNode] = {node.id: node for node in bundle.nodes}
87
+ self.adjacency: Dict[str, List[Any]] = defaultdict(list)
88
+ for edge in bundle.edges:
89
+ self.adjacency[edge.source_id].append(edge)
90
+
91
+ # Terminal crown jewels: named targets plus privileged nodes with no
92
+ # outbound edges (i.e. they are endpoints rather than stepping stones).
93
+ outgoing_sources = {edge.source_id for edge in bundle.edges}
94
+ self.crown_jewel_ids: Set[str] = set()
95
+ for node in bundle.nodes:
96
+ if node.name in CROWN_JEWEL_NAMES or node.id in CROWN_JEWEL_NAMES:
97
+ self.crown_jewel_ids.add(node.id)
98
+ elif node.is_privileged and node.id not in outgoing_sources:
99
+ self.crown_jewel_ids.add(node.id)
100
+
101
+ # Entry nodes are non-crown-jewel, non-privileged user/service
102
+ # principals that have at least one outbound edge using an attack relation.
103
+ self.entry_ids: List[str] = []
104
+ for node in bundle.nodes:
105
+ if node.id in self.crown_jewel_ids:
106
+ continue
107
+ if node.is_privileged:
108
+ continue
109
+ if node.principal_type not in ("user", "service_principal"):
110
+ continue
111
+ outbound = self.adjacency.get(node.id, [])
112
+ if any(getattr(edge, "relation", None) in ENTRY_RELATIONS for edge in outbound):
113
+ self.entry_ids.append(node.id)
114
+
115
+ def find_shortest_paths(
116
+ self, max_display: int = 5, max_depth: int = 8
117
+ ) -> Tuple[List[AttackPath], List[AttackPath]]:
118
+ discovered: List[Tuple[List[str], List[str]]] = []
119
+
120
+ for start in self.entry_ids:
121
+ queue: deque = deque()
122
+ queue.append((start, [start], []))
123
+ visited: Set[str] = {start}
124
+
125
+ while queue:
126
+ node_id, node_ids, edge_relations = queue.popleft()
127
+ depth = len(node_ids) - 1
128
+
129
+ if node_id in self.crown_jewel_ids and node_id != start:
130
+ if depth <= max_depth:
131
+ discovered.append((list(node_ids), list(edge_relations)))
132
+ continue
133
+
134
+ if depth >= max_depth:
135
+ continue
136
+
137
+ for edge in self.adjacency.get(node_id, []):
138
+ target_id = getattr(edge, "target_id", None)
139
+ if not target_id or target_id in node_ids:
140
+ continue
141
+ if target_id in visited:
142
+ continue
143
+ relation = getattr(edge, "relation", "")
144
+ visited.add(target_id)
145
+ queue.append(
146
+ (
147
+ target_id,
148
+ node_ids + [target_id],
149
+ edge_relations + [relation],
150
+ )
151
+ )
152
+
153
+ # Deduplicate identical node sequences.
154
+ unique: Dict[Tuple[str, ...], Tuple[List[str], List[str]]] = {}
155
+ for node_ids, edge_relations in discovered:
156
+ key = tuple(node_ids)
157
+ if key not in unique:
158
+ unique[key] = (node_ids, edge_relations)
159
+
160
+ # Build path records and rank them.
161
+ records: List[Dict[str, Any]] = []
162
+ for node_ids, edge_relations in unique.values():
163
+ start_node = self.nodes.get(node_ids[0])
164
+ start_name = start_node.name if start_node else node_ids[0]
165
+ start_label = start_name
166
+ if start_node is not None and not _is_phishing_resistant(start_node):
167
+ start_label = f"{start_name} (no phishing-resistant MFA)"
168
+
169
+ phrase_parts: List[str] = [start_label]
170
+ for relation, source_id, target_id in zip(
171
+ edge_relations, node_ids, node_ids[1:]
172
+ ):
173
+ source_node = self.nodes.get(source_id)
174
+ target_node = self.nodes.get(target_id)
175
+ source_name = source_node.name if source_node else source_id
176
+ target_name = target_node.name if target_node else target_id
177
+ phrase_parts.append(_edge_phrase(relation, source_name, target_name))
178
+
179
+ records.append(
180
+ {
181
+ "nodes": list(node_ids),
182
+ "edges": list(edge_relations),
183
+ "steps": len(node_ids) - 1,
184
+ "critical_weight": sum(
185
+ 1 for relation in edge_relations if relation in CRITICAL_EDGE_RELATIONS
186
+ ),
187
+ "start_name": start_name,
188
+ "phrase_parts": phrase_parts,
189
+ }
190
+ )
191
+
192
+ records.sort(
193
+ key=lambda r: (
194
+ r["steps"],
195
+ -r["critical_weight"],
196
+ r["start_name"],
197
+ r["nodes"],
198
+ r["edges"],
199
+ )
200
+ )
201
+
202
+ paths: List[AttackPath] = []
203
+ for index, record in enumerate(records, start=1):
204
+ summary = (
205
+ f"Path {index} ({record['steps']} steps): "
206
+ + " → ".join(record["phrase_parts"])
207
+ + "."
208
+ )
209
+ paths.append(
210
+ AttackPath(
211
+ rank=index,
212
+ steps=record["steps"],
213
+ summary=summary,
214
+ nodes=record["nodes"],
215
+ edges=record["edges"],
216
+ )
217
+ )
218
+
219
+ return paths[: max(0, max_display)], paths
@@ -0,0 +1,3 @@
1
+ -----BEGIN PRIVATE KEY-----
2
+ MC4CAQAwBQYDK2VwBCIEIFn+WDSDJc8KicUZfNysZvw7i8UipEDZt29csdD6XDYi
3
+ -----END PRIVATE KEY-----
@@ -0,0 +1,3 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MCowBQYDK2VwAyEA8Fx1urEDlaNrznRg13JIPY8NyQ9JpdkqdhjdQMuDHQo=
3
+ -----END PUBLIC KEY-----
trproof/models.py ADDED
@@ -0,0 +1,76 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+ from typing import Any, Literal
5
+
6
+ from pydantic import BaseModel, Field
7
+
8
+
9
+ class Severity(str, Enum):
10
+ CRITICAL = "CRITICAL"
11
+ HIGH = "HIGH"
12
+ MEDIUM = "MEDIUM"
13
+ LOW = "LOW"
14
+
15
+
16
+ class PrincipalNode(BaseModel):
17
+ id: str
18
+ name: str
19
+ principal_type: Literal["user", "group", "computer", "service_principal", "role"]
20
+ source: Literal["ad", "entra"]
21
+ is_privileged: bool = False
22
+ metadata: dict[str, Any] = Field(default_factory=dict)
23
+
24
+
25
+ class IdentityEdge(BaseModel):
26
+ source_id: str
27
+ target_id: str
28
+ relation: str
29
+ description: str
30
+
31
+
32
+ class Finding(BaseModel):
33
+ id: str
34
+ title: str
35
+ severity: Severity
36
+ source: Literal["ad", "entra"]
37
+ affected_count: int
38
+ affected_entities: list[str]
39
+ why_it_matters: str
40
+ how_to_fix: str
41
+
42
+
43
+ class AttackPath(BaseModel):
44
+ rank: int
45
+ steps: int
46
+ summary: str
47
+ nodes: list[str]
48
+ edges: list[str]
49
+
50
+
51
+ class CollectionWarning(BaseModel):
52
+ check_name: str
53
+ source: Literal["ad", "entra"]
54
+ reason: str
55
+
56
+
57
+ class ScanBundle(BaseModel):
58
+ nodes: list[PrincipalNode] = Field(default_factory=list)
59
+ edges: list[IdentityEdge] = Field(default_factory=list)
60
+ findings: list[Finding] = Field(default_factory=list)
61
+ warnings: list[CollectionWarning] = Field(default_factory=list)
62
+ metadata: dict[str, Any] = Field(default_factory=dict)
63
+
64
+
65
+ class AssessmentReport(BaseModel):
66
+ schema_version: str = "1.0"
67
+ generated_at: str
68
+ environment_label: str
69
+ verdict: Severity
70
+ top_paths: list[AttackPath]
71
+ all_paths: list[AttackPath]
72
+ findings: list[Finding]
73
+ warnings: list[CollectionWarning]
74
+ canonical_sha256: str = ""
75
+ signature_b64: str = ""
76
+ public_key_b64: str = ""
@@ -0,0 +1 @@
1
+ """Report package (Phase 5+)."""
trproof/report/html.py ADDED
@@ -0,0 +1,222 @@
1
+ """Self-contained HTML report renderer for TrProof."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import html
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+
9
+ from trproof.models import AssessmentReport
10
+
11
+
12
+ def _escape(value: object) -> str:
13
+ return html.escape(str(value), quote=True)
14
+
15
+
16
+ def _scan_date(generated_at: str) -> str:
17
+ try:
18
+ return datetime.fromisoformat(generated_at.replace("Z", "+00:00")).strftime(
19
+ "%Y-%m-%d"
20
+ )
21
+ except ValueError:
22
+ return str(generated_at)[:10]
23
+
24
+
25
+ def _source_label(source: str) -> str:
26
+ if source == "ad":
27
+ return "AD"
28
+ if source == "entra":
29
+ return "Entra"
30
+ return _escape(source)
31
+
32
+
33
+ def _verdict_color(verdict: str) -> str:
34
+ return {
35
+ "CRITICAL": "#dc2626",
36
+ "HIGH": "#ea580c",
37
+ "MEDIUM": "#ca8a04",
38
+ "LOW": "#16a34a",
39
+ }.get(verdict, "#374151")
40
+
41
+
42
+ def render_html_report(report: AssessmentReport, output_path: Path) -> Path:
43
+ verdict = report.verdict.value
44
+ verdict_color = _verdict_color(verdict)
45
+ scan_date = _scan_date(report.generated_at)
46
+
47
+ path_items = "".join(
48
+ f"<li>{_escape(path.summary)}</li>" for path in report.top_paths
49
+ )
50
+ if not path_items:
51
+ path_items = "<li>No direct attack paths to Tier-0 administrators found.</li>"
52
+
53
+ finding_rows = []
54
+ for finding in report.findings:
55
+ finding_rows.append(
56
+ "<tr>"
57
+ f"<td><span class=\"chip severity-{_escape(finding.severity.value.lower())}\">{_escape(finding.severity.value)}</span></td>"
58
+ f"<td>{_escape(finding.title)}</td>"
59
+ f"<td>{_source_label(finding.source)}</td>"
60
+ f"<td>{finding.affected_count}</td>"
61
+ f"<td>{_escape(finding.why_it_matters)}</td>"
62
+ f"<td>{_escape(finding.how_to_fix)}</td>"
63
+ "</tr>"
64
+ )
65
+ findings_table = "".join(finding_rows) or (
66
+ "<tr><td colspan=\"6\">No findings.</td></tr>"
67
+ )
68
+
69
+ warnings_section = ""
70
+ if report.warnings:
71
+ warning_items = "".join(
72
+ f"<li>{_escape(w.check_name)} ({_escape(w.reason)})</li>"
73
+ for w in report.warnings
74
+ )
75
+ warnings_section = (
76
+ "<section class=\"warnings\">"
77
+ "<h2>Could not check</h2>"
78
+ f"<ul>{warning_items}</ul>"
79
+ "</section>"
80
+ )
81
+
82
+ digest = _escape(report.canonical_sha256)
83
+ public_key_fingerprint = _escape(report.public_key_b64[:24] + "...")
84
+
85
+ document = f"""<!DOCTYPE html>
86
+ <html lang="en">
87
+ <head>
88
+ <meta charset="utf-8">
89
+ <meta name="viewport" content="width=device-width, initial-scale=1">
90
+ <title>Identity attack surface as of {_escape(scan_date)}</title>
91
+ <style>
92
+ :root {{
93
+ --bg: #f8fafc;
94
+ --card: #ffffff;
95
+ --text: #0f172a;
96
+ --muted: #475569;
97
+ --border: #cbd5e1;
98
+ }}
99
+ * {{ box-sizing: border-box; }}
100
+ body {{
101
+ margin: 0;
102
+ padding: 24px;
103
+ font-family: "Segoe UI", Arial, sans-serif;
104
+ color: var(--text);
105
+ background: var(--bg);
106
+ line-height: 1.45;
107
+ }}
108
+ .container {{ max-width: 1100px; margin: 0 auto; }}
109
+ header {{ margin-bottom: 20px; }}
110
+ h1 {{ margin: 0 0 12px; font-size: 24px; }}
111
+ h2 {{ margin: 18px 0 8px; font-size: 18px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }}
112
+ .badge {{
113
+ display: inline-block;
114
+ padding: 10px 18px;
115
+ border-radius: 999px;
116
+ color: #ffffff;
117
+ font-weight: 700;
118
+ font-size: 18px;
119
+ background: {verdict_color};
120
+ margin-bottom: 8px;
121
+ }}
122
+ .meta {{ color: var(--muted); font-size: 13px; }}
123
+ .card {{
124
+ background: var(--card);
125
+ border: 1px solid var(--border);
126
+ border-radius: 10px;
127
+ padding: 16px;
128
+ margin-bottom: 16px;
129
+ }}
130
+ .paths ol {{ margin: 8px 0 0 20px; }}
131
+ table {{
132
+ width: 100%;
133
+ border-collapse: collapse;
134
+ font-size: 13px;
135
+ }}
136
+ th, td {{
137
+ border: 1px solid var(--border);
138
+ padding: 8px;
139
+ vertical-align: top;
140
+ text-align: left;
141
+ }}
142
+ th {{ background: #e2e8f0; }}
143
+ .chip {{
144
+ display: inline-block;
145
+ padding: 2px 8px;
146
+ border-radius: 999px;
147
+ color: #ffffff;
148
+ font-size: 11px;
149
+ font-weight: 700;
150
+ }}
151
+ .severity-critical {{ background: #dc2626; }}
152
+ .severity-high {{ background: #ea580c; }}
153
+ .severity-medium {{ background: #ca8a04; }}
154
+ .severity-low {{ background: #16a34a; }}
155
+ footer {{
156
+ margin-top: 20px;
157
+ padding-top: 12px;
158
+ border-top: 1px solid var(--border);
159
+ color: var(--muted);
160
+ font-size: 12px;
161
+ }}
162
+ @media print {{
163
+ body {{ padding: 12mm; background: #ffffff; }}
164
+ .card {{ box-shadow: none; }}
165
+ table {{ font-size: 11px; }}
166
+ footer {{ page-break-inside: avoid; }}
167
+ }}
168
+ </style>
169
+ </head>
170
+ <body>
171
+ <div class="container">
172
+ <header>
173
+ <h1>Identity attack surface as of {_escape(scan_date)}</h1>
174
+ <div class="badge">Your identity attack surface: {_escape(verdict)}</div>
175
+ <div class="meta">Environment: {_escape(report.environment_label)}</div>
176
+ <div class="meta">Scan timestamp: {_escape(report.generated_at)}</div>
177
+ </header>
178
+
179
+ <section class="card">
180
+ <h2>Top 5 Attack Paths</h2>
181
+ <ol>{path_items}</ol>
182
+ </section>
183
+
184
+ <section class="card">
185
+ <h2>Findings</h2>
186
+ <table>
187
+ <thead>
188
+ <tr>
189
+ <th>Severity</th>
190
+ <th>Finding Title</th>
191
+ <th>Source</th>
192
+ <th>Affected Count</th>
193
+ <th>Why this matters</th>
194
+ <th>How to fix</th>
195
+ </tr>
196
+ </thead>
197
+ <tbody>
198
+ {findings_table}
199
+ </tbody>
200
+ </table>
201
+ </section>
202
+
203
+ {warnings_section}
204
+
205
+ <footer>
206
+ <h2>Auditor Verification</h2>
207
+ <p>Signed with Ed25519 — verify with trproof-verify</p>
208
+ <p>SHA-256: {digest}</p>
209
+ <p>Public Key: {public_key_fingerprint}</p>
210
+ </footer>
211
+ </div>
212
+ </body>
213
+ </html>
214
+ """
215
+
216
+ output_path.parent.mkdir(parents=True, exist_ok=True)
217
+ output_path.write_text(document, encoding="utf-8")
218
+ return output_path
219
+
220
+
221
+ # Backwards-friendly alias for older stub name.
222
+ render_html = render_html_report
@@ -0,0 +1,121 @@
1
+ """Ed25519 report signing and verification for TrProof."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import hashlib
7
+ import json
8
+ from pathlib import Path
9
+ from typing import Literal
10
+
11
+ from cryptography.exceptions import InvalidSignature
12
+ from cryptography.hazmat.primitives import serialization
13
+ from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
14
+
15
+ from trproof.models import AssessmentReport
16
+
17
+
18
+ _DEFAULT_KEY_DIR = Path(__file__).resolve().parent.parent / "keys"
19
+ DEFAULT_PRIVATE_KEY_PATH = _DEFAULT_KEY_DIR / "default_ed25519_priv.pem"
20
+ DEFAULT_PUBLIC_KEY_PATH = _DEFAULT_KEY_DIR / "default_ed25519_pub.pem"
21
+
22
+
23
+ def canonical_payload_bytes(report: AssessmentReport) -> bytes:
24
+ data = report.model_dump()
25
+ for field in ("canonical_sha256", "signature_b64", "public_key_b64"):
26
+ data.pop(field, None)
27
+ return json.dumps(
28
+ data, sort_keys=True, separators=(",", ":"), ensure_ascii=False
29
+ ).encode("utf-8")
30
+
31
+
32
+ def _load_private_key(path: Path) -> Ed25519PrivateKey:
33
+ key = serialization.load_pem_private_key(path.read_bytes(), password=None)
34
+ if not isinstance(key, Ed25519PrivateKey):
35
+ raise ValueError("Not an Ed25519 private key")
36
+ return key
37
+
38
+
39
+ def _load_public_key(path: Path) -> Ed25519PublicKey:
40
+ key = serialization.load_pem_public_key(path.read_bytes())
41
+ if not isinstance(key, Ed25519PublicKey):
42
+ raise ValueError("Not an Ed25519 public key")
43
+ return key
44
+
45
+
46
+ def sign_report(
47
+ report: AssessmentReport, private_key_path: Path | None = None
48
+ ) -> AssessmentReport:
49
+ report = report.model_copy(deep=True)
50
+ key_path = private_key_path if private_key_path is not None else DEFAULT_PRIVATE_KEY_PATH
51
+ private_key = _load_private_key(key_path)
52
+
53
+ payload = canonical_payload_bytes(report)
54
+ report.canonical_sha256 = hashlib.sha256(payload).hexdigest()
55
+ signature = private_key.sign(payload)
56
+ report.signature_b64 = base64.b64encode(signature).decode("ascii")
57
+
58
+ public_pem = private_key.public_key().public_bytes(
59
+ encoding=serialization.Encoding.PEM,
60
+ format=serialization.PublicFormat.SubjectPublicKeyInfo,
61
+ )
62
+ report.public_key_b64 = base64.b64encode(public_pem).decode("ascii")
63
+
64
+ return report
65
+
66
+
67
+ def verify_report(
68
+ report_path: Path, public_key_path: Path | None = None
69
+ ) -> tuple[Literal["VALID", "INVALID", "TAMPERED"], str]:
70
+ # Parse JSON
71
+ try:
72
+ report = AssessmentReport.model_validate_json(
73
+ report_path.read_text(encoding="utf-8")
74
+ )
75
+ except Exception:
76
+ return ("INVALID", "Malformed JSON report")
77
+
78
+ try:
79
+ payload = canonical_payload_bytes(report)
80
+ except Exception:
81
+ return ("INVALID", "Malformed report payload")
82
+
83
+ actual_sha256 = hashlib.sha256(payload).hexdigest()
84
+ if actual_sha256 != report.canonical_sha256:
85
+ return ("TAMPERED", "Canonical SHA-256 hash mismatch: report content was modified after signing.")
86
+
87
+ # Determine public keys to check.
88
+ keys_to_check: list[Ed25519PublicKey] = []
89
+ if public_key_path is not None:
90
+ try:
91
+ keys_to_check.append(_load_public_key(public_key_path))
92
+ except Exception:
93
+ return ("INVALID", "Invalid public key PEM")
94
+ else:
95
+ try:
96
+ embedded_key = serialization.load_pem_public_key(
97
+ base64.b64decode(report.public_key_b64)
98
+ )
99
+ if not isinstance(embedded_key, Ed25519PublicKey):
100
+ raise ValueError("Not an Ed25519 public key")
101
+ keys_to_check.append(embedded_key)
102
+ except Exception:
103
+ return ("TAMPERED", "Invalid embedded public key")
104
+ try:
105
+ keys_to_check.append(_load_public_key(DEFAULT_PUBLIC_KEY_PATH))
106
+ except Exception:
107
+ return ("INVALID", "Bundled public key unavailable")
108
+
109
+ # Decode signature
110
+ try:
111
+ signature = base64.b64decode(report.signature_b64, validate=True)
112
+ except Exception:
113
+ return ("TAMPERED", "Invalid signature encoding")
114
+
115
+ for public_key in keys_to_check:
116
+ try:
117
+ public_key.verify(signature, payload)
118
+ except InvalidSignature:
119
+ return ("TAMPERED", "Ed25519 cryptographic signature verification failed.")
120
+
121
+ return ("VALID", f"Verified Ed25519 signature and SHA-256 digest ({actual_sha256[:16]}...).")
@@ -0,0 +1 @@
1
+ """Scoring package (Phase 4+)."""