-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtr_rte.py
More file actions
145 lines (132 loc) · 4.77 KB
/
Copy pathtr_rte.py
File metadata and controls
145 lines (132 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""TR-RTE: Runtime / TEE platform checks (spec §3.1)."""
from __future__ import annotations
import hmac
import re
from typing import Any
from trace_tests.result import Finding, Status
_DIGEST_RE = re.compile(r"^sha(256:[0-9a-f]{64}|384:[0-9a-f]{96})$")
_VALID_PLATFORMS = frozenset(
{
"intel-tdx",
"amd-sev-snp",
# Azure confidential VM: SEV-SNP behind a Hyper-V paravisor (vTPM-rooted).
"azure-cvm-sev-snp",
"nvidia-h100",
"nvidia-blackwell",
"aws-nitro",
"arm-cca",
"google-confidential-space",
"tpm2",
"software-only",
}
)
# Platforms that provide no hardware attestation evidence. Valid only at Level 0.
_DEV_PLATFORMS = frozenset({"software-only"})
def check(
trace: dict[str, Any], level: int = 0, expected_nonce: str | None = None
) -> list[Finding]:
"""Return TR-RTE findings for the runtime / TEE platform claim.
*level* is the conformance level being checked. Development-mode platforms
(e.g. ``software-only``) are accepted at Level 0 but rejected at Level 1+
because they carry no hardware attestation evidence.
"""
findings: list[Finding] = []
runtime = trace.get("runtime")
if not isinstance(runtime, dict):
return [
Finding(
"TR-RTE-001", Status.FAIL, "TR-RTE-001: runtime field is missing or not an object"
)
]
platform = runtime.get("platform")
if isinstance(platform, str) and platform in _DEV_PLATFORMS:
if level == 0:
findings.append(
Finding("TR-RTE-001", Status.PASS, f"runtime.platform is registered ({platform!r})")
)
else:
findings.append(
Finding(
"TR-RTE-001",
Status.FAIL,
f"TR-RTE-001: runtime.platform {platform!r} is development-mode "
"and not acceptable for "
f"hardware-attested levels (Level {level} requires a hardware TEE platform)",
)
)
elif isinstance(platform, str) and platform in _VALID_PLATFORMS:
findings.append(
Finding("TR-RTE-001", Status.PASS, f"runtime.platform is registered ({platform!r})")
)
else:
valid_platforms = sorted(_VALID_PLATFORMS)
findings.append(
Finding(
"TR-RTE-001",
Status.FAIL,
f"TR-RTE-001: runtime.platform {platform!r} is not in the "
f"registered set; valid: {valid_platforms}",
)
)
measurement = runtime.get("measurement", "")
if _DIGEST_RE.match(str(measurement)):
findings.append(
Finding("TR-RTE-002", Status.PASS, "runtime.measurement has valid digest format")
)
else:
findings.append(
Finding(
"TR-RTE-002",
Status.FAIL,
"TR-RTE-002: runtime.measurement must match sha256:<64hex> or "
f"sha384:<96hex>, got {measurement!r}",
)
)
rim_uri = runtime.get("rim_uri")
if rim_uri is None:
findings.append(
Finding("TR-RTE-003", Status.SKIP, "runtime.rim_uri not present (optional)")
)
elif isinstance(rim_uri, str) and rim_uri.startswith("https://"):
findings.append(
Finding("TR-RTE-003", Status.PASS, f"runtime.rim_uri is an https URI ({rim_uri[:60]})")
)
else:
findings.append(
Finding(
"TR-RTE-003",
Status.FAIL,
f"TR-RTE-003: runtime.rim_uri must be an https URI, got {rim_uri!r}",
)
)
if level >= 1:
actual_nonce = runtime.get("nonce")
if not isinstance(expected_nonce, str) or not expected_nonce:
findings.append(
Finding(
"TR-RTE-004",
Status.FAIL,
"TR-RTE-004: Level 1+ verification requires the verifier's expected nonce",
)
)
elif not isinstance(actual_nonce, str) or not actual_nonce:
findings.append(
Finding(
"TR-RTE-004",
Status.FAIL,
"TR-RTE-004: runtime.nonce is missing or empty",
)
)
elif hmac.compare_digest(actual_nonce, expected_nonce):
findings.append(
Finding("TR-RTE-004", Status.PASS, "runtime.nonce matches the verifier challenge")
)
else:
findings.append(
Finding(
"TR-RTE-004",
Status.FAIL,
"TR-RTE-004: runtime.nonce does not match the verifier challenge",
)
)
return findings