Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/casepack/validate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Buffer } from "node:buffer";
import {
createPublicKey,
type JsonWebKeyInput,
} from "node:crypto";
import { jwkThumbprint } from "../crypto.js";
import {
isSha256Digest,
} from "../canonical.js";
Expand Down Expand Up @@ -388,8 +385,7 @@ function validatePublicJwk(value: unknown, path: string, issues: ValidationIssue
return false;
}
try {
const key = createPublicKey({ key: value as unknown as JsonWebKeyInput["key"], format: "jwk" });
if (key.asymmetricKeyType !== "ed25519") throw new TypeError("Unexpected key type");
jwkThumbprint(value as unknown as Ed25519PublicJwk);
} catch {
addIssue(issues, path, "MBCP_SCHEMA_INVALID", "External public key is malformed");
return false;
Expand Down
31 changes: 31 additions & 0 deletions test/casepack-v11.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,37 @@ test("caller-pinned external trust verifies a signed source checkpoint without e
assert.equal(report.coverageStatus, "satisfied");
assert.equal(report.nativeBundle.trustChecked, false);

// Identity-point public keys permit R=identity, S=0 without a private key.
// Pinning such a snapshot must not turn this forgery into source evidence.
const identity = Buffer.alloc(32);
identity[0] = 1;
const identitySnapshot = sealExternalTrustSnapshot({
...externalTrustSnapshot,
keys: [{
...externalTrustSnapshot.keys[0],
publicJwk: { kty: "OKP", crv: "Ed25519", x: identity.toString("base64url") },
}],
snapshotDigest: undefined,
});
const forgedCheckpoint = {
...checkpoint,
proofs: [{
...checkpoint.proofs[0],
signature: Buffer.concat([identity, Buffer.alloc(32)]).toString("base64url"),
}],
};
const identityReport = verifyMandateBoundCasePack(
resealPack({
...candidate,
externalTrustSnapshot: identitySnapshot,
sourceCheckpoints: [forgedCheckpoint],
}),
{ ...anchors, externalTrustSnapshotDigest: identitySnapshot.snapshotDigest },
);
assert.equal(identityReport.valid, false);
assert.ok(identityReport.issues.some((issue) =>
issue.code === "MBCP_SCHEMA_INVALID" && issue.path.endsWith(".publicJwk")));

const lateKeySnapshot = sealExternalTrustSnapshot({
...externalTrustSnapshot,
keys: [{
Expand Down
Loading