From 94c33f3d604ebf9a37dba551eb822b57ebfea902 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 4 Jun 2014 16:12:10 +0200 Subject: Added TransactionId for Signatures --- .../java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java | 4 ++++ .../at/gv/egiz/pdfas/lib/api/sign/IPlainSigner.java | 4 ++-- .../main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java | 4 ++-- .../at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java | 10 ++++++++++ .../lib/impl/signing/pdfbox/PdfboxSignerWrapper.java | 7 +++++-- .../gv/egiz/pdfas/lib/impl/status/OperationStatus.java | 7 +++++++ .../main/java/at/gv/egiz/sl/util/BKUSLConnector.java | 18 +++++++++++++----- .../main/java/at/gv/egiz/sl/util/BaseSLConnector.java | 5 +++-- .../src/main/java/at/gv/egiz/sl/util/ISLConnector.java | 9 +++++---- .../java/at/gv/egiz/sl/util/ISignatureConnector.java | 5 +++-- .../gv/egiz/sl/util/ISignatureConnectorSLWrapper.java | 13 +++++++------ .../src/main/java/at/gv/egiz/sl/util/MOAConnector.java | 5 +++-- 12 files changed, 64 insertions(+), 27 deletions(-) (limited to 'pdf-as-lib/src/main/java') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java index 3f37eebb..bb35f68f 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsParameter.java @@ -48,4 +48,8 @@ public interface PdfAsParameter { * @param dataSource */ public void setDataSource(DataSource dataSource); + + public String getTransactionId(); + + public void setTransactionId(String id); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/IPlainSigner.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/IPlainSigner.java index 8ab770e7..903b9630 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/IPlainSigner.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/IPlainSigner.java @@ -39,7 +39,7 @@ public interface IPlainSigner { * @return * @throws PdfAsException */ - public X509Certificate getCertificate() throws PdfAsException; + public X509Certificate getCertificate(SignParameter parameter) throws PdfAsException; /** * Sign the document @@ -48,7 +48,7 @@ public interface IPlainSigner { * @return * @throws PdfAsException */ - public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException; + public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter) throws PdfAsException; /** * Gets the PDF Subfilter for this signer diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index c40704b1..b146edfe 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -149,7 +149,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { status.setRequestedSignature(requestedSignature); requestedSignature.setCertificate(status.getSignParamter() - .getPlainSigner().getCertificate()); + .getPlainSigner().getCertificate(parameter)); // Only use this profileID because validation was done in // RequestedSignature @@ -168,7 +168,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { IPdfSigner signer = PdfSignerFactory.createPdfSigner(); signer.signPDF(status.getPdfObject(), requestedSignature, new PdfboxSignerWrapper(status.getSignParamter() - .getPlainSigner())); + .getPlainSigner(), parameter)); // ================================================================ // Create SignResult diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java index c9e8ef54..362715a3 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java @@ -31,11 +31,13 @@ public class PdfAsParameterImpl implements PdfAsParameter { protected Configuration configuration; protected DataSource dataSource; + protected String transactionId; public PdfAsParameterImpl(Configuration configuration, DataSource dataSource) { this.configuration = configuration; this.dataSource = dataSource; + this.transactionId = null; } public Configuration getConfiguration() { @@ -53,4 +55,12 @@ protected Configuration configuration; public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String id) { + this.transactionId = id; + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PdfboxSignerWrapper.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PdfboxSignerWrapper.java index 0925a646..faa49148 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PdfboxSignerWrapper.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox/PdfboxSignerWrapper.java @@ -37,6 +37,7 @@ import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException; import at.gv.egiz.pdfas.common.utils.PDFUtils; import at.gv.egiz.pdfas.common.utils.StreamUtils; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.impl.signing.sig_interface.PDFASSignatureInterface; public class PdfboxSignerWrapper implements PDFASSignatureInterface { @@ -49,10 +50,12 @@ public class PdfboxSignerWrapper implements PDFASSignatureInterface { private PDSignature signature; private int[] byteRange; private Calendar date; + private SignParameter parameters; - public PdfboxSignerWrapper(IPlainSigner signer) { + public PdfboxSignerWrapper(IPlainSigner signer, SignParameter parameters) { this.signer = signer; this.date = Calendar.getInstance(); + this.parameters = parameters; } public byte[] sign(InputStream inputStream) throws SignatureException, @@ -63,7 +66,7 @@ public class PdfboxSignerWrapper implements PDFASSignatureInterface { logger.info("Byte Range 2: " + byteRange2); try { logger.info("Signing with Pdfbox Wrapper"); - byte[] signature = signer.sign(data, byteRange); + byte[] signature = signer.sign(data, byteRange, this.parameters); return signature; } catch (PdfAsException e) { throw new PdfAsWrappedIOException(e); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java index 75eee27f..4a8445b5 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -156,4 +156,11 @@ public class OperationStatus implements Serializable { this.signingDate = signingDate; } + public String getTransactionId() { + if(this.signParamter != null) { + return this.signParamter.getTransactionId(); + } + return null; + } + } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java index afceb96f..204fd727 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java @@ -46,6 +46,7 @@ import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException; import at.gv.egiz.pdfas.common.utils.PDFUtils; import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; import at.gv.egiz.sl.schema.ErrorResponseType; import at.gv.egiz.sl.schema.InfoboxReadRequestType; @@ -69,7 +70,7 @@ public class BKUSLConnector extends BaseSLConnector { return builder.build(); } - private String performHttpRequestToBKU(String xmlRequest, RequestPackage pack) + private String performHttpRequestToBKU(String xmlRequest, RequestPackage pack, SignParameter parameter) throws ClientProtocolException, IOException, IllegalStateException { CloseableHttpClient client = null; try { @@ -81,6 +82,13 @@ public class BKUSLConnector extends BaseSLConnector { entityBuilder.addTextBody(XMLREQUEST, xmlRequest, ContentType.TEXT_XML); + if(parameter != null) { + String transactionId = parameter.getTransactionId(); + if(transactionId != null) { + entityBuilder.addTextBody("TransactionId_", transactionId); + } + } + if(pack != null && pack.getSignatureData() != null) { entityBuilder.addBinaryBody("fileupload", PDFUtils.blackOutSignature(pack.getSignatureData(), pack.getByteRange())); @@ -115,7 +123,7 @@ public class BKUSLConnector extends BaseSLConnector { } public InfoboxReadResponseType sendInfoboxReadRequest( - InfoboxReadRequestType request) throws PdfAsException { + InfoboxReadRequestType request, SignParameter parameter) throws PdfAsException { JAXBElement element = null; String slRequest; try { @@ -123,7 +131,7 @@ public class BKUSLConnector extends BaseSLConnector { .createInfoboxReadRequest(request)); logger.trace(slRequest); - String slResponse = performHttpRequestToBKU(slRequest, null); + String slResponse = performHttpRequestToBKU(slRequest, null, parameter); element = (JAXBElement) SLMarschaller .unmarshalFromString(slResponse); @@ -154,7 +162,7 @@ public class BKUSLConnector extends BaseSLConnector { } public CreateCMSSignatureResponseType sendCMSRequest( - RequestPackage pack) throws PdfAsException { + RequestPackage pack, SignParameter parameter) throws PdfAsException { JAXBElement element = null; String slRequest; try { @@ -162,7 +170,7 @@ public class BKUSLConnector extends BaseSLConnector { .createCreateCMSSignatureRequest(pack.getRequestType())); logger.debug(slRequest); - String slResponse = performHttpRequestToBKU(slRequest, pack); + String slResponse = performHttpRequestToBKU(slRequest, pack, parameter); element = (JAXBElement) SLMarschaller .unmarshalFromString(slResponse); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java index 5321ed51..99cdb9f8 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PDFIOException; import at.gv.egiz.pdfas.common.utils.PDFUtils; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.sl.schema.Base64OptRefContentType; import at.gv.egiz.sl.schema.Base64XMLLocRefContentType; import at.gv.egiz.sl.schema.Base64XMLLocRefOptRefContentType; @@ -60,7 +61,7 @@ public abstract class BaseSLConnector implements ISLConnector { protected ObjectFactory of = new ObjectFactory(); - public InfoboxReadRequestType createInfoboxReadRequest() { + public InfoboxReadRequestType createInfoboxReadRequest(SignParameter parameter) { InfoboxReadRequestType request = new InfoboxReadRequestType(); request.setInfoboxIdentifier("Certificates"); InfoboxReadParamsAssocArrayType readData = new InfoboxReadParamsAssocArrayType(); @@ -73,7 +74,7 @@ public abstract class BaseSLConnector implements ISLConnector { return request; } - public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange) + public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange, SignParameter parameter) throws PDFIOException { //if (base64) { byte[] data = PDFUtils.blackOutSignature(signatureData, byteRange); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java index 120f2f73..1a2f8f79 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISLConnector.java @@ -25,14 +25,15 @@ package at.gv.egiz.sl.util; import at.gv.egiz.pdfas.common.exceptions.PDFIOException; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; import at.gv.egiz.sl.schema.InfoboxReadRequestType; import at.gv.egiz.sl.schema.InfoboxReadResponseType; public interface ISLConnector { - public InfoboxReadRequestType createInfoboxReadRequest(); - public InfoboxReadResponseType sendInfoboxReadRequest(InfoboxReadRequestType request) throws PdfAsException; - public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange) throws PDFIOException; - public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack) throws PdfAsException; + public InfoboxReadRequestType createInfoboxReadRequest(SignParameter parameter); + public InfoboxReadResponseType sendInfoboxReadRequest(InfoboxReadRequestType request, SignParameter parameter) throws PdfAsException; + public RequestPackage createCMSRequest(byte[] signatureData, int[] byteRange, SignParameter parameter) throws PDFIOException; + public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack, SignParameter parameter) throws PdfAsException; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnector.java index e39398a6..fdb95f49 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnector.java @@ -25,8 +25,9 @@ package at.gv.egiz.sl.util; import iaik.x509.X509Certificate; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; public interface ISignatureConnector { - public X509Certificate getCertificate() throws PdfAsException; - public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException; + public X509Certificate getCertificate(SignParameter parameter) throws PdfAsException; + public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter) throws PdfAsException; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java index 1b9fad2a..b564c215 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/ISignatureConnectorSLWrapper.java @@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.impl.verify.VerifyResultImpl; import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; import at.gv.egiz.sl.schema.InfoboxAssocArrayPairType; @@ -58,13 +59,13 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector { this.connector = connector; } - public X509Certificate getCertificate() throws PdfAsException { + public X509Certificate getCertificate(SignParameter parameter) throws PdfAsException { X509Certificate certificate = null; try { InfoboxReadRequestType request = connector - .createInfoboxReadRequest(); + .createInfoboxReadRequest(parameter); InfoboxReadResponseType response = connector - .sendInfoboxReadRequest(request); + .sendInfoboxReadRequest(request, parameter); Iterator iterator = response .getAssocArrayData().getPair().iterator(); @@ -83,11 +84,11 @@ public class ISignatureConnectorSLWrapper implements ISignatureConnector { return certificate; } - public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException { + public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter) throws PdfAsException { RequestPackage pack = connector.createCMSRequest( - input, byteRange); + input, byteRange, parameter); CreateCMSSignatureResponseType response = connector - .sendCMSRequest(pack); + .sendCMSRequest(pack, parameter); try { SignedData signedData = new SignedData(new ByteArrayInputStream( response.getCMSSignature())); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java index 9c5c720a..73de30cf 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java @@ -58,6 +58,7 @@ import at.gv.egiz.pdfas.common.exceptions.PdfAsMOAException; import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException; import at.gv.egiz.pdfas.common.settings.ISettings; import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; public class MOAConnector implements ISignatureConnector { @@ -125,7 +126,7 @@ public class MOAConnector implements ISignatureConnector { this.keyIdentifier = config.getValue(MOA_SIGN_KEY_ID); } - public X509Certificate getCertificate() throws PdfAsException { + public X509Certificate getCertificate(SignParameter parameter) throws PdfAsException { return this.certificate; } @@ -134,7 +135,7 @@ public class MOAConnector implements ISignatureConnector { return builder.build(); } - public byte[] sign(byte[] input, int[] byteRange) throws PdfAsException { + public byte[] sign(byte[] input, int[] byteRange, SignParameter parameter) throws PdfAsException { CloseableHttpClient client = null; try { client = buildHttpClient(); -- cgit v1.2.3