Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | 4x 4x 92x 92x 92x 25x 25x 36x 12x 13x 13x 13x 7x 13x 13x 7x 50x 13x 110x 13x 2x 2x 2x 2x 13x 78x 2x 1x 22x 88x 92x | "use client";
import { useMemo, useState } from "react";
import { Lock } from "lucide-react";
import { PolicyHash } from "@/components/spe/SpeBadges";
import {
ADR_068_URL,
SPE_EVENT_LABELS,
SPE_EVENT_TYPES,
formatSpeTime,
speEventLabel,
type SpeAuditEvent,
type SpeEventType,
type SpeOptOutCounts,
} from "@/lib/spe";
import { useT } from "@/lib/i18n/translate";
const EVENT_CLASSES: Record<string, string> = {
"spe.attestation":
"bg-(--role-holder-bg) text-(--role-holder-text) border border-(--role-holder-border)",
"spe.key_release":
"bg-(--role-user-bg) text-(--role-user-text) border border-(--role-user-border)",
"spe.key_refused":
"bg-(--role-admin-bg) text-(--role-admin-text) border border-(--role-admin-border)",
"spe.workspace_loaded":
"bg-(--role-trust-bg) text-(--role-trust-text) border border-(--role-trust-border)",
"spe.workspace_destroyed":
"bg-(--surface-2) text-(--text-secondary) border border-(--border)",
"spe.optout_synced":
"bg-(--role-patient-bg) text-(--role-patient-text) border border-(--role-patient-border)",
};
function SimulatedMarker({ simulated }: { simulated: boolean | null }) {
const t = useT("admin");
Iif (simulated === null) {
return <span className="text-(--text-secondary)">{t("unknown")}</span>;
}
return simulated ? (
<span className="text-(--warning-text) font-semibold">
{t("Simulated")}
</span>
) : (
<span className="text-(--success-text) font-semibold">{t("Hardware")}</span>
);
}
/** "1 added, 0 removed, 6 opted out in the hub", in the picker's language. */
export function useOptOutText() {
const t = useT("admin");
return (c: SpeOptOutCounts) => {
const n = (v: number | null) => (v === null ? "?" : String(v));
return t("{added} added, {removed} removed, {inHub} opted out in the hub", {
added: n(c.added),
removed: n(c.removed),
inHub: n(c.inHub),
});
};
}
/**
* The "Secure processing" group of the audit trail (#774): attestations, key
* releases and refusals, workspaces loaded and destroyed, each with the
* evidence summary the proxy recorded on the ADR-045 chain.
*/
export function SpeAuditSection({ events }: { events: SpeAuditEvent[] }) {
const t = useT("admin");
const optOutText = useOptOutText();
const [shown, setShown] = useState<Set<SpeEventType>>(
() => new Set(SPE_EVENT_TYPES),
);
const [speId, setSpeId] = useState("");
const speIds = useMemo(
() =>
[
...new Set(events.map((e) => e.speId).filter(Boolean) as string[]),
].sort(),
[events],
);
const visible = events.filter(
(e) =>
(!(SPE_EVENT_TYPES as readonly string[]).includes(e.eventType) ||
shown.has(e.eventType as SpeEventType)) &&
(!speId || e.speId === speId),
);
const toggle = (type: SpeEventType) =>
setShown((prev) => {
const next = new Set(prev);
if (next.has(type)) next.delete(type);
else Enext.add(type);
return next;
});
return (
<section className="mb-8" data-testid="spe-audit-section">
<h2 className="font-semibold text-sm mb-1 flex items-center gap-2">
<Lock size={14} className="text-(--layer5-text)" aria-hidden="true" />
{t("Secure processing")}
<span className="text-xs font-normal text-(--text-secondary)">
({t("{n} of {total}", { n: visible.length, total: events.length })})
</span>
</h2>
<p className="text-xs text-(--text-secondary) mb-3">
{t(
"Attestation and key release for each SPE workspace, and the Art. 71 opt-outs pushed into it (counts only), appended to the audit chain (ADR-045). What each label proves:",
)}{" "}
<a
href={ADR_068_URL}
target="_blank"
rel="noopener noreferrer"
className="text-(--accent) hover:underline"
>
ADR-068
</a>
.
</p>
<fieldset
aria-label={t("Secure processing event types")}
className="flex flex-wrap items-center gap-2 p-3 mb-4 bg-(--surface) border border-(--border) rounded-lg text-xs"
>
<legend className="sr-only">
{t("Secure processing event types")}
</legend>
{SPE_EVENT_TYPES.map((type) => (
<label
key={type}
className="flex items-center gap-1.5 px-2 py-1 rounded-sm border border-(--border) cursor-pointer"
>
<input
type="checkbox"
checked={shown.has(type)}
onChange={() => toggle(type)}
className="w-3.5 h-3.5"
/>
{t(SPE_EVENT_LABELS[type])}
</label>
))}
{speIds.length > 1 && (
<select
aria-label={t("SPE")}
value={speId}
onChange={(e) => setSpeId(e.target.value)}
className="bg-(--surface-2) border border-(--border) rounded-sm px-2 py-1 text-(--text-primary)"
>
<option value="">{t("All SPEs")}</option>
{speIds.map((id) => (
<option key={id} value={id}>
{id}
</option>
))}
</select>
)}
</fieldset>
{visible.length === 0 ? (
<p className="text-sm text-(--text-secondary)">
{t("No secure processing events recorded")}
</p>
) : (
<div className="overflow-x-auto border border-(--border) rounded-xl">
<table className="w-full text-left text-xs">
<thead>
<tr className="border-b border-(--border) bg-(--surface)/60">
{[
t("Recorded"),
t("Event"),
t("SPE"),
t("Permit"),
t("Policy hash"),
t("TEE"),
t("Scope"),
t("Evidence"),
].map((h) => (
<th
key={h}
className="py-2 px-3 font-medium text-(--text-secondary)"
>
{h}
</th>
))}
</tr>
</thead>
<tbody>
{visible.map((e) => (
<tr
key={e.id}
className="border-b border-(--border) hover:bg-(--surface-2)/40"
>
<td className="py-2 px-3 whitespace-nowrap text-(--text-secondary)">
{e.recorded ? formatSpeTime(e.recorded) : t("not yet")}
</td>
<td className="py-2 px-3">
<span
title={e.eventType}
className={`inline-block px-1.5 py-0.5 rounded-sm text-[10px] font-semibold ${
EVENT_CLASSES[e.eventType] ??
"bg-(--surface-2) text-(--text-secondary)"
}`}
>
{t(speEventLabel(e.eventType))}
</span>
{e.optOut && (
<span className="block mt-0.5 text-[10px] text-(--text-secondary)">
{optOutText(e.optOut)}
</span>
)}
</td>
<td className="py-2 px-3 font-semibold text-(--text-primary)">
{e.speId ?? t("unknown")}
</td>
<td className="py-2 px-3 font-mono text-[11px]">
{e.permitId ?? t("none")}
</td>
<td className="py-2 px-3">
<PolicyHash hash={e.policyHash} />
</td>
<td className="py-2 px-3">{e.teeType ?? t("unknown")}</td>
<td className="py-2 px-3">
{e.attestationScope ?? t("unknown")}
</td>
<td className="py-2 px-3">
<SimulatedMarker simulated={e.simulated} />
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</section>
);
}
|