From cdb06ecc42fa80fc27828de93f5a8f350d1dca6a Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Mon, 1 Feb 2021 16:02:34 +0100 Subject: [PATCH] getPDFSignatureCount: also handle handy-signatur.at blocks Turns out they use a sightly different format. Make the regex to find them less specific so it gets detected as well. --- src/utils.js | 4 ++-- test/unit.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 98796e2..67f4f4e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -111,8 +111,8 @@ export const readBinaryFileContent = async (file) => { */ export const getPDFSignatureCount = async (file) => { const sigRegex = new RegExp( - "/Type\\s*/Sig\\s*/Filter\\s*/Adobe.PPKLite\\s*/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)", - "g"); + "/Type\\s*/Sig.*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)", + "gs"); const content = await readBinaryFileContent(file); let matches = 0; while (sigRegex.exec(content) !== null) { diff --git a/test/unit.js b/test/unit.js index 6038335..8959860 100644 --- a/test/unit.js +++ b/test/unit.js @@ -47,11 +47,15 @@ suite('pdf signature detection', () => { } test('getPDFSignatureCount', async () => { + // Produced via pdf-as-web let sig1 = "/Type\n/Sig\n/Filter\n/Adobe.PPKLite\n/SubFilter\n/ETSI.CAdES.detached"; let sig2 = "/Type\n/Sig\n/Filter\n/Adobe.PPKLite\n/SubFilter\n/adbe.pkcs7.detached"; + // Produced via https://www.handy-signatur.at + let sig3 = "/Type /Sig\n/Name (Max Meier)\n/Location ()\n/Reason ()\n/M (D:20210201154123+01'00')\n/Filter /asign.ECDSA\n/SubFilter /ETSI.CAdES.detached"; assert(await getPDFSignatureCount(getPDFFile(sig1)) === 1); assert(await getPDFSignatureCount(getPDFFile(sig2)) === 1); + assert(await getPDFSignatureCount(getPDFFile(sig3)) === 1); assert(await getPDFSignatureCount(getPDFFile(sig1 + sig2)) === 2); assert(await getPDFSignatureCount(getPDFFile("foo" + sig1 + "bar" + sig2 + "quux")) === 2); assert(await getPDFSignatureCount(getPDFFile("\nfoo" + sig1 + "bar\n")) === 1); -- GitLab