Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Match a revocation list's distribution point, and report a cut-off chain
Claudeb564f2f63fc2
diff --git a/node_modules b/node_modulesnew file mode 120000index 0000000..e7d71a7--- /dev/null+++ b/node_modules@@ -0,0 +1 @@+/home/user/signudoc/node_modules\ No newline at end of filediff --git a/src/lib/services/pdf-ltv.test.ts b/src/lib/services/pdf-ltv.test.tsindex d0ad8d4..d6698cc 100644--- a/src/lib/services/pdf-ltv.test.ts+++ b/src/lib/services/pdf-ltv.test.ts@@ -583,7 +583,19 @@ function criticalExtension(oid: string, value: Buffer): Buffer {}test("revocation lists that may leave a certificate out are refused", async () => {- const lists: { expect: RegExp | null; extension: Buffer; name: string }[] = [+ /** An issuing distribution point for one address, [0] fullName. */+ const forPoint = (url: string) =>+ criticalExtension(+ "2.5.29.28",+ der.sequence(+ encode(0xa0, encode(0xa0, encode(0x86, Buffer.from(url, "latin1")))),+ ),+ );+ const lists: {+ expect: RegExp | null;+ extension: Buffer | ((crlUrl: string) => Buffer);+ name: string;+ }[] = [{// A delta list only has what changed since its base list.expect: /delta list/,@@ -621,12 +633,28 @@ test("revocation lists that may leave a certificate out are refused", async () =),name: "user certificates only",},+ {+ // A list for another partition of the CA's certificates.+ expect: /distribution point the certificate does not name/,+ extension: () => forPoint("http://127.0.0.1:1/other-partition.crl"),+ name: "another distribution point",+ },+ {+ // The list the certificate points to.+ expect: null,+ extension: (crlUrl) => forPoint(crlUrl),+ name: "the certificate's distribution point",+ },];for (const list of lists) {await withPki(async (pki) => {pki.state.ocspDown = true;- pki.state.crlExtensions = [list.extension];+ pki.state.crlExtensions = [+ typeof list.extension === "function"+ ? list.extension(new URL("/ca.crl", pki.timestampUrl).toString())+ : list.extension,+ ];const data = await collectValidationData(findSignatures(await sealedWith(pki, { timestamp: false })).map(diff --git a/src/lib/services/pdf-ltv.ts b/src/lib/services/pdf-ltv.tsindex caf2f51..c621205 100644--- a/src/lib/services/pdf-ltv.ts+++ b/src/lib/services/pdf-ltv.ts@@ -863,11 +863,35 @@ const KNOWN_CRL_EXTENSIONS = new Set<string>([/*** Refuses a list that may leave out a revoked certificate (RFC 5280, 5.2* and 6.3.3): a delta list, which only has what changed since its base- * list; a list for some reasons only, or for certificates of others (an+ * list; a list for one distribution point that is not one the certificate+ * names; a list for some reasons only, or for certificates of others (an* indirect list); a list for the other kind of certificate (CA or end* entity); and any list with a critical extension this reader does not* know.*/+/**+ * A list for one distribution point covers only the certificates that name+ * it. Its full name must hold an address from the certificate's own CRL+ * distribution points; a name relative to the issuer is not matched.+ */+function assertNamedPoint(body: Buffer, point: Tlv, certificate: Certificate) {+ const name = children(body, point)[0];+ const addresses: string[] = [];++ // DistributionPointName: [0] fullName, or [1] nameRelativeToCRLIssuer.+ if (name && (name.tag & 0x1f) === 0) {+ for (const general of children(body, name)) {+ uriNames(body, general, addresses);+ }+ }++ if (!addresses.some((address) => certificate.crlUrls.includes(address))) {+ throw new LongTermValidationError(+ "The revocation list is for a distribution point the certificate does not name.",+ );+ }+}+function assertCompleteList(body: Buffer,wrapper: Tlv | undefined,@@ -905,6 +929,12 @@ function assertCompleteList(// [1] only user certificates, [2] only CA certificates, [3] only// some reasons, [4] indirect, [5] only attribute certificates.const number = item.tag & 0x1f;++ if (number === 0) {+ assertNamedPoint(body, item, certificate);+ continue;+ }+const set = contentBytes(body, item)[0] !== 0;const isCa = certificate.x509.ca;@@ -1182,6 +1212,12 @@ export async function collectValidationData(}}+ if (queue.some((certificate) => !done.has(certificate.fingerprint))) {+ result.problems.push(+ `Stopped after ${String(MAX_CHAIN_CERTIFICATES)} certificates; the rest were not checked.`,+ );+ }+return result;}