forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { root, run, requireThat, safeFailure } from "./runtime";
|
||||
import { createGitProofProducer, proofHash } from "./git-tracking-proof";
|
||||
import {
|
||||
gitProofSourceSnapshot,
|
||||
gitProofSourceDirectories,
|
||||
gitProofRootFiles,
|
||||
} from "./git-tracking-source";
|
||||
async function main() {
|
||||
requireThat(
|
||||
root === "/Users/rey/mtuci/vp/lab7",
|
||||
"CANONICAL_MAC_GIT_PRODUCER_REQUIRED",
|
||||
);
|
||||
requireThat(
|
||||
(
|
||||
await run(["git", "-C", root, "rev-parse", "--show-toplevel"])
|
||||
).out.trim() === root,
|
||||
"WRONG_CANONICAL_GIT_REPOSITORY",
|
||||
);
|
||||
const proof = await createGitProofProducer({
|
||||
query: async (args) => {
|
||||
const r = await run(args, { allowFailure: true });
|
||||
return { code: r.code, stdout: r.out };
|
||||
},
|
||||
head: async () =>
|
||||
(await run(["git", "-C", root, "rev-parse", "HEAD"])).out.trim(),
|
||||
snapshot: () => gitProofSourceSnapshot(root),
|
||||
})(root);
|
||||
const content = Buffer.from(
|
||||
JSON.stringify(
|
||||
{
|
||||
...proof,
|
||||
source_scope: {
|
||||
kind: "canonical operational source and public contracts",
|
||||
directories: gitProofSourceDirectories,
|
||||
root_files: gitProofRootFiles,
|
||||
excludes:
|
||||
"mutable evidence, submission, private runtime and nonoperational documents",
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
if (Bun.argv.includes("--check")) {
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
state: "PASS_CANONICAL_GIT_SOURCE_CAPTURE_GUARDS",
|
||||
head: proof.head,
|
||||
source_files: Object.keys(proof.files).length,
|
||||
source_generation_sha256: proof.source_generation_sha256,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const path =
|
||||
"evidence/openbao/canonical-git-proof-" + crypto.randomUUID() + ".json";
|
||||
await mkdir(resolve(root, "evidence/openbao"), { recursive: true });
|
||||
await writeFile(resolve(root, path), content, { flag: "wx", mode: 0o644 });
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
path,
|
||||
sha256: proofHash(content),
|
||||
source_files: Object.keys(proof.files).length,
|
||||
source_generation_sha256: proof.source_generation_sha256,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (import.meta.main)
|
||||
try {
|
||||
await main();
|
||||
} catch (error) {
|
||||
safeFailure(error);
|
||||
}
|
||||
Reference in New Issue
Block a user