endesive icon indicating copy to clipboard operation
endesive copied to clipboard

PDF verify only treats the first signature found

Open AdorianM opened this issue 3 years ago • 2 comments

I was trying to verify a pdf having two signatures. I noticed, though, that the pdf.verify function only looks for the first '/ByteRange' definition, which could lead to missing the other ones (See here)

I would suggest iterating through something like:

re.finditer(b'/ByteRange', pdfdata)

Hope this helps in improving the library.

AdorianM avatar Apr 29 '22 13:04 AdorianM

Here is my code to extra all signature

from PyPDF2 import PdfFileReader
from asn1crypto import cms

pdf_data = PdfFileReader(io.BytesIO(input_data), strict=False)

   fields = pdf_data .getFields()

    for field in fields:

        tree = fields.get(field)

        data = tree.get("/V")

        strimDate = re.findall(r'\d+\+\d\d\'\d\d\'', data["/M"])

        timestamp= datetime.datetime.strptime(strimDate[0].replace("'", ""),'%Y%m%d%H%M%S%z')

        signed_data = cms.ContentInfo.load(data["/Contents"])['content']

Now signed_data is at https://github.com/m32/endesive/blob/482b00a113495dd9b53b1d68698d858d3008882a/endesive/verifier.py#L42

tanthienqn avatar Aug 29 '22 10:08 tanthienqn

please check the git version

m32 avatar Aug 29 '22 11:08 m32