Replies: 1 comment
-
I'm confused by what you are trying to do here. You are calling Here's why it can't work in a nutshell: PDF signatures are not computed over the input document, but over a "just-in-time" hash based on a "transient" state of the document right before injecting the cryptographic signature. In particular, this happens after all the relevant annotations have been computed. Ordinarily, pyHanko takes control of this process end-to-end (that's what If you precompute a signature and then go through the regular, high-level API from the start, the underlying document will change and you end up putting a wrong signature into the document. Word of advice: try and get your workflow up and running without using interrupted signing first, i.e. just by subclassing |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm trying to sign a pdf file and keep getting "this document has been altered or corrupted....since it was signed" it seems that signed pdf file does not include byterange and i think pyhanko could not set values properly. Timestamp signature's ok, stamp figure's ok on the first page of pdf file. The only issue is user signature on the signed pdf file.
def sign_pdf(input_pdf_path, output_pdf_path, user_cert_pem, signature_bytes, validation_context):
cert_store = SimpleCertificateStore()
user_cert_der = pem_to_der(user_cert_pem)
user_cert_asn1 = asn1_x509.Certificate.load(user_cert_der)
The other script output which is comparing the original file and signed pdf file: Comparing PDFs:
Comparing Page 1:
Differences found on Page 1:
Page 1 Structure:
{'/Contents': {'/Filter': "'/FlateDecode'"}, '/Parent': {'/Count': '1', '/Kids': ['... (depth limit reached)'], '/MediaBox': ['... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)'], '/Type': "'/Pages'"}, '/Resources': {'/Font': {'/F1': '... (depth limit reached)'}, '/ProcSet': ['... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)']}, '/Type': "'/Page'", '/MediaBox': ''}
Page 2 Structure:
{'/Contents': {'/Filter': "'/FlateDecode'"}, '/Parent': {'/Count': '1', '/Kids': ['... (depth limit reached)'], '/MediaBox': ['... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)'], '/Type': "'/Pages'"}, '/Resources': {'/Font': {'/F1': '... (depth limit reached)'}, '/ProcSet': ['... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)', '... (depth limit reached)']}, '/Type': "'/Page'", '/Annots': [{'/FT': '... (depth limit reached)', '/T': '... (depth limit reached)', '/Type': '... (depth limit reached)', '/Subtype': '... (depth limit reached)', '/F': '... (depth limit reached)', '/Rect': '... (depth limit reached)', '/P': '... (depth limit reached)', '/AP': '... (depth limit reached)', '/V': '... (depth limit reached)'}, {'/FT': '... (depth limit reached)', '/T': '... (depth limit reached)', '/Type': '... (depth limit reached)', '/Subtype': '... (depth limit reached)', '/F': '... (depth limit reached)', '/Rect': '... (depth limit reached)', '/P': '... (depth limit reached)', '/TU': '... (depth limit reached)', '/V': '... (depth limit reached)'}], '/MediaBox': ''}
Signature Annotation Structure: {'/FT': '/Sig', '/T': 'Signature', '/Type': '/Annot', '/Subtype': '/Widget', '/F': 132, '/Rect': [100, 100, 200, 150], '/P': IndirectObject(3, 0, 139928584042880), '/AP': {'/N': IndirectObject(21, 0, 139928584042880)}, '/V': IndirectObject(22, 0, 139928584042880)}
Byte range not found.
Beta Was this translation helpful? Give feedback.
All reactions