Skip to content

Commit ab6a293

Browse files
committed
[red] Require exact firmware source for audited beta
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent a9b54e9 commit ab6a293

2 files changed

Lines changed: 105 additions & 16 deletions

File tree

‎tools/web/src/test/firmware-staging.test.ts‎

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe("external firmware bundle staging", () => {
117117
join(
118118
outputDirectory,
119119
"firmware",
120-
"v0.4.1",
120+
"v0.4.2",
121121
"esp32-s3-n16r8",
122122
"manifest.json",
123123
),
@@ -128,14 +128,14 @@ describe("external firmware bundle staging", () => {
128128
join(
129129
outputDirectory,
130130
"firmware",
131-
"v0.4.1",
131+
"v0.4.2",
132132
"esp32-s3-n16r8",
133133
"firmware.bin",
134134
),
135135
).then((value) => Array.from(value)),
136136
).resolves.toEqual(Array.from(fixture.firmwareBytes));
137137
await expect(
138-
readdir(join(outputDirectory, "firmware", "v0.4.1")),
138+
readdir(join(outputDirectory, "firmware", "v0.4.2")),
139139
).resolves.not.toContain("esp32-c3-4mb");
140140
expect(fixture.descriptor.profiles.map(({ id }) => id)).toEqual([
141141
"esp32-4mb",
@@ -164,7 +164,7 @@ describe("external firmware bundle staging", () => {
164164
accessControlled: true,
165165
deployment: "candidate",
166166
hilStatus: "pending",
167-
version: "0.4.1",
167+
version: "0.4.2",
168168
});
169169
await expect(
170170
stageFixture({
@@ -205,7 +205,7 @@ describe("external firmware bundle staging", () => {
205205
accessControlled: false,
206206
deployment: "public-beta",
207207
hilStatus: "pending",
208-
version: "0.4.1",
208+
version: "0.4.2",
209209
});
210210
await expect(
211211
validatePreservedPublicFirmwareRelease(stagedRoot, {
@@ -242,7 +242,7 @@ describe("external firmware bundle staging", () => {
242242

243243
await expect(
244244
validateAttestedPublicBetaBundle(bundleDirectory, "public-beta"),
245-
).rejects.toThrow(/attested.*v0\.4\.1/i);
245+
).rejects.toThrow(/audited.*v0\.4\.2/i);
246246
});
247247

248248
it("rejects external bytes that no longer match the generated bundle checksums", async () => {
@@ -633,6 +633,85 @@ describe("external firmware bundle staging", () => {
633633
.toBe(repositoryRoot);
634634
});
635635

636+
it("runs a public beta through the canonical audited-candidate and license gates", async () => {
637+
const stagingScript = join(
638+
process.cwd(),
639+
"scripts",
640+
"stage-firmware-release.js",
641+
);
642+
const bundleDirectory = await temporaryDirectory(
643+
"public-beta-audit-bundle",
644+
);
645+
const licenseEvidenceDirectory = await temporaryDirectory(
646+
"public-beta-license-evidence",
647+
);
648+
const licenseBuildRoot = await temporaryDirectory(
649+
"public-beta-license-build",
650+
);
651+
const firmwareSourceRoot = await temporaryDirectory(
652+
"public-beta-source-root",
653+
);
654+
const fakeBin = await temporaryDirectory("public-beta-validator-bin");
655+
const fakePython = join(fakeBin, "python3");
656+
const captureFile = join(fakeBin, "public-beta-arguments.txt");
657+
await writeFile(
658+
fakePython,
659+
[
660+
"#!/bin/sh",
661+
'printf "%s\\n" "$@" > "${PYBLE_TEST_VALIDATOR_CAPTURE}"',
662+
"",
663+
].join("\n"),
664+
"utf8",
665+
);
666+
await chmod(fakePython, 0o755);
667+
668+
const validationProgram = [
669+
`const staging = await import(${JSON.stringify(pathToFileURL(stagingScript).href)});`,
670+
`await staging.validateWithCanonicalReleaseTool(${JSON.stringify(bundleDirectory)}, "public-beta");`,
671+
].join("\n");
672+
const baseEnvironment: NodeJS.ProcessEnv = {
673+
...process.env,
674+
PATH: `${fakeBin}:${process.env.PATH ?? ""}`,
675+
PYBLE_TEST_VALIDATOR_CAPTURE: captureFile,
676+
};
677+
delete baseEnvironment.PYBLE_FIRMWARE_LICENSE_EVIDENCE_DIR;
678+
delete baseEnvironment.PYBLE_FIRMWARE_LICENSE_BUILD_ROOT;
679+
delete baseEnvironment.PYBLE_FIRMWARE_SOURCE_ROOT;
680+
681+
await expect(
682+
execFile(
683+
process.execPath,
684+
["--input-type=module", "--eval", validationProgram],
685+
{ cwd: process.cwd(), env: baseEnvironment },
686+
),
687+
).rejects.toThrow();
688+
689+
await execFile(
690+
process.execPath,
691+
["--input-type=module", "--eval", validationProgram],
692+
{
693+
cwd: process.cwd(),
694+
env: {
695+
...baseEnvironment,
696+
PYBLE_FIRMWARE_LICENSE_BUILD_ROOT: licenseBuildRoot,
697+
PYBLE_FIRMWARE_LICENSE_EVIDENCE_DIR: licenseEvidenceDirectory,
698+
PYBLE_FIRMWARE_SOURCE_ROOT: firmwareSourceRoot,
699+
},
700+
},
701+
);
702+
const arguments_ = (await readFile(captureFile, "utf8"))
703+
.trimEnd()
704+
.split("\n");
705+
expect(arguments_).toContain("--audited-candidate");
706+
expect(arguments_).not.toContain("--public");
707+
expect(arguments_).toContain("--license-evidence-dir");
708+
expect(arguments_).toContain("--license-build-root");
709+
expect(arguments_).toContain("--repo-root");
710+
expect(arguments_[arguments_.indexOf("--repo-root") + 1]).toBe(
711+
firmwareSourceRoot,
712+
);
713+
});
714+
636715
it("leaves no finalized version or selector when final staged-root validation fails", async () => {
637716
const fixture = createFirmwareReleaseFixture();
638717
const realBundleDirectory = await temporaryDirectory("real-release-bundle");
@@ -693,7 +772,7 @@ describe("external firmware bundle staging", () => {
693772
).resolves.toEqual(descriptor);
694773

695774
await writeFile(
696-
join(stagedRoot, "firmware", "v0.4.1", "release.json"),
775+
join(stagedRoot, "firmware", "v0.4.2", "release.json"),
697776
new Uint8Array([0x7b, 0x7d, 0x0a]),
698777
);
699778
await expect(

‎tools/web/src/test/vps-deployment-contract.test.ts‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ describe("Cloudflare-fronted VPS deployment", () => {
8989
expect(headers).toContain("Strict-Transport-Security");
9090
});
9191

92-
it("routes the exact v0.4.1 public beta through the immutable firmware boundary", async () => {
92+
it("routes the exact v0.4.2 public beta through the immutable firmware boundary", async () => {
9393
const config = await readFile(
9494
join(deploymentRoot, "nginx", "10-pyble-dev-https.conf"),
9595
"utf8",
9696
);
97-
expect(config).not.toContain("location ^~ /firmware/v0.4.1/");
97+
expect(config).not.toContain("location ^~ /firmware/v0.4.2/");
9898
expect(config).not.toContain("@burned_firmware_candidate");
9999
expect(config).toMatch(
100100
/location \^~ \/firmware\/\s*\{[\s\S]*?alias \/srv\/pyble\/firmware\//,
@@ -154,19 +154,29 @@ describe("Cloudflare-fronted VPS deployment", () => {
154154
});
155155

156156
it("accepts only the exact unrestricted pending public beta in the activation path", async () => {
157-
const script = await readFile(
158-
join(deploymentRoot, "vps", "deploy.sh"),
159-
"utf8",
160-
);
157+
const [script, staging] = await Promise.all([
158+
readFile(join(deploymentRoot, "vps", "deploy.sh"), "utf8"),
159+
readFile(
160+
join(process.cwd(), "scripts", "stage-firmware-release.js"),
161+
"utf8",
162+
),
163+
]);
161164

162165
expect(script).toContain('descriptor.deployment === "public-beta"');
163166
expect(script).toContain('descriptor.hilStatus === "pending"');
164167
expect(script).toContain("descriptor.accessControlled === false");
165168
expect(script).toContain(
166-
"8b84fbb65a0463d20369e1d86dac566ca7a2039ebc30f9186f55c05421962445",
169+
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
167170
);
168-
expect(script).toMatch(
169-
/public-beta[\s\S]*?(?:skip|does not require)[\s\S]*?annotated tag/i,
171+
expect(staging).toMatch(
172+
/public-beta[\s\S]*?--audited-candidate[\s\S]*?--license-evidence-dir[\s\S]*?--license-build-root/,
173+
);
174+
expect(script).toContain("PYBLE_FIRMWARE_LICENSE_EVIDENCE_DIR");
175+
expect(script).toContain("PYBLE_FIRMWARE_LICENSE_BUILD_ROOT");
176+
expect(script).toContain("PYBLE_FIRMWARE_SOURCE_ROOT");
177+
expect(script).toContain("local_firmware_tag_object_before_build");
178+
expect(script).not.toMatch(
179+
/public-beta[\s\S]{0,180}(?:skip|does not require)[\s\S]{0,180}annotated tag/i,
170180
);
171181
});
172182

0 commit comments

Comments
 (0)