diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-09-30 14:24:16 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-09-30 14:24:16 +0200 |
commit | 9a513d43b310f2e6283fa195a8aa11493a7dcb2c (patch) | |
tree | 2038e303e454004ed719cfebe2dfb554571b86b5 /pdf-over-signator/src/main/java/at/asit | |
parent | 96ba5fe6185cfdeb326ae3148ce88f299e41ef25 (diff) | |
download | pdf-over-9a513d43b310f2e6283fa195a8aa11493a7dcb2c.tar.gz pdf-over-9a513d43b310f2e6283fa195a8aa11493a7dcb2c.tar.bz2 pdf-over-9a513d43b310f2e6283fa195a8aa11493a7dcb2c.zip |
kill off pdfover-signator
Diffstat (limited to 'pdf-over-signator/src/main/java/at/asit')
9 files changed, 0 insertions, 702 deletions
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.java deleted file mode 100644 index be3eec4f..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BKUs.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.signator; - -/** - * Enumeration of available BKU types - * - */ -public enum BKUs { - /** Local BKU */ - LOCAL, - - /** Mobile BKU */ - MOBILE, - - /** KeyStore */ - KS, - - /** No BKU */ - NONE -} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BkuSlConnector.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BkuSlConnector.java deleted file mode 100644 index 002c457c..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/BkuSlConnector.java +++ /dev/null @@ -1,30 +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.signator;
-
-// Imports
-
-/**
- *
- */
-public interface BkuSlConnector {
- /**
- * @param request
- * @return SL Response
- * @throws SignatureException
- */
- public String handleSLRequest(PdfAs4SLRequest request) throws SignatureException;
-}
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java deleted file mode 100644 index d0fb6cfe..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -//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-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java deleted file mode 100644 index 3c94f104..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -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-signator/src/main/java/at/asit/pdfover/signator/Emblem.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Emblem.java deleted file mode 100644 index 7f2e305c..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -// 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 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-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java deleted file mode 100644 index ea9fe5fb..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -// 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-signator/src/main/java/at/asit/pdfover/signator/SignResult.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResult.java deleted file mode 100644 index 91bce421..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -//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-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java deleted file mode 100644 index 0ac6534b..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -//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-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java deleted file mode 100644 index 5d0f0457..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/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.signator; - -//Imports - -/** - * Represents the position of a visible signature block - */ -public class SignaturePosition { - - /** - * The x value of the position - */ - protected float x = 0; - - /** - * The y value of the position - */ - protected float 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(float x, float 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(float x, float 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(float x, float y) { - this.x = x; - this.y = y; - } - - /** - * Gets the X value of the position - * @return float the x value of the position - */ - public float getX() { - return this.x; - } - - /** - * Gets the Y value of the position - * @return float the y value of the position - */ - public float 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; - } -} |