Skip to content
Snippets Groups Projects
Commit cdb06ecc authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

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.
parent 870f3520
Branches
No related tags found
No related merge requests found
Pipeline #16397 failed
...@@ -111,8 +111,8 @@ export const readBinaryFileContent = async (file) => { ...@@ -111,8 +111,8 @@ export const readBinaryFileContent = async (file) => {
*/ */
export const getPDFSignatureCount = async (file) => { export const getPDFSignatureCount = async (file) => {
const sigRegex = new RegExp( const sigRegex = new RegExp(
"/Type\\s*/Sig\\s*/Filter\\s*/Adobe.PPKLite\\s*/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)", "/Type\\s*/Sig.*?/SubFilter\\s*(/ETSI\\.CAdES\\.detached|/adbe\\.pkcs7\\.detached)",
"g"); "gs");
const content = await readBinaryFileContent(file); const content = await readBinaryFileContent(file);
let matches = 0; let matches = 0;
while (sigRegex.exec(content) !== null) { while (sigRegex.exec(content) !== null) {
......
...@@ -47,11 +47,15 @@ suite('pdf signature detection', () => { ...@@ -47,11 +47,15 @@ suite('pdf signature detection', () => {
} }
test('getPDFSignatureCount', async () => { 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 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"; 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(sig1)) === 1);
assert(await getPDFSignatureCount(getPDFFile(sig2)) === 1); assert(await getPDFSignatureCount(getPDFFile(sig2)) === 1);
assert(await getPDFSignatureCount(getPDFFile(sig3)) === 1);
assert(await getPDFSignatureCount(getPDFFile(sig1 + sig2)) === 2); assert(await getPDFSignatureCount(getPDFFile(sig1 + sig2)) === 2);
assert(await getPDFSignatureCount(getPDFFile("foo" + sig1 + "bar" + sig2 + "quux")) === 2); assert(await getPDFSignatureCount(getPDFFile("foo" + sig1 + "bar" + sig2 + "quux")) === 2);
assert(await getPDFSignatureCount(getPDFFile("\nfoo" + sig1 + "bar\n")) === 1); assert(await getPDFSignatureCount(getPDFFile("\nfoo" + sig1 + "bar\n")) === 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment