endesive
endesive copied to clipboard
PDF verify only treats the first signature found
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.
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
please check the git version