Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B81BB200BAA for ; Thu, 27 Oct 2016 19:24:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B6C93160AF6; Thu, 27 Oct 2016 17:24:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D329D160AE6 for ; Thu, 27 Oct 2016 19:24:29 +0200 (CEST) Received: (qmail 8095 invoked by uid 500); 27 Oct 2016 17:24:29 -0000 Mailing-List: contact users-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@pdfbox.apache.org Delivered-To: mailing list users@pdfbox.apache.org Received: (qmail 8083 invoked by uid 99); 27 Oct 2016 17:24:28 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Oct 2016 17:24:28 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 359C0180681 for ; Thu, 27 Oct 2016 17:24:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.879 X-Spam-Level: * X-Spam-Status: No, score=1.879 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.com.br Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id pBLvuJYb8QsI for ; Thu, 27 Oct 2016 17:24:25 +0000 (UTC) Received: from nm17-vm2.bullet.mail.ne1.yahoo.com (nm17-vm2.bullet.mail.ne1.yahoo.com [98.138.91.93]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id CA3435F484 for ; Thu, 27 Oct 2016 17:24:24 +0000 (UTC) Received: from [98.138.100.115] by nm17.bullet.mail.ne1.yahoo.com with NNFMP; 27 Oct 2016 17:24:23 -0000 Received: from [98.138.87.4] by tm106.bullet.mail.ne1.yahoo.com with NNFMP; 27 Oct 2016 17:24:23 -0000 Received: from [127.0.0.1] by omp1004.mail.ne1.yahoo.com with NNFMP; 27 Oct 2016 17:24:23 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 39040.67862.bm@omp1004.mail.ne1.yahoo.com X-YMail-OSG: FRF_3q4VM1m05kfuybh3aO5iB7s1UZo3plN6OrOx1kMgcadHA8oSLaPLQydBDg8 198KbjWO_wz1mqgT8ajXcqpUST6TlrFRm1hNvUy5a..Bf73v9fctqXqIGvx1otXpcd0l_UvbI0HG KFbe.wwyFsp2O1TW819GKUygj4x3nlv3hvFahl7yqfTZwXMWXLq36gzpkj_hX01GYlC9nuZsXIfZ in2DkhDv22qx56X0L_IBK9uD5LQrzQXCetY1iXUAhzMoH60olaia7lDTUhDISj7Lc.7bCMvJnPHu XqePBjjfNkwpKAqimZLtJ1lepgQ_VvoAPa9yJ49iMfcH1CBhbVSP67v0rWOhCdV0M_MfbKRfo7Wm SZKniQYI3or8wC7n.wqJP._ExLu8YP14zfE5ZcOgclm1kA0PkMuov6N.zlbn41m3yt6eo3XQBDvT n7GuLUIp4RCzIhhpErxRBGE.eaamzxBj2fo0YpNSkLziMRkJxVOo8Pvoj1NbHYH8uTNzeu9NX55Y zghMQOj_QllKBL6Wlgtr5MkcDAnP7lioN3RfERQ-- Received: from jws200032.mail.ne1.yahoo.com by sendmailws153.mail.ne1.yahoo.com; Thu, 27 Oct 2016 17:24:22 +0000; 1477589062.672 Date: Thu, 27 Oct 2016 17:24:21 +0000 (UTC) From: Fabricio Pombo Koch Reply-To: Fabricio Pombo Koch To: "users@pdfbox.apache.org" Message-ID: <1683543358.2333028.1477589061617@mail.yahoo.com> In-Reply-To: <44e8ecbb-1b17-5aa6-eba2-b8693cb30a77@t-online.de> References: <551227248.2099264.1477574322310.ref@mail.yahoo.com> <551227248.2099264.1477574322310@mail.yahoo.com> <44e8ecbb-1b17-5aa6-eba2-b8693cb30a77@t-online.de> Subject: Re: External signature in 2 steps MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2333027_2140332234.1477589061612" archived-at: Thu, 27 Oct 2016 17:24:30 -0000 ------=_Part_2333027_2140332234.1477589061612 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Tilman, I'm gonna try it. And I'm sorry about the indentation of my last e-mail. Thank you again!Fabricio P Koch=20 Em Quinta-feira, 27 de Outubro de 2016 14:49, Tilman Hausherr escreveu: =20 Am 27.10.2016 um 15:18 schrieb Fabricio Pombo Koch: > Tilman, thanks for your reply. > I'm not familiarized with PDF structure, this way, I don't know how to in= sert the signature manually into the PDF. > This code works for me to sign in "one step": > File inFile =3D new File("IN_PDF_FILE");PDDocument doc =3D PDDocument.loa= d(inFile);PDSignature signature =3D new PDSignature();signature.setFilter(P= DSignature.FILTER_ADOBE_PPKLITE);signature.setSubFilter(PDSignature.SUBFILT= ER_ADBE_PKCS7_DETACHED);signature.setName("USERNAME");signature.setLocation= ("LOCATION");signature.setReason("TESTING");doc.addSignature(signature);Fil= e outFile =3D new File("OUT_PDF_FILE");FileOutputStream fos =3D new FileOut= putStream(outFile);ExternalSigningSupport externalSigning =3D doc.saveIncre= mentalForExternalSigning(fos);MessageDigest digest =3D MessageDigest.getIns= tance("SHA-256");byte[] content=3D IOUtils.toByteArray(externalSigning.getC= ontent());byte[] hash =3D digest.digest(content);externalSigning.setSignatu= re(VALUE_RETURNED_FROM_MY_SIGNATURE_SERVICE);doc.close(); > > But, I can't=C2=A0 run the following line because I recieve the "VALUE_RE= TURNED_FROM_MY_SIGNATURE_SERVICE" value in a future time:externalSigning.se= tSignature(VALUE_RETURNED_FROM_MY_SIGNATURE_SERVICE); > So, I tried using all that code, except the "externalSigning.setSignature= " method. Then, in my 2nd step, I wrote it all again (from PDDocumento.load= () until doc.close()).It sign the file, but the signature is invalid. What you have to do is to access the PDF file, seek to the appropriate=20 position, and then write the hex string of your signature. If the byterange is 0 61887 65989 21205 then go to 61888, and write there. To get the byte range, as I explained yesterday, you need to access the=20 PDF file with PDFBox again earlier but after the (unfinished) "signing",=20 get the field (you know its name), and then the signature, then the=20 ByteRange ( signature.getByteRange() ). Close again. So: 1) unfinished sign, close 2) reload with pdfbox to get the byte range, close 3) reload with random access class, access appropriate position, write=20 sig in ascii hex, close I can't give much help now because I'm busy until mid next week. Tilman > > It would be nice If you create the new feature.Meanwhile, how could I add= the signature manually? I have no idea. > > Thanks,Fabricio P Koch > > -------------------------------------------------------------------------= -------------------------------------------------- > > From: Tilman Hausherr Subject: Re: External signature i= n 2 stepsDate: 2016-10-26 18:43 (-0200)List: users@pdfbox.apache.orgAm 26.1= 0.2016 um 21:53 schrieb Fabricio Pombo Koch:show/hide original textYou woul= d have to use the new "external" strategy that exists since 2.0.3, but with= out writing the signature. Before closing, get the ByteRange from the signa= ture object. > HOWEVER... that one isn't available, because after being calculated the B= yteRange isn't assigned back to the PDFBox structure. > (Open a signed PDF with NOTEPAD++ and search for ByteRange to understand = what II mean) > So you'd have to reload the PDF; get the field (you know its name), and t= hen the signature, then the ByteRange ( signature.getByteRange() ). Close a= gain. > Then write the signature that you got at the appropriate place in the fil= e. This can be done without PDFBox. > I could do a change that you can access the byte range, i.e. don't have t= o reload the PDF just to get the byte range. However this will have to wait= until mid next week, because I wouldn't have the time to become active if = it doens't work. (Although I just tested it). > Tilman > ---------------------------------------------------------------------To u= nsubscribe, e-mail: users-unsubscribe@pdfbox.apache.orgFor additional comma= nds, e-mail: users-help@pdfbox.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org For additional commands, e-mail: users-help@pdfbox.apache.org =20 ------=_Part_2333027_2140332234.1477589061612--