Skip to content

Commit

Permalink
More careful checking of watermark and nullifier, taking types into a…
Browse files Browse the repository at this point in the history
…ccount
  • Loading branch information
robknight committed Jul 6, 2024
1 parent 59d698c commit 8215588
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/lib/zuauth/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function authenticate(
): Promise<ZKEdDSAEventTicketPCD> {
const serializedPCD = JSON.parse(pcdStr);
if (serializedPCD.type !== ZKEdDSAEventTicketPCDTypeName) {
throw new Error("PCD is malformed or of the incorrect type");
throw new ZuAuthAuthenticationError("PCD is malformed or of the incorrect type");

Check failure on line 63 in packages/lib/zuauth/src/server.ts

View workflow job for this annotation

GitHub Actions / Build-and-Test

Replace `"PCD·is·malformed·or·of·the·incorrect·type"` with `⏎······"PCD·is·malformed·or·of·the·incorrect·type"⏎····`
}

const pcd = await ZKEdDSAEventTicketPCDPackage.deserialize(serializedPCD.pcd);
Expand All @@ -69,12 +69,22 @@ export async function authenticate(
throw new ZuAuthAuthenticationError("ZK ticket PCD is not valid");
}

if (pcd.claim.watermark.toString() !== watermark) {
throw new ZuAuthAuthenticationError("PCD watermark does not match");
// Check if the external nullifier matches
if (externalNullifier !== undefined) {
if (pcd.claim.externalNullifier === undefined) {
throw new ZuAuthAuthenticationError("PCD is missing external nullifier when one was provided");

Check failure on line 75 in packages/lib/zuauth/src/server.ts

View workflow job for this annotation

GitHub Actions / Build-and-Test

Replace `"PCD·is·missing·external·nullifier·when·one·was·provided"` with `⏎········"PCD·is·missing·external·nullifier·when·one·was·provided"⏎······`
}
if (pcd.claim.externalNullifier.toString() !== externalNullifier.toString()) {

Check failure on line 77 in packages/lib/zuauth/src/server.ts

View workflow job for this annotation

GitHub Actions / Build-and-Test

Replace `pcd.claim.externalNullifier.toString()·!==·externalNullifier.toString()` with `⏎······pcd.claim.externalNullifier.toString()·!==·externalNullifier.toString()⏎····`
throw new ZuAuthAuthenticationError(
"External nullifier does not match the provided value"
);
}
} else if (pcd.claim.externalNullifier !== undefined) {
throw new ZuAuthAuthenticationError("PCD contains an external nullifier when none was provided");

Check failure on line 83 in packages/lib/zuauth/src/server.ts

View workflow job for this annotation

GitHub Actions / Build-and-Test

Replace `"PCD·contains·an·external·nullifier·when·none·was·provided"` with `⏎······"PCD·contains·an·external·nullifier·when·none·was·provided"⏎····`
}

if (pcd.claim.externalNullifier?.toString() !== externalNullifier) {
throw new ZuAuthAuthenticationError("External nullfier does not match");

Check failure on line 85 in packages/lib/zuauth/src/server.ts

View workflow job for this annotation

GitHub Actions / Build-and-Test

Delete `··`
if (pcd.claim.watermark !== watermark.toString()) {
throw new ZuAuthAuthenticationError("PCD watermark does not match");
}

// For each of the fields configured to be revealed, check that the claim
Expand Down

0 comments on commit 8215588

Please sign in to comment.