diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-05-06 12:20:08 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-05-06 12:20:08 +0200 |
commit | 53d5b439a422c72e6f94a2fb1012c85732e33bfe (patch) | |
tree | 2475dae53178df8a68609ee9bbfb486af4b49d5e /pdf-as-web/src/main/java/at | |
parent | c0c25045fafa139a9e6337fd732945ee9cd6318a (diff) | |
download | pdf-as-4-53d5b439a422c72e6f94a2fb1012c85732e33bfe.tar.gz pdf-as-4-53d5b439a422c72e6f94a2fb1012c85732e33bfe.tar.bz2 pdf-as-4-53d5b439a422c72e6f94a2fb1012c85732e33bfe.zip |
PDF-AS 4 RC24.0.0-RC2
Diffstat (limited to 'pdf-as-web/src/main/java/at')
6 files changed, 165 insertions, 12 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index f9d3e720..75c98610 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -57,14 +57,17 @@ import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; import at.gv.egiz.pdfas.sigs.pkcs7detached.PKCS7DetachedSigner; import at.gv.egiz.pdfas.web.config.WebConfiguration; import at.gv.egiz.pdfas.web.exception.PdfAsWebException; -import at.gv.egiz.sl.CreateCMSSignatureRequestType; -import at.gv.egiz.sl.CreateCMSSignatureResponseType; -import at.gv.egiz.sl.InfoboxAssocArrayPairType; -import at.gv.egiz.sl.InfoboxReadRequestType; -import at.gv.egiz.sl.InfoboxReadResponseType; -import at.gv.egiz.sl.ObjectFactory; +import at.gv.egiz.pdfas.web.ws.PDFASSignParameters; +import at.gv.egiz.pdfas.web.ws.PDFASSignParameters.Connector; +import at.gv.egiz.sl.schema.CreateCMSSignatureRequestType; +import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; +import at.gv.egiz.sl.schema.InfoboxAssocArrayPairType; +import at.gv.egiz.sl.schema.InfoboxReadRequestType; +import at.gv.egiz.sl.schema.InfoboxReadResponseType; +import at.gv.egiz.sl.schema.ObjectFactory; import at.gv.egiz.sl.util.BKUSLConnector; import at.gv.egiz.sl.util.MOAConnector; +import at.gv.egiz.sl.util.RequestPackage; import at.gv.egiz.sl.util.SLMarschaller; public class PdfAsHelper { @@ -295,13 +298,15 @@ public class PdfAsHelper { IPlainSigner signer; if (connector.equals("moa")) { signer = new PAdESSigner(new MOAConnector(config)); - } else { + } else if(connector.equals("jks")) { signer = new PKCS7DetachedSigner( WebConfiguration.getKeystoreFile(), WebConfiguration.getKeystoreAlias(), WebConfiguration.getKeystorePass(), WebConfiguration.getKeystoreKeyPass(), WebConfiguration.getKeystoreType()); + } else { + throw new PdfAsWebException("Invalid connector (moa | jks)"); } signParameter.setPlainSigner(signer); @@ -321,6 +326,57 @@ public class PdfAsHelper { return output.getData(); } + /** + * Create synchronous PDF Signature + * + * @param request + * The Web request + * @param response + * The Web response + * @param pdfData + * The pdf data + * @return The signed pdf data + * @throws Exception + */ + public static byte[] synchornousServerSignature(byte[] pdfData, PDFASSignParameters params) throws Exception { + Configuration config = pdfAs.getConfiguration(); + + // Generate Sign Parameter + SignParameter signParameter = PdfAsFactory.createSignParameter(config, + new ByteArrayDataSource(pdfData)); + + // Get Connector + + IPlainSigner signer; + if (params.getConnector().equals(Connector.MOA)) { + signer = new PAdESSigner(new MOAConnector(config)); + } else if(params.getConnector().equals(Connector.JKS)) { + signer = new PKCS7DetachedSigner( + WebConfiguration.getKeystoreFile(), + WebConfiguration.getKeystoreAlias(), + WebConfiguration.getKeystorePass(), + WebConfiguration.getKeystoreKeyPass(), + WebConfiguration.getKeystoreType()); + } else { + throw new PdfAsWebException("Invalid connector (moa | jks)"); + } + + signParameter.setPlainSigner(signer); + + // set Signature Profile (null use default ...) + signParameter.setSignatureProfileId(params.getProfile()); + + ByteArrayDataSink output = new ByteArrayDataSink(); + signParameter.setOutput(output); + + // set Signature Position + signParameter.setSignaturePosition(params.getPosition()); + + pdfAs.sign(signParameter); + + return output.getData(); + } + public static void startSignature(HttpServletRequest request, HttpServletResponse response, ServletContext context, byte[] pdfData) throws Exception { @@ -354,6 +410,7 @@ public class PdfAsHelper { if (connector.equals("bku") || connector.equals("onlinebku") || connector.equals("mobilebku")) { BKUSLConnector conn = new BKUSLConnector(config); + //conn.setBase64(true); signer = new PAdESSigner(conn); session.setAttribute(PDF_SL_CONNECTOR, conn); } else { @@ -495,13 +552,13 @@ public class PdfAsHelper { } else if (statusRequest.needSignature()) { logger.info("Needing Signature from BKU"); // build SL Request for cms signature - CreateCMSSignatureRequestType createCMSSignatureRequestType = bkuSLConnector + RequestPackage pack = bkuSLConnector .createCMSRequest(statusRequest.getSignatureData(), statusRequest.getSignatureDataByteRange()); String slRequest = SLMarschaller .marshalToString(of - .createCreateCMSSignatureRequest(createCMSSignatureRequestType)); + .createCreateCMSSignatureRequest(pack.getRequestType())); response.setContentType("text/xml"); response.getWriter().write(slRequest); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java index cf25c2f2..5b951b78 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/DataURLServlet.java @@ -36,9 +36,9 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.web.exception.PdfAsSecurityLayerException; import at.gv.egiz.pdfas.web.helper.PdfAsHelper; -import at.gv.egiz.sl.CreateCMSSignatureResponseType; -import at.gv.egiz.sl.ErrorResponseType; -import at.gv.egiz.sl.InfoboxReadResponseType; +import at.gv.egiz.sl.schema.CreateCMSSignatureResponseType; +import at.gv.egiz.sl.schema.ErrorResponseType; +import at.gv.egiz.sl.schema.InfoboxReadResponseType; import at.gv.egiz.sl.util.SLMarschaller; /** diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSignParameters.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSignParameters.java new file mode 100644 index 00000000..4658372b --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSignParameters.java @@ -0,0 +1,43 @@ +package at.gv.egiz.pdfas.web.ws; + +import java.io.Serializable; + +public class PDFASSignParameters implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -2375108993871456465L; + + public enum Connector { + JKS, + MOA + } + + Connector connector; + String position; + String profile; + + + public Connector getConnector() { + return connector; + } + public void setConnector(Connector connector) { + this.connector = connector; + } + public String getPosition() { + return position; + } + public void setPosition(String position) { + this.position = position; + } + public String getProfile() { + return profile; + } + public void setProfile(String profile) { + this.profile = profile; + } + + + +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigning.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigning.java new file mode 100644 index 00000000..0b75c0e0 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigning.java @@ -0,0 +1,11 @@ +package at.gv.egiz.pdfas.web.ws; + +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.Style; + +@WebService +@SOAPBinding(style = Style.RPC) +public interface PDFASSigning { + public byte[] signPDFDokument(byte[] inputDocument, PDFASSignParameters parameters); +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java new file mode 100644 index 00000000..39c6c24d --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java @@ -0,0 +1,34 @@ +package at.gv.egiz.pdfas.web.ws; + +import javax.jws.WebService; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.soap.MTOM; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.pdfas.web.config.WebConfiguration; +import at.gv.egiz.pdfas.web.helper.PdfAsHelper; + +@MTOM +@WebService(endpointInterface = "at.gv.egiz.pdfas.web.ws.PDFASSigning") +public class PDFASSigningImpl implements PDFASSigning { + + private static final Logger logger = LoggerFactory + .getLogger(PDFASSigningImpl.class); + + public byte[] signPDFDokument(byte[] inputDocument, + PDFASSignParameters parameters) { + try { + return PdfAsHelper.synchornousServerSignature(inputDocument, parameters); + } catch(Throwable e) { + logger.error("Server Signature failed.", e); + if(WebConfiguration.isShowErrorDetails()) { + throw new WebServiceException("Server Signature failed.", e); + } else { + throw new WebServiceException("Server Signature failed."); + } + } + } + +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/package-info.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/package-info.java new file mode 100644 index 00000000..0ed0acfc --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author afitzek + * + */ +package at.gv.egiz.pdfas.web.ws;
\ No newline at end of file |