forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
import { root, run, requireThat } from "./runtime";
|
||||
import { verifyBackendHandover } from "./preflight-build";
|
||||
export async function verifyCheckedRuntime() {
|
||||
const source = await verifyBackendHandover();
|
||||
requireThat(
|
||||
source.count === 112 &&
|
||||
source.sha256 ===
|
||||
"09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609",
|
||||
"CHECKED_RUNTIME_SOURCE_MISMATCH",
|
||||
);
|
||||
const image = "mtuci-vp7-security-app:local",
|
||||
imageID =
|
||||
"sha256:10ba7b17671b785016130f96f781cbee7abb9f8d22ad6ec2e2027bc5eb972e4d";
|
||||
const expected = {
|
||||
app: "37726b99a2b64f888d4cf5a0b72e949ff12318fa5d3a2e162a748573f2a484c0",
|
||||
worker: "9d359b5b6e0a0cbaa515bca37238af9a838c1100cbdd0c698e8d4b500f1f3a3f",
|
||||
"s3-control":
|
||||
"5c6ad096222ade5452574a43c9343ae91dd4d596104f68dac02b15bd6c8837a3",
|
||||
};
|
||||
const buildPath = resolve(root, "evidence/preflight/checked112-build.json"),
|
||||
buildBytes = await readFile(buildPath),
|
||||
build = JSON.parse(buildBytes.toString());
|
||||
const hash = (b: Uint8Array) => createHash("sha256").update(b).digest("hex");
|
||||
requireThat(
|
||||
build.source_handover_sha256 === source.sha256 &&
|
||||
build.source_files_verified === 112 &&
|
||||
Object.entries(expected).every(([p, sha]) => build.binaries[p] === sha),
|
||||
"CHECKED_RUNTIME_BUILD_RECEIPT_MISMATCH",
|
||||
);
|
||||
async function verify() {
|
||||
await source.verify();
|
||||
requireThat(
|
||||
(await readFile(buildPath)).equals(buildBytes),
|
||||
"CHECKED_RUNTIME_BUILD_RECEIPT_CHANGED",
|
||||
);
|
||||
requireThat(
|
||||
hash(await readFile(resolve(root, "scripts/s3-control.go"))) ===
|
||||
build.s3_control_source_sha256,
|
||||
"CHECKED_RUNTIME_HELPER_SOURCE_CHANGED",
|
||||
);
|
||||
const info = JSON.parse(
|
||||
(await run(["docker", "image", "inspect", image])).out,
|
||||
)[0];
|
||||
requireThat(
|
||||
info.Id === imageID &&
|
||||
info.Os === "linux" &&
|
||||
info.Architecture === "amd64",
|
||||
"CHECKED_RUNTIME_IMAGE_CHANGED",
|
||||
);
|
||||
const installed = await run([
|
||||
"docker",
|
||||
"run",
|
||||
"--rm",
|
||||
"--pull=never",
|
||||
"--network",
|
||||
"none",
|
||||
"--entrypoint",
|
||||
"sha256sum",
|
||||
imageID,
|
||||
"/app",
|
||||
"/worker",
|
||||
"/s3-control",
|
||||
]);
|
||||
const lines = installed.out.trim().split("\n");
|
||||
requireThat(lines.length === 3, "CHECKED_RUNTIME_BINARY_OUTPUT_INVALID");
|
||||
const actual: Record<string, string> = {};
|
||||
for (const line of lines) {
|
||||
const m = line.match(/^([a-f0-9]{64})\s+\/(app|worker|s3-control)$/);
|
||||
requireThat(m, "CHECKED_RUNTIME_BINARY_OUTPUT_INVALID");
|
||||
actual[m[2]] = m[1];
|
||||
}
|
||||
requireThat(
|
||||
Object.entries(expected).every(([p, sha]) => actual[p] === sha),
|
||||
"CHECKED_RUNTIME_BINARY_CHANGED",
|
||||
);
|
||||
}
|
||||
await verify();
|
||||
return {
|
||||
image,
|
||||
image_id: imageID,
|
||||
source_sha256: source.sha256,
|
||||
binaries: expected,
|
||||
verify,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user