summaryrefslogtreecommitdiff
path: root/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit
diff options
context:
space:
mode:
authorTobias Kellner <tobias.kellner@iaik.tugraz.at>2014-11-27 20:48:16 +0100
committerTobias Kellner <tobias.kellner@iaik.tugraz.at>2014-11-27 20:48:16 +0100
commit896fbe4a5643bf8c29968f8514a1c14fd51c4d9e (patch)
tree0f3e3bec7093e9be39c94199b50db1a61154c54d /pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit
parent5ef48a2002856bea0cac10e1dac6fb2985dca893 (diff)
downloadpdf-over-896fbe4a5643bf8c29968f8514a1c14fd51c4d9e.tar.gz
pdf-over-896fbe4a5643bf8c29968f8514a1c14fd51c4d9e.tar.bz2
pdf-over-896fbe4a5643bf8c29968f8514a1c14fd51c4d9e.zip
Add PDF-AS4 signer
Diffstat (limited to 'pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit')
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java144
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java79
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java56
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java161
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java146
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java31
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java133
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java34
8 files changed, 784 insertions, 0 deletions
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
new file mode 100644
index 00000000..33221285
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+// Imports
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.signator.BkuSlConnector;
+import at.asit.pdfover.signator.SignatureException;
+import at.asit.pdfover.signer.pdfas.exceptions.PdfAs4SLRequestException;
+import at.gv.egiz.pdfas.common.exceptions.PDFIOException;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException;
+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;
+import at.gv.egiz.sl.schema.InfoboxReadResponseType;
+import at.gv.egiz.sl.util.BaseSLConnector;
+import at.gv.egiz.sl.util.RequestPackage;
+import at.gv.egiz.sl.util.SLMarschaller;
+
+/**
+ *
+ */
+public class PdfAs4BKUSLConnector extends BaseSLConnector {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PdfAs4BKUSLConnector.class);
+
+ private BkuSlConnector connector;
+
+ /**
+ * Constructor
+ * @param connector the BKU SL Connector
+ */
+ public PdfAs4BKUSLConnector(BkuSlConnector connector) {
+ this.connector = connector;
+ }
+
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.sl.util.ISLConnector#sendInfoboxReadRequest(at.gv.egiz.sl.schema.InfoboxReadRequestType, at.gv.egiz.pdfas.lib.api.sign.SignParameter)
+ */
+ @Override
+ public InfoboxReadResponseType sendInfoboxReadRequest(
+ InfoboxReadRequestType request, SignParameter parameter)
+ throws PdfAsException {
+ JAXBElement<?> element = null;
+ try {
+ String slRequestString = SLMarschaller.marshalToString(this.of.createInfoboxReadRequest(request));
+ log.trace(slRequestString);
+
+ PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, null);
+ String slResponse = this.connector.handleSLRequest(slRequest).getSLRespone();
+
+ element = (JAXBElement<?>) SLMarschaller
+ .unmarshalFromString(slResponse);
+ } catch (JAXBException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ } catch (PdfAs4SLRequestException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ } catch (SignatureException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ }
+
+ if (element == null) {
+ throw new PDFIOException("error.pdf.io.04");
+ }
+
+ if (element.getValue() instanceof InfoboxReadResponseType) {
+ InfoboxReadResponseType infoboxReadResponseType = (InfoboxReadResponseType) element
+ .getValue();
+ return infoboxReadResponseType;
+ } else if (element.getValue() instanceof ErrorResponseType) {
+ ErrorResponseType errorResponseType = (ErrorResponseType) element
+ .getValue();
+ throw new SLPdfAsException(errorResponseType.getErrorCode(),
+ errorResponseType.getInfo());
+ }
+ throw new PdfAsException("error.pdf.io.03");
+ }
+
+ /* (non-Javadoc)
+ * @see at.gv.egiz.sl.util.ISLConnector#sendCMSRequest(at.gv.egiz.sl.util.RequestPackage, at.gv.egiz.pdfas.lib.api.sign.SignParameter)
+ */
+ @Override
+ public CreateCMSSignatureResponseType sendCMSRequest(RequestPackage pack,
+ SignParameter parameter) throws PdfAsException {
+ JAXBElement<?> element = null;
+ try {
+ String slRequestString = SLMarschaller.marshalToString(this.of.createCreateCMSSignatureRequest(pack.getRequestType()));
+ log.debug(slRequestString);
+
+ PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, pack.getSignatureData());
+ String slResponse = this.connector.handleSLRequest(slRequest).getSLRespone();
+
+ element = (JAXBElement<?>) SLMarschaller
+ .unmarshalFromString(slResponse);
+ } catch (JAXBException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ } catch (PdfAs4SLRequestException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ } catch (SignatureException e) {
+ throw new PDFIOException("error.pdf.io.03", e);
+ }
+
+ if (element == null) {
+ throw new PDFIOException("error.pdf.io.05");
+ }
+
+ if (element.getValue() instanceof CreateCMSSignatureResponseType) {
+ CreateCMSSignatureResponseType createCMSSignatureResponseType = (CreateCMSSignatureResponseType) element
+ .getValue();
+ log.debug(createCMSSignatureResponseType.toString());
+ return createCMSSignatureResponseType;
+ } else if (element.getValue() instanceof ErrorResponseType) {
+ ErrorResponseType errorResponseType = (ErrorResponseType) element
+ .getValue();
+ throw new SLPdfAsException(errorResponseType.getErrorCode(),
+ errorResponseType.getInfo());
+ }
+ throw new PdfAsException("error.pdf.io.03");
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java
new file mode 100644
index 00000000..21a6bbdb
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+// Imports
+import java.io.File;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.signator.SignatureException;
+import at.gv.egiz.pdfas.lib.api.PdfAs;
+import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+
+/**
+ * PDF-AS 4 Helper
+ */
+public class PdfAs4Helper {
+ /**
+ * SLF4J Logger instance
+ **/
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory
+ .getLogger(PdfAs4Helper.class);
+
+ /**
+ * PDF-AS Object
+ */
+ private static PdfAs pdfAs = null;
+
+ /**
+ * Gets PDF-AS Object
+ * @return the PDF-AS Object
+ * @throws SignatureException
+ */
+ public static synchronized PdfAs getPdfAs() throws SignatureException {
+ if (pdfAs == null) {
+ try {
+ pdfAs = createPdfAs();
+ } catch(Exception e) {
+ throw new SignatureException(e);
+ }
+ }
+ return pdfAs;
+ }
+
+ /**
+ * Creates PDF-AS Object
+ * @return the PDF-AS Object
+ * @throws PdfAsException
+ */
+ private static PdfAs createPdfAs() {
+ File directory = new File (".");
+ System.setProperty("log4j.configuration", directory.getAbsolutePath() +
+ "/log4j.properties");
+ return PdfAsFactory.createPdfAs(new File(getWorkDir()));
+ }
+
+ /**
+ * Provides the working directory
+ * @return the working directory
+ */
+ public static String getWorkDir() {
+ return System.getProperty("user.home") + "/.pdf-over";
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java
new file mode 100644
index 00000000..87babd59
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+// Imports
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.signator.ByteArrayDocumentSource;
+import at.asit.pdfover.signator.SLRequest;
+import at.asit.pdfover.signer.pdfas.exceptions.PdfAs4SLRequestException;
+
+/**
+ * PDF - AS Security Layer Request implementation
+ */
+public class PdfAs4SLRequest extends SLRequest {
+
+ /**
+ * SLF4J Logger instance
+ **/
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(PdfAs4SLRequest.class);
+
+ /**
+ * Default constructor
+ * @param slRequest
+ * @param signData
+ * @throws PdfAs4SLRequestException
+ */
+ public PdfAs4SLRequest(String slRequest, byte[] signData) throws PdfAs4SLRequestException {
+// if(!slRequest.contains(PdfAs4Signer.LOC_REF)) {
+// log.error("PDF-AS SL request doesn't contain " + PdfAs4Signer.LOC_REF);
+// log.debug("Request: " + slRequest);
+// throw new PdfAs4SLRequestException("PDF-AS SL request doesn't contain " + PdfAs4Signer.LOC_REF);
+// }
+//
+// // Modifing SL Request ...
+// setRequest(slRequest.replace(PdfAs4Signer.LOC_REF, SLRequest.DATAOBJECT_STRING));
+
+ setRequest(slRequest);
+ setSignatureData(signData == null ? null : new ByteArrayDocumentSource(signData));
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
new file mode 100644
index 00000000..38aabadd
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+//Imports
+import iaik.x509.X509Certificate;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.util.HashMap;
+import java.util.Locale;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.signator.SignatureDimension;
+import at.asit.pdfover.signator.SignatureParameter;
+import at.asit.pdfover.signator.SignaturePosition;
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.PdfAs;
+import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+
+/**
+ * Implementation of SignatureParameter for PDF-AS 4 Library
+ */
+public class PdfAs4SignatureParameter extends SignatureParameter {
+ /** The profile ID for the German signature block */
+ private static final String PROFILE_ID_DE = "SIGNATURBLOCK_SMALL_DE_PDFA";
+ /** The profile ID for the German signature block if a signature note is set */
+ private static final String PROFILE_ID_DE_NOTE = "SIGNATURBLOCK_SMALL_DE_NOTE_PDFA";
+ /** The profile ID for the English signature block */
+ private static final String PROFILE_ID_EN = "SIGNATURBLOCK_SMALL_EN_PDFA";
+ /** The profile ID for the English signature block if a signature note is set */
+ private static final String PROFILE_ID_EN_NOTE = "SIGNATURBLOCK_SMALL_EN_NOTE_PDFA";
+
+ private HashMap<String, String> genericProperties = new HashMap<String, String>();
+
+ private int sig_w = 229;
+ private int sig_h = 77;
+
+ /**
+ * SLF4J Logger instance
+ **/
+ static final Logger log = LoggerFactory
+ .getLogger(PdfAs4SignatureParameter.class);
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholderDimension()
+ */
+ @Override
+ public SignatureDimension getPlaceholderDimension() {
+ return new SignatureDimension(this.sig_w, this.sig_h);
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholder()
+ */
+ @Override
+ public Image getPlaceholder() {
+ String sigProfile = getPdfAsSignatureProfileId();
+ String sigEmblem = (getEmblem() == null ? null : getEmblem().getFileName());
+ String sigNote = getProperty("SIG_NOTE");
+
+ try {
+ X509Certificate cert = new X509Certificate(PdfAs4SignatureParameter.class.getResourceAsStream("/qualified.cer"));
+ PdfAs pdfas = PdfAs4Helper.getPdfAs();
+ Configuration conf = pdfas.getConfiguration();
+ if (sigEmblem != null && !sigEmblem.trim().equals("")) {
+ conf.setValue("sig_obj." + sigProfile + ".value.SIG_LABEL", sigEmblem);
+ }
+ if (sigNote != null) {
+ conf.setValue("sig_obj." + sigProfile + ".value.SIG_NOTE", sigNote);
+ }
+ SignParameter param = PdfAsFactory
+ .createSignParameter(conf, null, null);
+ param.setSignatureProfileId(sigProfile);
+ Image img = pdfas.generateVisibleSignaturePreview(param, cert, 72*4);
+ this.sig_w = img.getWidth(null)/4;
+ this.sig_h = img.getHeight(null)/4;
+
+ return img;
+ } catch (Exception e) {
+ log.error("Failed to get signature placeholder", e);
+ return new BufferedImage(getPlaceholderDimension().getWidth(),
+ getPlaceholderDimension().getHeight(),
+ BufferedImage.TYPE_INT_RGB);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SignatureParameter#setProperty(java.lang.String, java.lang.String)
+ */
+ @Override
+ public void setProperty(String key, String value) {
+ this.genericProperties.put(key, value);
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SignatureParameter#getProperty(java.lang.String)
+ */
+ @Override
+ public String getProperty(String key) {
+ return this.genericProperties.get(key);
+ }
+
+ /**
+ * Gets the Signature Position String for PDF-AS
+ *
+ * @return Signature Position String
+ */
+ public String getPdfAsSignaturePosition() {
+ SignaturePosition in_pos = getSignaturePosition();
+ String out_pos;
+
+ if (!in_pos.useAutoPositioning()) {
+ if (in_pos.getPage() < 1) {
+ out_pos = String.format(
+ (Locale) null,
+ "p:new;x:%f;y:%f", in_pos.getX(),
+ in_pos.getY());
+ } else {
+ out_pos = String.format(
+ (Locale) null,
+ "p:%d;x:%f;y:%f", in_pos.getPage(), in_pos.getX(),
+ in_pos.getY());
+ }
+ } else {
+ out_pos = "p:auto;x:auto;y:auto";
+ }
+
+ return out_pos;
+ }
+
+ /**
+ * Get the Signature Profile ID for this set of parameters
+ * @return the Signature Profile ID
+ */
+ public String getPdfAsSignatureProfileId() {
+ String lang = getSignatureLanguage();
+ boolean useNote = (getProperty("SIG_NOTE") != null);
+
+ if (lang != null && lang.equals("en"))
+ return useNote ? PROFILE_ID_EN_NOTE : PROFILE_ID_EN;
+
+ return useNote ? PROFILE_ID_DE_NOTE : PROFILE_ID_DE;
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
new file mode 100644
index 00000000..0f42a517
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
@@ -0,0 +1,146 @@
+package at.asit.pdfover.signer.pdfas;
+
+import java.io.ByteArrayOutputStream;
+import java.util.UUID;
+
+import javax.activation.DataSource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.signator.ByteArrayDocumentSource;
+import at.asit.pdfover.signator.SignResult;
+import at.asit.pdfover.signator.SignResultImpl;
+import at.asit.pdfover.signator.SignatureException;
+import at.asit.pdfover.signator.SignatureParameter;
+import at.asit.pdfover.signator.SignaturePosition;
+import at.asit.pdfover.signator.Signer;
+import at.asit.pdfover.signator.SigningState;
+import at.gv.egiz.pdfas.common.exceptions.PDFASError;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.PdfAs;
+import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.sigs.pades.PAdESSigner;
+import at.gv.egiz.sl.util.ISLConnector;
+import at.knowcenter.wag.egov.egiz.pdf.TablePos;
+
+/**
+ * PDF AS Signer Implementation
+ */
+public class PdfAs4Signer implements Signer {
+
+ /**
+ * SLF4J Logger instance
+ **/
+ static final Logger log = LoggerFactory.getLogger(PdfAs4Signer.class);
+
+ /**
+ * The template URL
+ */
+ protected static final String URL_TEMPLATE = "http://pdfover.4.gv.at/template";
+
+ /**
+ * Location reference string
+ */
+ protected static final String LOC_REF = "<sl:LocRefContent>" + URL_TEMPLATE
+ + "</sl:LocRefContent>";
+
+ @Override
+ public SigningState prepare(SignatureParameter parameter)
+ throws SignatureException {
+ PdfAs4SignatureParameter sign_para = null;
+
+ if (PdfAs4SignatureParameter.class.isInstance(parameter)) {
+ sign_para = PdfAs4SignatureParameter.class.cast(parameter);
+ }
+
+ if (sign_para == null) {
+ throw new SignatureException("Incorrect SignatureParameter!");
+ }
+
+ String sigProfile = sign_para.getPdfAsSignatureProfileId();
+ String sigEmblem = (sign_para.getEmblem() == null ? null : sign_para.getEmblem().getFileName());
+ String sigNote = sign_para.getProperty("SIG_NOTE");
+ String sigPos = sign_para.getPdfAsSignaturePosition();
+
+ PdfAs pdfas = PdfAs4Helper.getPdfAs();
+ Configuration config = pdfas.getConfiguration();
+ if (sigEmblem != null && !sigEmblem.trim().isEmpty()) {
+ config.setValue("sig_obj." + sigProfile + ".value.SIG_LABEL", sigEmblem);
+ }
+
+ if(sigNote != null) {
+ config.setValue("sig_obj." + sigProfile + ".value.SIG_NOTE", sigNote);
+ }
+
+ PdfAs4SigningState state = new PdfAs4SigningState();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataSource input = new ByteArrayDataSource(parameter.getInputDocument().getByteArray());
+ SignParameter param = PdfAsFactory.createSignParameter(config, input, output);
+ param.setSignaturePosition(sigPos);
+ param.setSignatureProfileId(sigProfile);
+ String id = UUID.randomUUID().toString();
+ param.setTransactionId(id);
+ state.setSignParameter(param);
+ state.setOutput(output);
+ return state;
+ }
+
+ @Override
+ public SignResult sign(SigningState state) throws SignatureException {
+ try {
+ PdfAs4SigningState sstate = null;
+
+ if (PdfAs4SigningState.class.isInstance(state)) {
+ sstate = PdfAs4SigningState.class.cast(state);
+ }
+
+ if (sstate == null) {
+ throw new SignatureException("Incorrect SigningState!");
+ }
+
+ // Retrieve objects
+ PdfAs pdfas = PdfAs4Helper.getPdfAs();
+
+ SignParameter param = sstate.getSignParameter();
+
+ ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector());
+ param.setPlainSigner(new PAdESSigner(connector));
+
+ pdfas.sign(param);
+
+ // Preparing Result Response
+ SignResultImpl result = new SignResultImpl();
+
+// // Set Signer Certificate
+// result.setSignerCertificate(..);
+
+ // Set Signature position
+ TablePos tp = new TablePos(param.getSignaturePosition());
+ SignaturePosition sp;
+ if (tp.isXauto() && tp.isYauto())
+ sp = new SignaturePosition();
+ else if (tp.isPauto())
+ sp = new SignaturePosition(tp.getPosX(), tp.getPosY());
+ else
+ sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage());
+ result.setSignaturePosition(sp);
+
+ // Set signed Document
+ result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray()));
+ return result;
+ } catch (PdfAsException e) {
+ throw new SignatureException(e);
+ } catch (PDFASError e) {
+ throw new SignatureException(e);
+ }
+ }
+
+ @Override
+ public SignatureParameter newParameter() {
+ return new PdfAs4SignatureParameter();
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java
new file mode 100644
index 00000000..3fa7ce16
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+//Imports
+import at.asit.pdfover.signator.Signer;
+import at.asit.pdfover.signator.SignerFactory;
+
+/**
+ * Factory class for PDF-AS Signer
+ */
+public class PdfAs4SignerFactory extends SignerFactory {
+
+ @Override
+ public Signer createSigner() {
+ return new PdfAs4Signer();
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
new file mode 100644
index 00000000..b8280142
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas;
+
+//Imports
+import java.io.ByteArrayOutputStream;
+
+import at.asit.pdfover.signator.BkuSlConnector;
+import at.asit.pdfover.signator.SLRequest;
+import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SigningState;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+
+/**
+ * Signing State for PDFAS Wrapper
+ */
+public class PdfAs4SigningState implements SigningState {
+
+ /**
+ * The Signature Layer request
+ */
+ private SLRequest slrequest;
+
+ /**
+ * The Signature Layer response
+ */
+ private SLResponse slresponse;
+
+ /**
+ * The Sign Parameters
+ */
+ private SignParameter parameter;
+
+ private ByteArrayOutputStream output;
+
+ private BkuSlConnector connector;
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#getSignatureRequest()
+ */
+ @Override
+ public SLRequest getSignatureRequest() {
+ return this.slrequest;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#setSignatureResponse(at.asit.pdfover.signator.SLResponse)
+ */
+ @Override
+ public void setSignatureResponse(SLResponse response) {
+ this.slresponse = response;
+ }
+
+ /**
+ * Sets the SL Request
+ * @param request The SL Request
+ */
+ public void setSignatureRequest(SLRequest request) {
+ this.slrequest = request;
+ }
+
+ /**
+ * Gets the SL Response
+ * @return The SL Response object
+ */
+ public SLResponse getSignatureResponse() {
+ return this.slresponse;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#hasSignatureResponse()
+ */
+ @Override
+ public boolean hasSignatureResponse() {
+ return this.slresponse != null;
+ }
+
+ /**
+ * @return the output
+ */
+ public ByteArrayOutputStream getOutput() {
+ return this.output;
+ }
+
+ /**
+ * @param output the output to set
+ */
+ public void setOutput(ByteArrayOutputStream output) {
+ this.output = output;
+ }
+
+ /**
+ * @return the parameter
+ */
+ public SignParameter getSignParameter() {
+ return this.parameter;
+ }
+
+ /**
+ * @param parameter the parameter to set
+ */
+ public void setSignParameter(SignParameter parameter) {
+ this.parameter = parameter;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#setBKUConnector(at.asit.pdfover.signator.BkuSlConnector)
+ */
+ @Override
+ public void setBKUConnector(BkuSlConnector connector) {
+ this.connector = connector;
+ }
+
+ /**
+ * @return the connector
+ */
+ public BkuSlConnector getBKUConnector() {
+ return this.connector;
+ }
+}
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java
new file mode 100644
index 00000000..70fe04c3
--- /dev/null
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012 by A-SIT, Secure Information Technology Center Austria
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://joinup.ec.europa.eu/software/page/eupl
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ */
+package at.asit.pdfover.signer.pdfas.exceptions;
+
+/**
+ *
+ */
+public class PdfAs4SLRequestException extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6855855001105199269L;
+
+ /**
+ * Constructor
+ * @param msg
+ */
+ public PdfAs4SLRequestException(String msg) {
+ super(msg);
+ }
+}