How to check if a PDF has any digital signature

I need to understand if there is any digital signature in the PDF. I have to manage huge PDF files, for example. 500 MB each, so I just need to find a way to separate the unsigned from the signed (so that I can only send signed PDFs to a method that manages them). Any procedure found so far includes an attempt to extract the certificate through, for example, Bouncycastle libs (in my case, for Java): if it is present, the PDF is signed if it is not present or an exception is raised, is it (sic!). But this is obviously a time / memory consumption, besides the resource implementation example.

Is there any quick way independent of the language, for example. open a PDF file and read the first bytes and search for information indicating that the file is signed? Alternatively, is there a reference guide that details how to do it inside a PDF?

Thank you in advance

+4
source share
2 answers

You will want to use the PDF library instead of trying to implement all this yourself, otherwise you will get bogged down in processing variations of linearized documents, filters, incremental updates, object streams, cross-reference streams and more.

; , , Adobe ISO 32000: 2008 , PDF v1.7 ISO- .

, PDF v1.7 8,7 ( ), 3.6.1 ( ) 8.6 ( ).

:

  • "Perms" "AcroForm".
  • "" "DocMDP", "UR" "UR3". , , , , Reader.
  • "AcroForm"; (, "XFA", , Porgy Bess: !). , () "SigFlags", . "", "FT" ( ), "Sig" (), "V" (Value), .

PDF, , , , .

+2

, ... "Sigflags" :

grep -m1 "/Sigflags" ${PDF_FILE}

:

grep -r --include=*.pdf -m1 -l "/Sigflags" . > signed_pdfs.txt

grep -r --include=*.pdf -m1 -L "/Sigflags" . > non_signed_pdfs.txt

Grep . ( .txt) .

, , . "".

, /Sigflags, , .

, ( ), , , .

peepdf, . . :

 $ peepdf -C "search /SigFlags" signed.pdf 

   [6]

  $ peepdf -C "search /SigFlags" non-signed.pdf 

    Not found!!

. PDF, PDF v1.7 Reference. PDF.

+1

Source: https://habr.com/ru/post/1664679/


All Articles