From e518f2a61c5d0f08e0f0f0505d9ade4b47dfe7e6 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Fri, 15 Jul 2022 09:29:54 +0200 Subject: flatten signer directory --- pdf-over-gui/pom.xml | 2 +- pdf-over-signer/.project | 6 + .../.settings/org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 11 +- pdf-over-signer/pdf-over-sigpdfas4/pom.xml | 79 ------- .../pdfover/signer/pdfas/PdfAs4BKUSLConnector.java | 150 -------------- .../at/asit/pdfover/signer/pdfas/PdfAs4Helper.java | 76 ------- .../asit/pdfover/signer/pdfas/PdfAs4SLRequest.java | 47 ----- .../signer/pdfas/PdfAs4SignatureParameter.java | 230 --------------------- .../at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 164 --------------- .../pdfover/signer/pdfas/PdfAs4SignerFactory.java | 31 --- .../pdfover/signer/pdfas/PdfAs4SigningState.java | 192 ----------------- .../pdfas/exceptions/PdfAs4SLRequestException.java | 34 --- .../src/main/resources/qualified.cer | 19 -- pdf-over-signer/pom.xml | 71 ++++++- .../pdfover/signer/pdfas/PdfAs4BKUSLConnector.java | 150 ++++++++++++++ .../at/asit/pdfover/signer/pdfas/PdfAs4Helper.java | 76 +++++++ .../asit/pdfover/signer/pdfas/PdfAs4SLRequest.java | 47 +++++ .../signer/pdfas/PdfAs4SignatureParameter.java | 230 +++++++++++++++++++++ .../at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 164 +++++++++++++++ .../pdfover/signer/pdfas/PdfAs4SignerFactory.java | 31 +++ .../pdfover/signer/pdfas/PdfAs4SigningState.java | 192 +++++++++++++++++ .../pdfas/exceptions/PdfAs4SLRequestException.java | 34 +++ pdf-over-signer/src/main/resources/qualified.cer | 19 ++ 24 files changed, 1025 insertions(+), 1032 deletions(-) delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/pom.xml delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java delete mode 100644 pdf-over-signer/pdf-over-sigpdfas4/src/main/resources/qualified.cer create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java create mode 100644 pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java create mode 100644 pdf-over-signer/src/main/resources/qualified.cer diff --git a/pdf-over-gui/pom.xml b/pdf-over-gui/pom.xml index bdb0e1bd..60f0af41 100644 --- a/pdf-over-gui/pom.xml +++ b/pdf-over-gui/pom.xml @@ -33,7 +33,7 @@ at.a-sit - pdf-over-sigpdfas4 + pdf-over-signer ${project.parent.version} diff --git a/pdf-over-signer/.project b/pdf-over-signer/.project index 2b698272..7cdcf912 100644 --- a/pdf-over-signer/.project +++ b/pdf-over-signer/.project @@ -5,6 +5,11 @@ + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.m2e.core.maven2Builder @@ -12,6 +17,7 @@ + org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature diff --git a/pdf-over-signer/.settings/org.eclipse.core.resources.prefs b/pdf-over-signer/.settings/org.eclipse.core.resources.prefs index 99f26c02..abdea9ac 100644 --- a/pdf-over-signer/.settings/org.eclipse.core.resources.prefs +++ b/pdf-over-signer/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,4 @@ eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 encoding/=UTF-8 diff --git a/pdf-over-signer/.settings/org.eclipse.jdt.core.prefs b/pdf-over-signer/.settings/org.eclipse.jdt.core.prefs index 3e73d18e..5621bfa1 100644 --- a/pdf-over-signer/.settings/org.eclipse.jdt.core.prefs +++ b/pdf-over-signer/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,8 @@ -#Fri Aug 03 18:09:51 CEST 2012 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=17 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -18,6 +17,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled @@ -64,6 +64,7 @@ org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled @@ -92,7 +93,9 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL,LOW org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX,NOTE diff --git a/pdf-over-signer/pdf-over-sigpdfas4/pom.xml b/pdf-over-signer/pdf-over-sigpdfas4/pom.xml deleted file mode 100644 index 28808999..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - 4.0.0 - - pdf-over-signer - at.a-sit - 4.4.2-SNAPSHOT - - - pdf-over-sigpdfas4 - PDF-Over PDF-AS 4 Signer - - ${project.basedir}/../.. - 4.2.1-snapshot - - - - at.a-sit - pdf-over-signator - ${project.parent.version} - - - at.gv.egiz.pdfas - pdf-as-lib - ${pdfover-build.pdfas-version} - - - at.gv.egiz.pdfas - sigs-pades - ${pdfover-build.pdfas-version} - - - at.gv.egiz.pdfas - pdf-as-pdfbox-2 - ${pdfover-build.pdfas-version} - - - iaik.prod - iaik_jce_full - 5.63_moa - - - iaik - iaik_eccelerate - 3.01 - - - iaik - iaik_cms - 2.15 - - - iaik - iaik_eccelerate_cms - 3.01 - - - at.a-sit - pdf-over-commons - ${project.parent.version} - compile - - - org.apache.pdfbox - pdfbox - 2.0.24 - - - - - EGIZ Maven - EGIZ Maven Repository - https://apps.egiz.gv.at/maven/ - - - local-repo - file://${pdfover-build.root-dir}/repo - - - 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 deleted file mode 100644 index 124bf43d..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.common.utils.PDFUtils; -import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; -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.trace(slRequestString); - - byte[] signatureData = pack.getSignatureData(); - if (IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD.equals(parameter.getConfiguration().getValue(IConfigurationConstants.SL_REQUEST_TYPE))) - signatureData = PDFUtils.blackOutSignature(signatureData, pack.getByteRange()); - - PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, signatureData); - 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.trace(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 deleted file mode 100644 index e523637f..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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() { - 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 deleted file mode 100644 index 87b97ac9..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 { - 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 deleted file mode 100644 index 032416cd..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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; -import at.asit.pdfover.commons.Profile; - -/** - * Implementation of SignatureParameter for PDF-AS 4 Library - */ -public class PdfAs4SignatureParameter extends SignatureParameter { - /** - * The profile ID extension for the German signature block - */ - private static final String PROFILE_ID_LANG_DE = "_DE"; - /** - * The profile ID extension for the English signature block - */ - private static final String PROFILE_ID_LANG_EN = "_EN"; - /** - * The profile ID extension for the signature note - */ - private static final String PROFILE_ID_NOTE = "_NOTE"; - /** - * The profile ID extension for PDF/A compatibility - */ - private static final String PROFILE_ID_PDFA = "_PDFA"; - - private static final String PROFILE_ID_RECOMMENDED = "_RECOMMENDED"; - - /** - * Visibility of signature block - */ - public static boolean PROFILE_VISIBILITY = true; - - private HashMap genericProperties = new HashMap(); - - /** - * This parameters are defining the signature block size - */ - private int sig_w = 229; - private int sig_h = 77; - - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory - .getLogger(PdfAs4SignatureParameter.class); - private String profile = Profile.getDefaultProfile(); - - /* (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); - boolean usePdfACompat = (getSignaturePdfACompat()); - - //Add Signature Param here// - String profileId; - - if (!PROFILE_VISIBILITY) { - log.debug("Profile visibility was set to false"); - return Profile.INVISIBLE.name(); - } - - Profile profile = Profile.getProfile(this.profile); - switch (profile) { - case BASE_LOGO: - case INVISIBLE: - return this.profile; - case AMTSSIGNATURBLOCK: - profileId = this.profile; - profileId += getLangProfilePart(lang); - profileId += PROFILE_ID_RECOMMENDED; - return profileId; - default: - profileId = this.profile; - profileId += getLangProfilePart(lang); - break; - } - - if (useNote) - profileId += PROFILE_ID_NOTE; - - if (usePdfACompat) - profileId += PROFILE_ID_PDFA; - - log.debug("Profile ID: {}", profileId); - return profileId; - } - - private String getLangProfilePart(String lang) { - return (lang != null && lang.equals("en")) ? PROFILE_ID_LANG_EN : PROFILE_ID_LANG_DE; - } - - @Override - public void setSignatureProfile(String profile) { - this.profile = profile; - } - - @Override - public String getSignatureProfile() { - return this.profile; - } - -} - - - 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 deleted file mode 100644 index 9943ec0e..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ /dev/null @@ -1,164 +0,0 @@ -package at.asit.pdfover.signer.pdfas; - -import java.io.ByteArrayOutputStream; -import java.util.UUID; - -import javax.activation.DataSource; - -import at.asit.pdfover.commons.Profile; -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.IConfigurationConstants; -import at.gv.egiz.pdfas.lib.api.PdfAs; -import at.gv.egiz.pdfas.lib.api.PdfAsFactory; -import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; -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 { - - - - - /** - * The template URL - */ - protected static final String URL_TEMPLATE = "http://pdfover.4.gv.at/template"; - - /** - * Location reference string - */ - protected static final String LOC_REF = "" + URL_TEMPLATE - + ""; - - @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 = null; - if (sign_para.getSignaturePosition() != null) { - 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); - if (sigPos != null) { - param.setSignaturePosition(sigPos); - } - param.setSignatureProfileId(sigProfile); - String id = UUID.randomUUID().toString(); - param.setTransactionId(id); - - if (parameter.isSearchForPlaceholderSignatures()) { - param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_MODE, "1"); - param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_SEARCH_ENABLED, IConfigurationConstants.TRUE); - } - - 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(); - - Configuration config = param.getConfiguration(); - config.setValue(IConfigurationConstants.SL_REQUEST_TYPE, - sstate.getUseBase64Request() ? - IConfigurationConstants.SL_REQUEST_TYPE_BASE64 : - IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD); - - IPlainSigner signer; - if (sstate.hasBKUConnector()) { - ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector()); - signer = new PAdESSigner(connector); - } else if (sstate.hasKSSigner()) { - signer = sstate.getKSSigner(); - } else { - throw new SignatureException("SigningState doesn't have a signer"); - } - param.setPlainSigner(signer); - - pdfas.sign(param); - - SignResultImpl result = new SignResultImpl(); - - if (param.getSignaturePosition() != null) { - 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 if (param.getSignatureProfileId().contains(Profile.AMTSSIGNATURBLOCK.name())) - sp = new SignaturePosition(); - else - sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage()); - result.setSignaturePosition(sp); - } - - result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray())); - return result; - } catch (PdfAsException | 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 deleted file mode 100644 index 3fa7ce16..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 deleted file mode 100644 index f0aff1c8..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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.SignatureException; -import at.asit.pdfover.signator.SigningState; -import at.gv.egiz.pdfas.common.exceptions.PDFASError; -import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; -import at.gv.egiz.pdfas.lib.api.sign.SignParameter; -import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; - -/** - * 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 bkuconnector = null; - - private IPlainSigner kssigner = null; - - private boolean useBase64Request; - - /* (non-Javadoc) - * @see at.asit.pdfover.signator.SigningState#getSignatureRequest() - */ - @Override - public SLRequest getSignatureRequest() { - return this.slrequest; - } - - /** - * Sets the SL Request - * @param request The SL Request - */ - public void setSignatureRequest(SLRequest request) { - this.slrequest = request; - } - - /* (non-Javadoc) - * @see at.asit.pdfover.signator.SigningState#setUseBase64Request(boolean) - */ - @Override - public void setUseBase64Request(boolean useBase64Request) { - this.useBase64Request = useBase64Request; - } - - /** - * Gets whether to use base64 (or FileUpload) for request data - * @return whether to use base64 for request data - */ - public boolean getUseBase64Request() { - return this.useBase64Request; - } - - /** - * Gets the SL Response - * @return The SL Response object - */ - public SLResponse getSignatureResponse() { - return this.slresponse; - } - - /* (non-Javadoc) - * @see at.asit.pdfover.signator.SigningState#setSignatureResponse(at.asit.pdfover.signator.SLResponse) - */ - @Override - public void setSignatureResponse(SLResponse response) { - this.slresponse = response; - } - - /* (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.bkuconnector = connector; - } - - /* (non-Javadoc) - * @see at.asit.pdfover.signator.SigningState#setKSSigner(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public void setKSSigner(String file, String alias, String kspassword, - String keypassword, String type) throws SignatureException { - try { - this.kssigner = new PAdESSignerKeystore(file, alias, kspassword, keypassword, type); - } catch (PDFASError e) { - throw new SignatureException(e); - } - } - - /** - * @return whether a BKU connector was set - */ - public boolean hasBKUConnector() { - return this.bkuconnector != null; - } - - /** - * @return the BKU connector - */ - public BkuSlConnector getBKUConnector() { - return this.bkuconnector; - } - - /** - * @return whether a KS signer was set - */ - public boolean hasKSSigner() { - return this.kssigner != null; - } - - /** - * @return the KS signer - */ - public IPlainSigner getKSSigner() { - return this.kssigner; - } - -} 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 deleted file mode 100644 index ab50e78b..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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); - } -} diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/resources/qualified.cer b/pdf-over-signer/pdf-over-sigpdfas4/src/main/resources/qualified.cer deleted file mode 100644 index e083c81e..00000000 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/resources/qualified.cer +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDJjCCAg4CCQDj2QcuXR0CJjANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJB -VDEPMA0GA1UECAwGU3R5cmlhMQ0wCwYDVQQHDARHcmF6MQ0wCwYDVQQKDARFR0la -MRcwFQYDVQQDDA5NYXggTXVzdGVybWFubjAeFw0xNDExMDYwOTQyMTVaFw0yNDEx -MDMwOTQyMTVaMFUxCzAJBgNVBAYTAkFUMQ8wDQYDVQQIDAZTdHlyaWExDTALBgNV -BAcMBEdyYXoxDTALBgNVBAoMBEVHSVoxFzAVBgNVBAMMDk1heCBNdXN0ZXJtYW5u -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwKREoPZyoxmmXiULkXA/ -onwGn+J9pXX2f9AZ7ktHhoRmV3ZJgfv2rCcSO1gAwRUyJY2MFfaDMfQchooHS7e0 -+nOFKfHt5QtwkK6TYImWiFZRjoTgsDW8tTFrrR82k6LNUi5Upj3l6t7mxOdWdJBA -U0cmqALW5QQTbnbeJFVlCrTiIRBgB+G+jXBu8C64/HS5rbUUccPXxU8Mi3OnUVVd -R9AL5RothHeCIcw19rAXaU7+o/jNPeTm5mdJqG+3+mca7qBBszvOPCTnMj81fdmX -R7NWCkkT8gAlB602IBhWUUx/Az8zVglsDoL61RNXn5EA2Ajq75qUkalN5zJNytie -AQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBZuxsCprwxByxRab8S97HP1Qpb8dlM -TVdqCYMRNCik4e7l04OAJdX62H1xtL3npoT0C+pM+fkUNk9E18UTvA3jyeQXJ6f+ -z1nzdTbHVE1HANveqvUgq+LqTCTfVLk09mFmEIZnkPVd97XarmxrfCJbCaiYljka -b63ER+87QE9YiN38nZpIlocOcI9QQVpE8boRCjgyJF3i84lIbKgwM32nWs0Sz+p1 -ewWHeQw3oziie3MfH3Xkag341i/k+7VF0FxLuPn7DZB4M5pZmjy0DNA/bdhGNu96 -pOjb/TWp18KMqCMrMAGLz/cjgWqbC4KkzPUtYx6HmCdtVXHWwRV7Lgto ------END CERTIFICATE----- diff --git a/pdf-over-signer/pom.xml b/pdf-over-signer/pom.xml index 4cfdbf90..3f7ca98f 100644 --- a/pdf-over-signer/pom.xml +++ b/pdf-over-signer/pom.xml @@ -7,12 +7,73 @@ .. pdf-over-signer - PDF-Over PDF-Signer libraries - pom + PDF-Over PDF-AS 4 Signer ${project.basedir}/.. + 4.2.1-snapshot - - pdf-over-sigpdfas4 - + + + at.a-sit + pdf-over-signator + ${project.version} + + + at.gv.egiz.pdfas + pdf-as-lib + ${pdfover-build.pdfas-version} + + + at.gv.egiz.pdfas + sigs-pades + ${pdfover-build.pdfas-version} + + + at.gv.egiz.pdfas + pdf-as-pdfbox-2 + ${pdfover-build.pdfas-version} + + + iaik.prod + iaik_jce_full + 5.63_moa + + + iaik + iaik_eccelerate + 3.01 + + + iaik + iaik_cms + 2.15 + + + iaik + iaik_eccelerate_cms + 3.01 + + + at.a-sit + pdf-over-commons + ${project.parent.version} + compile + + + org.apache.pdfbox + pdfbox + 2.0.24 + + + + + EGIZ Maven + EGIZ Maven Repository + https://apps.egiz.gv.at/maven/ + + + local-repo + file://${pdfover-build.root-dir}/repo + + diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java new file mode 100644 index 00000000..124bf43d --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java @@ -0,0 +1,150 @@ +/* + * 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.common.utils.PDFUtils; +import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; +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.trace(slRequestString); + + byte[] signatureData = pack.getSignatureData(); + if (IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD.equals(parameter.getConfiguration().getValue(IConfigurationConstants.SL_REQUEST_TYPE))) + signatureData = PDFUtils.blackOutSignature(signatureData, pack.getByteRange()); + + PdfAs4SLRequest slRequest = new PdfAs4SLRequest(slRequestString, signatureData); + 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.trace(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/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java new file mode 100644 index 00000000..e0b8ff46 --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java @@ -0,0 +1,76 @@ +/* + * 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() { + 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/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java new file mode 100644 index 00000000..87b97ac9 --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java @@ -0,0 +1,47 @@ +/* + * 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 { + setRequest(slRequest); + setSignatureData(signData == null ? null : new ByteArrayDocumentSource(signData)); + } +} diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java new file mode 100644 index 00000000..032416cd --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java @@ -0,0 +1,230 @@ +/* + * 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; +import at.asit.pdfover.commons.Profile; + +/** + * Implementation of SignatureParameter for PDF-AS 4 Library + */ +public class PdfAs4SignatureParameter extends SignatureParameter { + /** + * The profile ID extension for the German signature block + */ + private static final String PROFILE_ID_LANG_DE = "_DE"; + /** + * The profile ID extension for the English signature block + */ + private static final String PROFILE_ID_LANG_EN = "_EN"; + /** + * The profile ID extension for the signature note + */ + private static final String PROFILE_ID_NOTE = "_NOTE"; + /** + * The profile ID extension for PDF/A compatibility + */ + private static final String PROFILE_ID_PDFA = "_PDFA"; + + private static final String PROFILE_ID_RECOMMENDED = "_RECOMMENDED"; + + /** + * Visibility of signature block + */ + public static boolean PROFILE_VISIBILITY = true; + + private HashMap genericProperties = new HashMap(); + + /** + * This parameters are defining the signature block size + */ + private int sig_w = 229; + private int sig_h = 77; + + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory + .getLogger(PdfAs4SignatureParameter.class); + private String profile = Profile.getDefaultProfile(); + + /* (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); + boolean usePdfACompat = (getSignaturePdfACompat()); + + //Add Signature Param here// + String profileId; + + if (!PROFILE_VISIBILITY) { + log.debug("Profile visibility was set to false"); + return Profile.INVISIBLE.name(); + } + + Profile profile = Profile.getProfile(this.profile); + switch (profile) { + case BASE_LOGO: + case INVISIBLE: + return this.profile; + case AMTSSIGNATURBLOCK: + profileId = this.profile; + profileId += getLangProfilePart(lang); + profileId += PROFILE_ID_RECOMMENDED; + return profileId; + default: + profileId = this.profile; + profileId += getLangProfilePart(lang); + break; + } + + if (useNote) + profileId += PROFILE_ID_NOTE; + + if (usePdfACompat) + profileId += PROFILE_ID_PDFA; + + log.debug("Profile ID: {}", profileId); + return profileId; + } + + private String getLangProfilePart(String lang) { + return (lang != null && lang.equals("en")) ? PROFILE_ID_LANG_EN : PROFILE_ID_LANG_DE; + } + + @Override + public void setSignatureProfile(String profile) { + this.profile = profile; + } + + @Override + public String getSignatureProfile() { + return this.profile; + } + +} + + + diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java new file mode 100644 index 00000000..9943ec0e --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -0,0 +1,164 @@ +package at.asit.pdfover.signer.pdfas; + +import java.io.ByteArrayOutputStream; +import java.util.UUID; + +import javax.activation.DataSource; + +import at.asit.pdfover.commons.Profile; +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.IConfigurationConstants; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import at.gv.egiz.pdfas.lib.api.PdfAsFactory; +import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; +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 { + + + + + /** + * The template URL + */ + protected static final String URL_TEMPLATE = "http://pdfover.4.gv.at/template"; + + /** + * Location reference string + */ + protected static final String LOC_REF = "" + URL_TEMPLATE + + ""; + + @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 = null; + if (sign_para.getSignaturePosition() != null) { + 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); + if (sigPos != null) { + param.setSignaturePosition(sigPos); + } + param.setSignatureProfileId(sigProfile); + String id = UUID.randomUUID().toString(); + param.setTransactionId(id); + + if (parameter.isSearchForPlaceholderSignatures()) { + param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_MODE, "1"); + param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_SEARCH_ENABLED, IConfigurationConstants.TRUE); + } + + 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(); + + Configuration config = param.getConfiguration(); + config.setValue(IConfigurationConstants.SL_REQUEST_TYPE, + sstate.getUseBase64Request() ? + IConfigurationConstants.SL_REQUEST_TYPE_BASE64 : + IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD); + + IPlainSigner signer; + if (sstate.hasBKUConnector()) { + ISLConnector connector = new PdfAs4BKUSLConnector(sstate.getBKUConnector()); + signer = new PAdESSigner(connector); + } else if (sstate.hasKSSigner()) { + signer = sstate.getKSSigner(); + } else { + throw new SignatureException("SigningState doesn't have a signer"); + } + param.setPlainSigner(signer); + + pdfas.sign(param); + + SignResultImpl result = new SignResultImpl(); + + if (param.getSignaturePosition() != null) { + 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 if (param.getSignatureProfileId().contains(Profile.AMTSSIGNATURBLOCK.name())) + sp = new SignaturePosition(); + else + sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage()); + result.setSignaturePosition(sp); + } + + result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray())); + return result; + } catch (PdfAsException | PDFASError e) { + throw new SignatureException(e); + } + } + + @Override + public SignatureParameter newParameter() { + return new PdfAs4SignatureParameter(); + } +} diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignerFactory.java new file mode 100644 index 00000000..3fa7ce16 --- /dev/null +++ b/pdf-over-signer/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/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java new file mode 100644 index 00000000..f0aff1c8 --- /dev/null +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java @@ -0,0 +1,192 @@ +/* + * 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.SignatureException; +import at.asit.pdfover.signator.SigningState; +import at.gv.egiz.pdfas.common.exceptions.PDFASError; +import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; +import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; + +/** + * 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 bkuconnector = null; + + private IPlainSigner kssigner = null; + + private boolean useBase64Request; + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.SigningState#getSignatureRequest() + */ + @Override + public SLRequest getSignatureRequest() { + return this.slrequest; + } + + /** + * Sets the SL Request + * @param request The SL Request + */ + public void setSignatureRequest(SLRequest request) { + this.slrequest = request; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.SigningState#setUseBase64Request(boolean) + */ + @Override + public void setUseBase64Request(boolean useBase64Request) { + this.useBase64Request = useBase64Request; + } + + /** + * Gets whether to use base64 (or FileUpload) for request data + * @return whether to use base64 for request data + */ + public boolean getUseBase64Request() { + return this.useBase64Request; + } + + /** + * Gets the SL Response + * @return The SL Response object + */ + public SLResponse getSignatureResponse() { + return this.slresponse; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.SigningState#setSignatureResponse(at.asit.pdfover.signator.SLResponse) + */ + @Override + public void setSignatureResponse(SLResponse response) { + this.slresponse = response; + } + + /* (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.bkuconnector = connector; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.SigningState#setKSSigner(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void setKSSigner(String file, String alias, String kspassword, + String keypassword, String type) throws SignatureException { + try { + this.kssigner = new PAdESSignerKeystore(file, alias, kspassword, keypassword, type); + } catch (PDFASError e) { + throw new SignatureException(e); + } + } + + /** + * @return whether a BKU connector was set + */ + public boolean hasBKUConnector() { + return this.bkuconnector != null; + } + + /** + * @return the BKU connector + */ + public BkuSlConnector getBKUConnector() { + return this.bkuconnector; + } + + /** + * @return whether a KS signer was set + */ + public boolean hasKSSigner() { + return this.kssigner != null; + } + + /** + * @return the KS signer + */ + public IPlainSigner getKSSigner() { + return this.kssigner; + } + +} diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java new file mode 100644 index 00000000..ab50e78b --- /dev/null +++ b/pdf-over-signer/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); + } +} diff --git a/pdf-over-signer/src/main/resources/qualified.cer b/pdf-over-signer/src/main/resources/qualified.cer new file mode 100644 index 00000000..e083c81e --- /dev/null +++ b/pdf-over-signer/src/main/resources/qualified.cer @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDJjCCAg4CCQDj2QcuXR0CJjANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJB +VDEPMA0GA1UECAwGU3R5cmlhMQ0wCwYDVQQHDARHcmF6MQ0wCwYDVQQKDARFR0la +MRcwFQYDVQQDDA5NYXggTXVzdGVybWFubjAeFw0xNDExMDYwOTQyMTVaFw0yNDEx +MDMwOTQyMTVaMFUxCzAJBgNVBAYTAkFUMQ8wDQYDVQQIDAZTdHlyaWExDTALBgNV +BAcMBEdyYXoxDTALBgNVBAoMBEVHSVoxFzAVBgNVBAMMDk1heCBNdXN0ZXJtYW5u +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwKREoPZyoxmmXiULkXA/ +onwGn+J9pXX2f9AZ7ktHhoRmV3ZJgfv2rCcSO1gAwRUyJY2MFfaDMfQchooHS7e0 ++nOFKfHt5QtwkK6TYImWiFZRjoTgsDW8tTFrrR82k6LNUi5Upj3l6t7mxOdWdJBA +U0cmqALW5QQTbnbeJFVlCrTiIRBgB+G+jXBu8C64/HS5rbUUccPXxU8Mi3OnUVVd +R9AL5RothHeCIcw19rAXaU7+o/jNPeTm5mdJqG+3+mca7qBBszvOPCTnMj81fdmX +R7NWCkkT8gAlB602IBhWUUx/Az8zVglsDoL61RNXn5EA2Ajq75qUkalN5zJNytie +AQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBZuxsCprwxByxRab8S97HP1Qpb8dlM +TVdqCYMRNCik4e7l04OAJdX62H1xtL3npoT0C+pM+fkUNk9E18UTvA3jyeQXJ6f+ +z1nzdTbHVE1HANveqvUgq+LqTCTfVLk09mFmEIZnkPVd97XarmxrfCJbCaiYljka +b63ER+87QE9YiN38nZpIlocOcI9QQVpE8boRCjgyJF3i84lIbKgwM32nWs0Sz+p1 +ewWHeQw3oziie3MfH3Xkag341i/k+7VF0FxLuPn7DZB4M5pZmjy0DNA/bdhGNu96 +pOjb/TWp18KMqCMrMAGLz/cjgWqbC4KkzPUtYx6HmCdtVXHWwRV7Lgto +-----END CERTIFICATE----- -- cgit v1.2.3