If I change the document through PDFBox, both Adobe Reader & PDFBox will detect the broken signature. If I change the document with an Adobe product (Adobe Illustrator in this case) Adobe will report signature as broken
This happens because there are two fundamental ways to re-save an existing PDF with changes:
- you can save all the objects of the changed PDF in a new file as-is; or
- you can append only the changed objects to (a copy of) the original file.
(For more details, also actual some seldom-used in-between technique, confer this answer.)
In the former case a signature from the original file is broken for good, it usually is not at the same offset in the PDF anymore and the signed bytes definitively have changed.
In the latter case such a signature still mathematically correctly signs the signed bytes as nothing has changed in the first part of the file (the copy of the original file). In such a case, though, only certain changes are considered allowed, cf. this answer.
(For some backgrounds on signing, incremental updates, and revisions confer this answer.)
PDF files changed by PDFBox (at least if saved as you do) are an example of the former case.
PDF files changed by Adobe Illustrator (at least if originally signed) are an example of the latter case.
The ShowSignature class only checks whether the signature still mathematically correctly signs its signed bytes. It signals the existence of changes as added in the latter case by an output of
Signature does not cover whole document
but it does not analyze whether those added changes are allowed or not.
Adobe Reader checks both the signature for mathematical correctness and the added changes for being allowed.
Consequently ShowSignature will not complain (merely hint at the existence of changes) while Adobe Reader will complain when confronted with your tampered.pdf file.
The reason why PDFBox (just like most (all?) other non-Adobe PDF libraries) don't check for allowed and disallowed appended changes is that this is highly non-trivial:
If you read the answer on allowed and dis-allowed changes already referenced above, you'll see that the descriptions are fairly abstract, they deal with visible objects presented by PDF viewers and not with data objects inside PDFs. Unfortunately, though, there are many different ways (in terms of data objects inside PDFs) to do the allowed changes (expressed in terms of visible objects presented by PDF viewers), so it's extremely difficult to judge in general whether a given change is allowed.
Even the analysis of changes in Adobe Reader is not perfect: Adobe for some changes only considers them allowed if they are done similarly as Adobe software would have done them.