summaryrefslogtreecommitdiff
path: root/pdf-over-signer
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-24 14:14:37 +0100
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-11-24 14:14:37 +0100
commitf39ab43fc0120b7fa97028d40acd7851de8d4a99 (patch)
tree335caaa8b701395bae64fbf67ca9afb1776ae658 /pdf-over-signer
parenta4dd755534013449be5573102114d8dcfccba159 (diff)
downloadpdf-over-master.tar.gz
pdf-over-master.tar.bz2
pdf-over-master.zip
Repository moved to GitHub: https://github.com/a-sit/pdf-overHEADmaster
Diffstat (limited to 'pdf-over-signer')
-rw-r--r--pdf-over-signer/pom.xml74
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java33
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/ByteArrayDocumentSource.java55
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/DocumentSource.java44
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java200
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/PDFFileDocumentSource.java88
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignResult.java65
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignatureException.java62
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignaturePosition.java124
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java44
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java172
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java75
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java46
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java213
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignaturePlaceholder.java78
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java183
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java82
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/exceptions/PdfAs4SLRequestException.java34
-rw-r--r--pdf-over-signer/src/main/resources/example.cer19
19 files changed, 0 insertions, 1691 deletions
diff --git a/pdf-over-signer/pom.xml b/pdf-over-signer/pom.xml
deleted file mode 100644
index 159b1ce3..00000000
--- a/pdf-over-signer/pom.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>pdf-over</artifactId>
- <groupId>at.a-sit</groupId>
- <version>4.4.3.1</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>pdf-over-signer</artifactId>
- <name>PDF-Over PDF-AS 4 Signer</name>
- <properties>
- <pdfover-build.root-dir>${project.basedir}/..</pdfover-build.root-dir>
- <pdfover-build.pdfas-version>4.2.1-snapshot</pdfover-build.pdfas-version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>at.gv.egiz.pdfas</groupId>
- <artifactId>pdf-as-lib</artifactId>
- <version>${pdfover-build.pdfas-version}</version>
- </dependency>
- <dependency>
- <groupId>at.gv.egiz.pdfas</groupId>
- <artifactId>sigs-pades</artifactId>
- <version>${pdfover-build.pdfas-version}</version>
- </dependency>
- <dependency>
- <groupId>at.gv.egiz.pdfas</groupId>
- <artifactId>pdf-as-pdfbox-2</artifactId>
- <version>${pdfover-build.pdfas-version}</version>
- </dependency>
- <dependency>
- <groupId>iaik.prod</groupId>
- <artifactId>iaik_jce_full</artifactId>
- <version>5.63_moa</version>
- </dependency>
- <dependency>
- <groupId>iaik</groupId>
- <artifactId>iaik_eccelerate</artifactId>
- <version>3.01</version>
- </dependency>
- <dependency>
- <groupId>iaik</groupId>
- <artifactId>iaik_cms</artifactId>
- <version>2.15</version>
- </dependency>
- <dependency>
- <groupId>iaik</groupId>
- <artifactId>iaik_eccelerate_cms</artifactId>
- <version>3.01</version>
- </dependency>
- <dependency>
- <groupId>at.a-sit</groupId>
- <artifactId>pdf-over-commons</artifactId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.pdfbox</groupId>
- <artifactId>pdfbox</artifactId>
- <version>2.0.24</version>
- </dependency>
- </dependencies>
- <repositories>
- <repository>
- <id>EGIZ Maven</id>
- <name>EGIZ Maven Repository</name>
- <url>https://apps.egiz.gv.at/maven/</url>
- </repository>
- <repository>
- <id>local-repo</id>
- <url>file://${pdfover-build.root-dir}/repo</url>
- </repository>
- </repositories>
-</project>
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java
deleted file mode 100644
index 3ef9cfd5..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/BkuSlConnector.java
+++ /dev/null
@@ -1,33 +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;
-
-import at.asit.pdfover.signer.pdfas.PdfAs4SLRequest;
-
-// Imports
-
-/**
- *
- */
-public interface BkuSlConnector {
- /**
- * @param request
- * @return SL Response
- * @throws SignatureException
- * @throws UserCancelledException
- */
- public String handleSLRequest(PdfAs4SLRequest request) throws SignatureException, UserCancelledException;
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/ByteArrayDocumentSource.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/ByteArrayDocumentSource.java
deleted file mode 100644
index 024722cc..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/ByteArrayDocumentSource.java
+++ /dev/null
@@ -1,55 +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;
-
-//Imports
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-/**
- * A DocumentSource using a byte[] to store the document content
- */
-public class ByteArrayDocumentSource implements DocumentSource {
-
- /**
- * Document content
- */
- protected byte[] data;
-
- /**
- * Constructor with byte[] content
- * @param data the document content
- */
- public ByteArrayDocumentSource(byte[] data) {
- this.data = data;
- }
-
- @Override
- public InputStream getInputStream() {
- return new ByteArrayInputStream(this.data);
- }
-
- @Override
- public int getLength() {
- return this.data.length;
- }
-
- @Override
- public byte[] getByteArray() {
- return this.data;
- }
-
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/DocumentSource.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/DocumentSource.java
deleted file mode 100644
index 2276c257..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/DocumentSource.java
+++ /dev/null
@@ -1,44 +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;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * A Document Source
- */
-public interface DocumentSource {
-
- /**
- * Gets the InputStream for this Document
- * @return InputStream for the document
- * @throws IOException
- */
- public InputStream getInputStream() throws IOException;
-
- /**
- * Get Length of document
- * @return length of the document
- */
- public int getLength();
-
- /**
- * Get Document as byte[]
- * @return byte[] of the Document
- */
- public byte[] getByteArray();
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java
deleted file mode 100644
index 6c368b16..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/Emblem.java
+++ /dev/null
@@ -1,200 +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;
-
-// Imports
-import at.asit.pdfover.commons.Constants;
-import at.asit.pdfover.commons.utils.ImageUtil;
-
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Properties;
-
-import javax.imageio.ImageIO;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO all of this caching business is a bit of a mess
- */
-public class Emblem {
- /**
- * SLF4J Logger instance
- **/
- private static final Logger log = LoggerFactory.getLogger(Emblem.class);
-
- private static final String CACHE_DIR = Constants.CONFIG_DIRECTORY;
- private static final String CACHE_IMG_FILENAME = ".emblem.png";
- private static final String CACHE_IMG_FORMAT = "png";
- private static final String CACHE_PROPS_FILENAME = ".emblem.properties";
-
- private static final String PROPKEY_ORIG_PATH = "IMG";
- private static final String PROPKEY_ORIG_DIGEST = "HSH";
- private static final int MAX_EMBLEM_WIDTH = 480;
- private static final int MAX_EMBLEM_HEIGHT = 600;
-
- private String originalFileName = null;
- private String originalFileHash = null;
- private Image image = null; /* image data, if we have it */
-
- private void lazyLoadImage() {
- if (this.image != null) return;
-
- String filename = getCachedFileName();
- if (this.image != null) return; /* getCachedFileName may have re-generated the cache and populated this.image */
-
- try {
- this.image = ImageUtil.readImageWithEXIFRotation(new File(filename));
- } catch (IOException e) {
- log.warn("Failed to load Emblem image");
- }
- }
-
- public int getWidth() { if (image == null) lazyLoadImage(); return (image != null) ? image.getWidth(null) : 0; }
- public int getHeight() { if (image == null) lazyLoadImage(); return (image != null) ? image.getHeight(null) : 0; }
-
- /**
- * Constructor
- * @param filename
- */
- public Emblem(String filename) {
- this.originalFileName = filename;
- }
-
- private static String getFileHash(String filename) throws IOException {
- InputStream is = Files.newInputStream(Path.of(filename));
- return DigestUtils.md5Hex(is);
- }
-
- private static BufferedImage reduceImageSizeIfNecessary(BufferedImage img, int maxWidth, int maxHeight) {
- int oheight = img.getHeight();
- int owidth = img.getWidth();
-
- double ratio = (double)owidth/(double)oheight;
-
- int height = oheight;
- int width = owidth;
- if (height > maxHeight) {
- height = maxHeight;
- width = (int) (maxHeight * ratio);
- }
- if (width > maxWidth) {
- width = maxWidth;
- height = (int) (maxWidth / ratio);
- }
- BufferedImage result = img;
- if (width != owidth || height != oheight) {
- //scale image
- log.debug("Scaling emblem: " + owidth + "x" + oheight + " to " + width + "x" + height);
- result = new BufferedImage(width, height, img.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : img.getType());
- Graphics2D g = result.createGraphics();
- g.drawImage(img, 0, 0, width, height, null);
- g.dispose();
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.Emblem#getFileName()
- */
- public String getCachedFileName() {
- String emblemImg = this.originalFileName;
- String emblemHsh = null;
- String cachedEmblemFileName = CACHE_DIR + File.separator + CACHE_IMG_FILENAME;
-
- if (emblemImg == null || !(new File(emblemImg).exists()))
- return null;
-
- Properties emblemProps = new Properties();
- // compare cache, try to load if match
- try {
- File cacheProps = new File(CACHE_DIR, CACHE_PROPS_FILENAME);
- if (cacheProps.exists()) {
- InputStream in = new FileInputStream(cacheProps);
- emblemProps.load(in);
- if (emblemImg.equals(emblemProps.getProperty(PROPKEY_ORIG_PATH))) {
- emblemHsh = getFileHash(emblemImg);
- if (emblemHsh.equals(emblemProps.getProperty(PROPKEY_ORIG_DIGEST))) {
- log.debug("Emblem cache hit: " + cachedEmblemFileName);
- return cachedEmblemFileName;
- }
- }
- }
- log.debug("Emblem cache miss");
- } catch (Exception e) {
- log.warn("Can't load emblem cache", e);
- }
-
- try {
- // create new cache
- if (emblemHsh == null)
- emblemHsh = getFileHash(emblemImg);
- emblemProps.setProperty(PROPKEY_ORIG_PATH, emblemImg);
- emblemProps.setProperty(PROPKEY_ORIG_DIGEST, emblemHsh);
- File imgFile = new File(emblemImg);
-
- BufferedImage img = ImageUtil.readImageWithEXIFRotation(imgFile);
- img = reduceImageSizeIfNecessary(img, MAX_EMBLEM_WIDTH, MAX_EMBLEM_HEIGHT);
-
- File file = new File(CACHE_DIR, CACHE_IMG_FILENAME);
- ImageIO.write(img, CACHE_IMG_FORMAT, file); // ignore returned boolean
- this.image = img;
- OutputStream out = new FileOutputStream(new File(CACHE_DIR, CACHE_PROPS_FILENAME));
- emblemProps.store(out, null);
- } catch (IOException e) {
- log.error("Can't save emblem cache", e);
- return this.originalFileName;
- }
- return cachedEmblemFileName;
- }
-
- /**
- * Return the original filename
- * @return the original filename
- */
- public String getOriginalFileName() {
- return this.originalFileName;
- }
-
- /**
- * Return the original filename
- * @return the original filename
- */
- public String getOriginalFileHash() {
- if (this.originalFileHash == null) {
- if (this.originalFileName == null || !(new File(this.originalFileName).exists())) {
- this.originalFileHash = "";
- } else try {
- this.originalFileHash = getFileHash(this.originalFileName);
- } catch (IOException e) {
- log.debug("Error getting file hash", e);
- this.originalFileHash = "";
- }
- }
- return this.originalFileHash;
- }
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/PDFFileDocumentSource.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/PDFFileDocumentSource.java
deleted file mode 100644
index 7dc5ef6a..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/PDFFileDocumentSource.java
+++ /dev/null
@@ -1,88 +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;
-
-// Imports
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-public class PDFFileDocumentSource implements DocumentSource {
- /**
- * SLF4J Logger instance
- **/
- private static final Logger log = LoggerFactory.getLogger(PDFFileDocumentSource.class);
-
- private File file;
-
- private byte[] data = null;
-
- private int len = 0;
-
- /**
- * Default constructor
- * @param file
- */
- public PDFFileDocumentSource(File file) {
- this.file = file;
- }
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.DocumentSource#getInputStream()
- */
- @Override
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.DocumentSource#getLength()
- */
- @Override
- public int getLength() {
- if(this.file.length() > Integer.MAX_VALUE) {
- log.error("File size to big!" + this.file.length());
- }
- this.len = (int) this.file.length();
- return this.len;
- }
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.DocumentSource#getByteArray()
- */
- @Override
- public byte[] getByteArray() {
- if(this.data == null) {
- try {
- InputStream stream = this.getInputStream();
- this.data = new byte[this.getLength()];
- stream.read(this.data);
- stream.close();
- } catch(IOException ex) {
- log.error("Failed to read file!", ex);
- }
- }
- return this.data;
- }
-
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignResult.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignResult.java
deleted file mode 100644
index d9aa5075..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignResult.java
+++ /dev/null
@@ -1,65 +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;
-
-//Imports
-import java.security.cert.X509Certificate;
-
-/**
- * The result of a signature operation
- */
-public class SignResult {
-
- private SignaturePosition position;
- private DocumentSource source;
- private X509Certificate certificate;
-
- public SignaturePosition getSignaturePosition() {
- return this.position;
- }
-
- public DocumentSource getSignedDocument() {
- return this.source;
- }
-
- public X509Certificate getSignerCertificate() {
- return this.certificate;
- }
-
- /**
- * Set the signer certificate
- * @param x509Certificate the signer certificate
- */
- public void setSignerCertificate(X509Certificate x509Certificate) {
- this.certificate = x509Certificate;
- }
-
- /**
- * Set the signature position
- * @param postion the signature position
- */
- public void setSignaturePosition(SignaturePosition postion) {
- this.position = postion;
- }
-
- /**
- * Set the signed document
- * @param source DocumentSource containing the signed document
- */
- public void setSignedDocument(DocumentSource source) {
- this.source = source;
- }
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignatureException.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignatureException.java
deleted file mode 100644
index 87b37dfe..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignatureException.java
+++ /dev/null
@@ -1,62 +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;
-
-//Imports
-
-/**
- * Base class for signature exceptions
- */
-public class SignatureException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 711578398780816710L;
-
-
- /**
- * Empty constructor
- */
- public SignatureException() {
- super();
- }
-
- /**
- * Constructor with causing exception
- * @param cause the cause
- */
- public SignatureException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructor with message
- * @param msg the message
- */
- public SignatureException(String msg) {
- super(msg);
- }
-
- /**
- * Constructor with message and causing exception
- * @param message the message
- * @param cause the cause
- */
- public SignatureException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignaturePosition.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignaturePosition.java
deleted file mode 100644
index 450277f0..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/SignaturePosition.java
+++ /dev/null
@@ -1,124 +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;
-
-//Imports
-
-/**
- * Represents the position of a visible signature block
- */
-public class SignaturePosition {
-
- /**
- * The x value of the position
- */
- protected double x = 0;
-
- /**
- * The y value of the position
- */
- protected double y = 0;
-
- /**
- * The page value of the position
- */
- protected int page = 0;
-
- /**
- * Whether automatic positioning is used
- */
- protected boolean autoPositioning;
-
- /**
- * Default constructor
- * No position given, hence automatic positioning will be used
- */
- public SignaturePosition() {
- this.autoPositioning = true;
- }
-
- /**
- * X - Y Constructor (Page = 0)
- * @param x The x value of the position
- * @param y The y value of the position
- */
- public SignaturePosition(double x, double y) {
- this.autoPositioning = false;
- setPosition(x, y);
- }
-
- /**
- * Constructor
- * @param x The x value of the signature position
- * @param y The y value of the signature position
- * @param page The page value of the signature position
- */
- public SignaturePosition(double x, double y, int page) {
- this.autoPositioning = false;
- setPosition(x, y);
- setPage(page);
- }
-
- /**
- * Sets new position
- * @param x the new x value
- * @param y the new y value
- */
- public void setPosition(double x, double y) {
- this.x = x;
- this.y = y;
- }
-
- /**
- * Gets the X value of the position
- * @return double the x value of the position
- */
- public double getX() {
- return this.x;
- }
-
- /**
- * Gets the Y value of the position
- * @return double the y value of the position
- */
- public double getY() {
- return this.y;
- }
-
- /**
- * Sets Page value of position
- * @param page the new page value
- */
- public void setPage(int page) {
- this.page = page;
- }
-
- /**
- * Gets the Page value of the position
- * @return int the page value of the position
- */
- public int getPage() {
- return this.page;
- }
-
- /**
- * Gets whether automatic positioning is used
- * @return true if the signature position is determined automatically
- */
- public boolean useAutoPositioning() {
- return this.autoPositioning;
- }
-}
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java
deleted file mode 100644
index ff1b4db8..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/UserCancelledException.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package at.asit.pdfover.signer;
-
-/**
- * The user cancelled the operation.
- */
-public class UserCancelledException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = -7341854663858331004L;
-
- /**
- * Empty constructor
- */
- public UserCancelledException() {
- super();
- }
-
- /**
- * Constructor with causing exception
- * @param cause the cause
- */
- public UserCancelledException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructor with message
- * @param msg the message
- */
- public UserCancelledException(String msg) {
- super(msg);
- }
-
- /**
- * Constructor with message and causing exception
- * @param message the message
- * @param cause the cause
- */
- public UserCancelledException(String message, Throwable cause) {
- super(message, cause);
- }
-}
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
deleted file mode 100644
index 1396255a..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4BKUSLConnector.java
+++ /dev/null
@@ -1,172 +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.signer.BkuSlConnector;
-import at.asit.pdfover.signer.SignatureException;
-import at.asit.pdfover.signer.UserCancelledException;
-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 {
- try {
- String slRequestString = SLMarschaller.marshalToString(this.of.createInfoboxReadRequest(request));
-
- String slResponse = this.connector.handleSLRequest(new PdfAs4SLRequest(slRequestString, null));
-
- element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
- } catch (SignatureException e) {
- Throwable c = e;
- while (c.getCause() != null)
- c = c.getCause();
- if (c instanceof IllegalStateException) // TODO: this is a legacy hack, remove it?
- throw new UserCancelledException(e);
- else
- throw e;
- }
- } 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);
- } catch (UserCancelledException e) {
- throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen.");
- }
-
- if (element == null) {
- throw new PDFIOException("error.pdf.io.04");
- }
-
- if (element.getValue() instanceof InfoboxReadResponseType) {
- return (InfoboxReadResponseType) element.getValue();
- } 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");
- }
-
- /** hack cf. #52 */
- public static Exception originalExceptionSwallowedByPDFASNPE = null;
- /* (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 {
- /* outermost try blocks are a hack cf. #52 */
-try { try {
- JAXBElement<?> element = null;
- try {
-
- String slRequestString = SLMarschaller.marshalToString(this.of.createCreateCMSSignatureRequest(pack.getRequestType()));
-
- 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);
-
- try {
- String slResponse = this.connector.handleSLRequest(slRequest);
-
- element = (JAXBElement<?>) SLMarschaller.unmarshalFromString(slResponse);
- } catch (SignatureException e) {
- Throwable c = e;
- while (c.getCause() != null)
- c = c.getCause();
- if (c instanceof IllegalStateException) // TODO: this is a legacy hack, remove it?
- throw new UserCancelledException(e);
- else
- throw e;
- }
- } 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);
- } catch (UserCancelledException e) {
- throw new SLPdfAsException(6001, "Vorgang durch den Benutzer abgebrochen.");
- }
-
- 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");
-} finally { originalExceptionSwallowedByPDFASNPE = null; } } catch (Exception e) { originalExceptionSwallowedByPDFASNPE = e; throw e; }
- }
-
-}
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
deleted file mode 100644
index 45dc2724..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Helper.java
+++ /dev/null
@@ -1,75 +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.signer.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
deleted file mode 100644
index d4e46e17..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SLRequest.java
+++ /dev/null
@@ -1,46 +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;
-
-import at.asit.pdfover.signer.ByteArrayDocumentSource;
-import at.asit.pdfover.signer.pdfas.exceptions.PdfAs4SLRequestException;
-
-/**
- * PDF - AS Security Layer Request implementation
- */
-public class PdfAs4SLRequest {
-
- /**
- * The security layer request
- */
- public final String xmlRequest;
-
- /**
- * The document to be signed
- */
- public final ByteArrayDocumentSource signatureData;
-
- /**
- * Default constructor
- * @param slRequest
- * @param signData
- * @throws PdfAs4SLRequestException
- */
- public PdfAs4SLRequest(String slRequest, byte[] signData) throws PdfAs4SLRequestException {
- this.xmlRequest = slRequest;
- this.signatureData = (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
deleted file mode 100644
index ee8c2741..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java
+++ /dev/null
@@ -1,213 +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.Color;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.image.BufferedImage;
-import java.util.Locale;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import at.asit.pdfover.signer.DocumentSource;
-import at.asit.pdfover.signer.Emblem;
-import at.asit.pdfover.signer.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.BKUs;
-import at.asit.pdfover.commons.Constants;
-import at.asit.pdfover.commons.Profile;
-
-/**
- * Implementation of SignatureParameter for PDF-AS 4 Library
- */
-public class PdfAs4SignatureParameter {
- /**
- * SLF4J Logger instance
- **/
- private static final Logger log = LoggerFactory.getLogger(PdfAs4SignatureParameter.class);
-
- /**
- * this is set by CliArguments.InvisibleProfile
- * TODO: this is a no good, very bad, hack
- */
- public static boolean PROFILE_VISIBILITY = true;
-
- /** The Signature Position */
- public SignaturePosition signaturePosition = null;
-
- /** The Signature language */
- public String signatureLanguage = null;
-
- /** The key identifier */
- public String keyIdentifier = null;
-
- /** The input document */
- public DocumentSource inputDocument = null;
-
- /** Holds the emblem */
- public Emblem emblem;
-
- /** Whether to use PDF/A compatibility */
- public boolean enablePDFACompat;
-
- /** The signature device */
- public BKUs signatureDevice;
-
- /** The siganture note, if any */
- public String signatureNote = null;
-
- /** Whether so look for placeholder signatures or not. */
- public boolean searchForPlaceholderSignatures = false;
-
- /** The size to scale the logo to (in mm) */
- public double targetLogoSize = Constants.DEFAULT_LOGO_ONLY_SIZE;
-
- /** The signature profile in use */
- public Profile signatureProfile = Profile.getDefaultProfile();
-
- Image getPlaceholder() {
- String sigProfile = getPdfAsSignatureProfileId();
-
- String sigEmblem = (this.emblem == null ? null : this.emblem.getCachedFileName());
- String sigNote = this.signatureNote;
-
- try {
- X509Certificate cert = new X509Certificate(PdfAs4SignatureParameter.class.getResourceAsStream("/example.cer"));
-
- PdfAs pdfas = PdfAs4Helper.getPdfAs();
- synchronized (PdfAs4Helper.class) {
- 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);
- }
- if (this.signatureProfile == Profile.BASE_LOGO)
- {
- int emblemWidth = (this.emblem != null) ? this.emblem.getWidth() : 1;
- int emblemHeight = (this.emblem != null) ? this.emblem.getHeight() : 1;
- double aspectRatio = ((double)emblemWidth) / emblemHeight;
- double targetWidth = this.targetLogoSize * Constants.PDF_UNITS_PER_MM;
- double targetHeight = this.targetLogoSize * Constants.PDF_UNITS_PER_MM;
- if (aspectRatio < 1)
- targetWidth *= aspectRatio;
- else
- targetHeight /= aspectRatio;
- conf.setValue("sig_obj." + sigProfile + ".table.main.Style.padding", "0");
- conf.setValue("sig_obj." + sigProfile + ".pos", "w:"+targetWidth+";f:0");
- conf.setValue("sig_obj." + sigProfile + ".table.main.Style.imagescaletofit", targetWidth+";"+targetHeight);
- }
- SignParameter param = PdfAsFactory.createSignParameter(conf, null, null);
- param.setSignatureProfileId(sigProfile);
-
- Image placeholder = pdfas.generateVisibleSignaturePreview(param, cert, 72 * 4);
-
- // WORKAROUND for #110, manually paint a black border
- if ((placeholder != null) && !this.signatureProfile.equals(Profile.BASE_LOGO))
- {
- Graphics2D ctx = (Graphics2D)placeholder.getGraphics();
- ctx.setColor(Color.BLACK);
- ctx.drawRect(0, 0, placeholder.getWidth(null)-1, placeholder.getHeight(null)-1);
- }
-
- return placeholder;
- }
- } catch (Exception e) {
- log.error("Failed to get signature placeholder", e);
- return new BufferedImage(229, 77, BufferedImage.TYPE_INT_RGB);
- }
- }
-
- /**
- * Gets the Signature Position String for PDF-AS
- *
- * @return Signature Position String
- */
- public String getPdfAsSignaturePosition() {
- SignaturePosition in_pos = this.signaturePosition;
-
- if (in_pos.useAutoPositioning())
- return "p:auto;x:auto;y:auto";
-
- if (in_pos.getPage() < 1)
- {
- return String.format(
- (Locale) null,
- "p:new;x:%f;y:%f", in_pos.getX(), in_pos.getY());
- } else {
- return String.format(
- (Locale) null,
- "p:%d;x:%f;y:%f", in_pos.getPage(), in_pos.getX(), in_pos.getY());
- }
- }
-
- /**
- * Get the Signature Profile ID for this set of parameters
- *
- * @return the Signature Profile ID
- */
- public String getPdfAsSignatureProfileId() {
-
- //Add Signature Param here//
- String profileId;
-
- if (!PROFILE_VISIBILITY) {
- log.debug("Profile visibility was set to false");
- return Profile.INVISIBLE.name();
- }
-
- switch (this.signatureProfile) {
- case BASE_LOGO:
- case INVISIBLE:
- return this.signatureProfile.name();
- case AMTSSIGNATURBLOCK:
- profileId = this.signatureProfile.name();
- profileId += getLangProfilePart(this.signatureLanguage);
- profileId += "_RECOMMENDED";
- return profileId;
- default:
- profileId = this.signatureProfile.name();
- profileId += getLangProfilePart(this.signatureLanguage);
- break;
- }
-
- if (this.signatureNote != null)
- profileId += "_NOTE";
-
- if (this.enablePDFACompat)
- profileId += "_PDFA";
-
- log.debug("Profile ID: {}", profileId);
- return profileId;
- }
-
- private static String getLangProfilePart(String lang) {
- return ("en".equals(lang)) ? "_EN" : "_DE";
- }
-}
-
-
-
diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignaturePlaceholder.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignaturePlaceholder.java
deleted file mode 100644
index 04bbcfdf..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignaturePlaceholder.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package at.asit.pdfover.signer.pdfas;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.TreeMap;
-import java.util.function.Consumer;
-
-import at.asit.pdfover.commons.Profile;
-import at.asit.pdfover.commons.utils.ImageUtil;
-
-/**
- * caches placeholders for signature parameters (placeholder generation is pretty slow)
- */
-public final class PdfAs4SignaturePlaceholder implements Runnable {
- private static TreeMap<PdfAs4SignatureParameter, PdfAs4SignaturePlaceholder> cache = new TreeMap<>(
- Comparator
- .comparing(PdfAs4SignatureParameter::getPdfAsSignatureProfileId)
- .thenComparing((p) -> { return (p.emblem != null) ? p.emblem.getOriginalFileHash() : ""; })
- .thenComparing((p) -> { return p.signatureNote; }, Comparator.nullsFirst(String::compareTo))
- .thenComparing((p) -> { return p.targetLogoSize; })
- );
-
- /**
- * request a placeholder for the specified parameter asynchronously
- * @param callback the callback to be invoked on completion (may also be invoked before this function returns!)
- */
- public static void For(PdfAs4SignatureParameter param, Consumer<PdfAs4SignaturePlaceholder> callback) {
- synchronized(cache) {
- cache.computeIfAbsent(param, (p) -> new PdfAs4SignaturePlaceholder(p)).AddCallback(callback);
- }
- }
-
- private final PdfAs4SignatureParameter param;
- private PdfAs4SignaturePlaceholder(PdfAs4SignatureParameter param) {
- this.param = param;
- new Thread(this).start();
- }
-
- private java.awt.image.BufferedImage awtImageData;
- public boolean hasImage() { return ((this.awtImageData != null) && (this.swtImageData != null)); }
- /** AWT image data for the placeholder */
- public java.awt.image.BufferedImage getAWTImage() { return this.awtImageData; }
- private org.eclipse.swt.graphics.ImageData swtImageData;
- /** SWT image data for the placeholder */
- public org.eclipse.swt.graphics.ImageData getSWTImage() { return this.swtImageData; }
-
- private ArrayList<Consumer<PdfAs4SignaturePlaceholder>> callbacks = new ArrayList<>();
- private void AddCallback(Consumer<PdfAs4SignaturePlaceholder> c) {
- synchronized (this) {
- if (this.callbacks != null)
- {
- this.callbacks.add(c);
- return;
- } /* else... */
- }
- /* ... else, not synchronized */
- c.accept(this);
- }
-
-
- @Override
- public void run() {
- if (!Profile.INVISIBLE.name().equals(this.param.getPdfAsSignatureProfileId())) {
- this.awtImageData = (java.awt.image.BufferedImage) this.param.getPlaceholder();
- this.swtImageData = ImageUtil.convertToSWT(this.awtImageData);
- } else {
- this.awtImageData = null;
- this.swtImageData = null;
- }
- ArrayList<Consumer<PdfAs4SignaturePlaceholder>> _callbacks;
- synchronized (this) {
- _callbacks = this.callbacks;
- this.callbacks = null;
- }
- _callbacks.forEach((c) -> c.accept(this));
- }
-
-}
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
deleted file mode 100644
index 7afa4ec5..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
+++ /dev/null
@@ -1,183 +0,0 @@
-package at.asit.pdfover.signer.pdfas;
-
-import java.io.ByteArrayOutputStream;
-import java.util.Objects;
-import java.util.UUID;
-
-import javax.activation.DataSource;
-
-import at.asit.pdfover.commons.Constants;
-import at.asit.pdfover.commons.Profile;
-import at.asit.pdfover.signer.ByteArrayDocumentSource;
-import at.asit.pdfover.signer.SignResult;
-import at.asit.pdfover.signer.SignatureException;
-import at.asit.pdfover.signer.SignaturePosition;
-import at.asit.pdfover.signer.UserCancelledException;
-import at.gv.egiz.pdfas.common.exceptions.PDFASError;
-import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
-import at.gv.egiz.pdfas.common.exceptions.SLPdfAsException;
-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 {
-
- /**
- * 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>";
-
- public static PdfAs4SigningState prepare(PdfAs4SignatureParameter parameter) throws SignatureException {
-
- if (parameter == null) {
- throw new SignatureException("Incorrect SignatureParameter!");
- }
-
- String sigProfile = parameter.getPdfAsSignatureProfileId();
- String sigEmblem = (parameter.emblem == null ? null : parameter.emblem.getCachedFileName());
- String sigNote = parameter.signatureNote;
- String sigPos = null;
- if (parameter.signaturePosition != null) {
- sigPos = parameter.getPdfAsSignaturePosition();
- }
-
- PdfAs pdfas = PdfAs4Helper.getPdfAs();
- synchronized (PdfAs4Helper.class) {
- 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);
- }
-
- // TODO encapsulate this parameter magic in PdfAs4SignatureParameter
- if (parameter.signatureProfile == Profile.BASE_LOGO)
- {
- int emblemWidth = (parameter.emblem != null) ? parameter.emblem.getWidth() : 1;
- int emblemHeight = (parameter.emblem != null) ? parameter.emblem.getHeight() : 1;
- double aspectRatio = ((double)emblemWidth) / emblemHeight;
- double targetWidth = parameter.targetLogoSize * Constants.PDF_UNITS_PER_MM;
- double targetHeight = parameter.targetLogoSize * Constants.PDF_UNITS_PER_MM;
- if (aspectRatio < 1)
- targetWidth *= aspectRatio;
- else
- targetHeight /= aspectRatio;
- config.setValue("sig_obj." + sigProfile + ".table.main.Style.padding", "0");
- config.setValue("sig_obj." + sigProfile + ".pos", "w:"+targetWidth+";f:0");
- config.setValue("sig_obj." + sigProfile + ".table.main.Style.imagescaletofit", targetWidth+";"+targetHeight);
- }
-
- PdfAs4SigningState state = new PdfAs4SigningState();
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- DataSource input = new ByteArrayDataSource(parameter.inputDocument.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.searchForPlaceholderSignatures) {
- param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_MODE, "1");
- param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_SEARCH_ENABLED, IConfigurationConstants.TRUE);
- }
-
- state.signParameter = param;
- state.output = output;
- return state;
- }
- }
-
- public static SignResult sign(PdfAs4SigningState state) throws SignatureException, UserCancelledException {
- try {
- if (state == null) {
- throw new SignatureException("Incorrect SigningState!");
- }
-
- PdfAs pdfas = PdfAs4Helper.getPdfAs();
- synchronized (PdfAs4Helper.class) {
- // Retrieve objects
- SignParameter param = state.signParameter;
-
- Configuration config = param.getConfiguration();
- config.setValue(IConfigurationConstants.SL_REQUEST_TYPE,
- state.useBase64Request ?
- IConfigurationConstants.SL_REQUEST_TYPE_BASE64 :
- IConfigurationConstants.SL_REQUEST_TYPE_UPLOAD);
-
- IPlainSigner signer;
- if (state.bkuConnector != null) {
- ISLConnector connector = new PdfAs4BKUSLConnector(state.bkuConnector);
- signer = new PAdESSigner(connector);
- } else if (state.hasKeystoreSigner()) {
- signer = state.getKeystoreSigner();
- } else {
- throw new SignatureException("SigningState doesn't have a signer");
- }
- param.setPlainSigner(signer);
-
- pdfas.sign(param);
-
- SignResult result = new SignResult();
-
- 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(state.output.toByteArray()));
- return result;
- }
- } catch (PdfAsException | PDFASError ex) {
- // workaround for PDF-AS nullpointerexception intercepting the actual exception
- // cf. issue #52
- // this is a bit of a hack...
- Exception e = ex;
- {
- if ((e instanceof PDFASError) && (e.getCause() instanceof NullPointerException))
- e = Objects.requireNonNullElse(PdfAs4BKUSLConnector.originalExceptionSwallowedByPDFASNPE, e);
- }
-
- {
- Throwable rootCause = e;
- while (rootCause.getCause() != null)
- rootCause = rootCause.getCause();
- try { /* error code 60xx is user cancellation */
- int errorCode = ((SLPdfAsException)rootCause).getCode();
- if ((6000 <= errorCode) && (errorCode <= 6099))
- throw new UserCancelledException();
- } catch (ClassCastException e2) { /* fall through to wrapped throw */}
- }
-
- throw new SignatureException(e);
- }
- }
-}
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
deleted file mode 100644
index 3ff0f75a..00000000
--- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SigningState.java
+++ /dev/null
@@ -1,82 +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.signer.BkuSlConnector;
-import at.asit.pdfover.signer.SignatureException;
-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 {
-
- /**
- * The Signature Layer request
- */
- public PdfAs4SLRequest signatureRequest;
-
- /**
- * The Signature Layer response
- */
- public String signatureResponse;
-
- /**
- * The Sign Parameters
- */
- public SignParameter signParameter;
-
- public ByteArrayOutputStream output;
-
- public BkuSlConnector bkuConnector = null;
-
- private IPlainSigner keystoreSigner = null;
-
- public boolean useBase64Request;
-
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SigningState#setKSSigner(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
- */
- public void setKeystoreSigner(String file, String alias, String kspassword,
- String keypassword, String type) throws SignatureException {
- try {
- this.keystoreSigner = new PAdESSignerKeystore(file, alias, kspassword, keypassword, type);
- } catch (PDFASError e) {
- throw new SignatureException(e);
- }
- }
-
- /**
- * @return whether a KS signer was set
- */
- public boolean hasKeystoreSigner() {
- return this.keystoreSigner != null;
- }
-
- /**
- * @return the KS signer
- */
- public IPlainSigner getKeystoreSigner() {
- return this.keystoreSigner;
- }
-
-}
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
deleted file mode 100644
index ab50e78b..00000000
--- a/pdf-over-signer/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/src/main/resources/example.cer b/pdf-over-signer/src/main/resources/example.cer
deleted file mode 100644
index e083c81e..00000000
--- a/pdf-over-signer/src/main/resources/example.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-----