From af90012c848711a4c9010dbcf71694dbfbca0e86 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 10 Jul 2014 12:09:05 +0200 Subject: Integrity verification of Signature after Signature creation to ensure correct signed Document --- .../main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pdf-as-legacy/src/main/java/at/gv/egiz') diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java index 9ed02053..bef3b01f 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java @@ -59,6 +59,7 @@ import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; import at.gv.egiz.pdfas.lib.impl.SignaturePositionImpl; +import at.gv.egiz.pdfas.lib.impl.StatusRequestImpl; public class PdfAsObject implements PdfAs { @@ -82,14 +83,22 @@ public class PdfAsObject implements PdfAs { } SignatureDetailInformationWrapper sdi = (SignatureDetailInformationWrapper) signatureDetailInformation; - StatusRequest request = sdi.getStatus(); + StatusRequest statusRequest = sdi.getStatus(); + + if (!(statusRequest instanceof StatusRequestImpl)) { + throw new PdfAsException(ErrorCode.SIGNATURE_COULDNT_BE_CREATED, + "Invalid state"); + } + StatusRequestImpl request = (StatusRequestImpl) statusRequest; + if (request.needSignature()) { try { byte[] signature = sdi.wrapper.getSignParameter4().getPlainSigner().sign( - request.getSignatureData(), request.getSignatureDataByteRange(), sdi.wrapper.getSignParameter4()); + request.getSignatureData(), request.getSignatureDataByteRange(), sdi.wrapper.getSignParameter4(), + request.getStatus().getRequestedSignature()); request.setSigature(signature); - request = this.pdfas4.process(request); + request = (StatusRequestImpl) this.pdfas4.process(request); if(request.isReady()) { at.gv.egiz.pdfas.lib.api.sign.SignResult result = this.pdfas4.finishSign(request); sdi.wrapper.syncNewToOld(); -- cgit v1.2.3