[ 
https://issues.apache.org/jira/browse/PDFBOX-3544?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15608901#comment-15608901
 ] 

Tilman Hausherr commented on PDFBOX-3544:
-----------------------------------------

I didn't test your code change (by your own admission, it doesn't work), I 
looked at what we do: we take the offset at "<" and after the ">" and that one 
is in /ByteRange. So there has to be an adjustment to get the actual 
signatzure. Adobe does the same, see the signed files in PDFBOX-3540. Because 
of that we have to add 1. I agree that this is in contradiction with the 
document you mention - that one sets the offset after the "<".

You can also find a file signed with itext in PDFBOX-1751, and with Adobe in 
PDFBOX-3114.

> Invalid ByteRange for getContents() method
> ------------------------------------------
>
>                 Key: PDFBOX-3544
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3544
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Signing
>    Affects Versions: 2.0.3
>            Reporter: Lonzak
>
> PDSignature.java class, getContents() method, line 325ff.
> {code:title=PDSignature.java|borderStyle=solid}
>     /**
>      * Will return the embedded signature between the byterange gap.
>      *
>      * @param pdfFile The signed pdf file as byte array
>      * @return a byte array containing the signature
>      * @throws IOException if the pdfFile can't be read
>      */
>     public byte[] getContents(byte[] pdfFile) throws IOException
>     {
>         int[] byteRange = getByteRange();
>         int begin = byteRange[0]+byteRange[1]+1;
>         int end = byteRange[2]-begin;
>         return getContents(new COSFilterInputStream(pdfFile,new int[] 
> {begin,end}));
>     }
> {code:}
> Lets asume a byte range of 
> /ByteRange[ 0, 840, 960, 240]
> The current implementation would return
> {841, 119} which is from *841 - 960*
> According to 
> [adobe|http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/DigitalSignaturesInPDF.pdf]
>  (page 5) this is invalid:
> {quote}
> "In this example, the hash is calculated for bytes 0 through 839, and 960 
> through 1200."
> {quote}
> Thus the values for the signature should be
> {840, 119} which is from *840 - 959*
> The implementation should be:
> {code:title=PDSignature.java|borderStyle=solid}
>     /**
>      * Will return the embedded signature between the byterange gap.
>      *
>      * @param pdfFile The signed pdf file as byte array
>      * @return a byte array containing the signature
>      * @throws IOException if the pdfFile can't be read
>      */
>     public byte[] getContents(byte[] pdfFile) throws IOException
>     {
>         int[] byteRange = getByteRange();
>         int begin = byteRange[0]+byteRange[1];
>         int end = byteRange[2]-begin-1;
>         return getContents(new COSFilterInputStream(pdfFile,new int[] 
> {begin,end}));
>     }
> {code:}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to