aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/framework')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/ConnectorFactory.java83
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/DataManager.java35
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/DataStrategy.java37
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/SignatorFactory.java100
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/SignatureHolderHelper.java34
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/VerificatorFactory.java45
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/config/SettingsHelper.java37
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java35
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/input/ExtractionStage.java66
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/input/PdfDataSource.java21
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/input/TextDataSource.java19
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java15
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SequentialSignatureDevice.java25
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SignatureDevice.java16
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/signator/Signator.java56
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/signator/SignatorInformation.java43
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/verificator/Verificator.java53
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilter.java52
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilterParameters.java76
19 files changed, 848 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/ConnectorFactory.java b/src/main/java/at/gv/egiz/pdfas/framework/ConnectorFactory.java
new file mode 100644
index 0000000..65c5af7
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/ConnectorFactory.java
@@ -0,0 +1,83 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework;
+
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.MultipartDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.OldEnvelopingBase64BKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.moa.DetachedLocRefMOAConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.moa.EnvelopingBase64MOAConnector;
+
+/**
+ * @author wprinz
+ */
+public class ConnectorFactory
+{
+ // TODO the functionality of the connector should be split into template
+ // handling and the actualy hardware access
+
+ public static String DETACHED_MULTIPART_BKU_CONNECTOR = "DetachedMultipartBKUConnector";
+
+ public static String ENVELOPING_BASE64_BKU_CONNECTOR = "EnvelopingBase64BKUConnector";
+
+ public static String OLD_ENVELOPING_BASE64_BKU_CONNECTOR = "OldEnvelopingBase64BKUConnector";
+
+ public static String DETACHED_LOCREF_MOA_CONNECTOR = "DetachedLocRefMOAConnector";
+
+ public static String ENVELOPING_BASE64_MOA_CONNECTOR = "EnvelopingBase64MOAConnector";
+
+
+
+ public static Connector createConnector (String connectorId, String profile, String locRef) throws ConnectorFactoryException, ConnectorException
+ {
+ if (connectorId.equals(DETACHED_MULTIPART_BKU_CONNECTOR))
+ {
+ return new MultipartDetachedBKUConnector(profile);
+ }
+
+ if (connectorId.equals(ENVELOPING_BASE64_BKU_CONNECTOR))
+ {
+ return new EnvelopedBase64BKUConnector(profile);
+ }
+
+ if (connectorId.equals(OLD_ENVELOPING_BASE64_BKU_CONNECTOR))
+ {
+ return new OldEnvelopingBase64BKUConnector(profile);
+ }
+
+ if (connectorId.equals(DETACHED_LOCREF_MOA_CONNECTOR))
+ {
+ return new DetachedLocRefMOAConnector(profile, locRef);
+ }
+
+ if (connectorId.equals(ENVELOPING_BASE64_MOA_CONNECTOR))
+ {
+ return new EnvelopingBase64MOAConnector(profile);
+ }
+
+ throw new ConnectorFactoryException("The connector Id " + connectorId + " couldn't be found by the ConnectorFactory.");
+ }
+
+ public static boolean isMOA (String connectorId)
+ {
+ if (connectorId.equals(DETACHED_LOCREF_MOA_CONNECTOR) || connectorId.equals(ENVELOPING_BASE64_MOA_CONNECTOR))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+// public static Connector createConnectorForCommandline (String connectorId) throws ConnectorFactoryException
+// {
+// }
+//
+// public static Connector createConnectorForCommandline (String connectorId) throws ConnectorFactoryException
+// {
+// }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/DataManager.java b/src/main/java/at/gv/egiz/pdfas/framework/DataManager.java
new file mode 100644
index 0000000..1640b07
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/DataManager.java
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework;
+
+/**
+ * The DataManager is a mediator for all components that need to allocate large
+ * data elements.
+ *
+ * <p>
+ * The DataManager uses a certain DataStrategy to perform the actual tasks. The
+ * strategy may be different in different environments. E.g. The commandline may
+ * implement a strategy to keep all data in memory, whereas the web might
+ * implement one that puts as many data onto the disk as possible to save
+ * memory.
+ * </p>
+ *
+ * @author wprinz
+ *
+ */
+public class DataManager
+{
+ protected static DataStrategy dataStrategy = null;
+
+ public static void initialize(DataStrategy ds)
+ {
+ dataStrategy = ds;
+ }
+
+ public static DataStrategy getDataStrategy()
+ {
+ return dataStrategy;
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/DataStrategy.java b/src/main/java/at/gv/egiz/pdfas/framework/DataStrategy.java
new file mode 100644
index 0000000..22f9676
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/DataStrategy.java
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework;
+
+import java.io.InputStream;
+
+import at.gv.egiz.pdfas.framework.input.DataSource;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.framework.output.DataSink;
+
+/**
+ * Factory for creating DataSources.
+ *
+ * @author wprinz
+ */
+public interface DataStrategy
+{
+
+ public TextDataSource createTextDataSource (String text);
+
+ public PdfDataSource createPdfDataSource (InputStream is);
+
+ public PdfDataSource createPdfDataSource (DataSource other, int length);
+
+ /**
+ * @deprecated - use streaming.
+ * @param pdf
+ * @return
+ */
+ public PdfDataSource createPdfDataSource (byte [] pdf);
+
+ public void destroyDataSource (DataSource dataSource);
+
+ public DataSink createDataSink ();
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/SignatorFactory.java b/src/main/java/at/gv/egiz/pdfas/framework/SignatorFactory.java
new file mode 100644
index 0000000..d4ecc26
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/SignatorFactory.java
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework;
+
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatorFactoryException;
+import at.gv.egiz.pdfas.impl.signator.binary.BinarySignator_1_0_0;
+import at.gv.egiz.pdfas.impl.signator.binary.BinarySignator_1_1_0;
+import at.gv.egiz.pdfas.impl.signator.detached.DetachedTextualSignator_1_0_0;
+import at.gv.egiz.pdfas.impl.signator.textual.TextualSignator_1_0_0;
+import at.gv.egiz.pdfas.impl.signator.textual.TextualSignator_1_1_0;
+import at.gv.egiz.pdfas.framework.signator.Signator;
+
+/**
+ * @author wprinz
+ *
+ */
+public class SignatorFactory
+{
+ /**
+ * The Vendor.
+ */
+ public static final String VENDOR = "bka.gv.at"; //$NON-NLS-1$
+
+ /**
+ * The binary Signator algorithm.
+ */
+ public static final String TYPE_BINARY = "binaer"; //$NON-NLS-1$
+
+ /**
+ * The textual Signator algorithm.
+ */
+ public static final String TYPE_TEXTUAL = "text"; //$NON-NLS-1$
+
+ /**
+ * Detached Signator.
+ */
+ public static final String TYPE_DETACHED_TEXTUAL = "detachedtext"; //$NON-NLS-1$
+
+ /**
+ * This application's current algorithm versions.
+ */
+ public static final String VERSION_1_0_0 = "v1.0.0"; //$NON-NLS-1$
+
+ /**
+ * This application's current algorithm versions.
+ */
+ public static final String VERSION_1_1_0 = "v1.1.0"; //$NON-NLS-1$
+
+
+ public static Signator createSignator (PdfASID id) throws SignatorFactoryException
+ {
+ if (!id.getVendor().equals(VENDOR))
+ {
+ throw new SignatorFactoryException("The vendor '" + id.getVendor() + "' is unrecognized by this SignatorFactory. (id='" + id + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ if (id.getType().equals(TYPE_BINARY))
+ {
+ if (id.getVersion().equals(VERSION_1_0_0))
+ {
+ return new BinarySignator_1_0_0();
+ }
+ if (id.getVersion().equals(VERSION_1_1_0))
+ {
+ return new BinarySignator_1_1_0();
+ }
+
+ throw new SignatorFactoryException("The version '" + id.getVersion() + "' of type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ if (id.getType().equals(TYPE_TEXTUAL))
+ {
+ if (id.getVersion().equals(VERSION_1_0_0))
+ {
+ return new TextualSignator_1_0_0();
+ }
+ if (id.getVersion().equals(VERSION_1_1_0))
+ {
+ return new TextualSignator_1_1_0();
+ }
+
+ throw new SignatorFactoryException("The version '" + id.getVersion() + "' of type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ if (id.getType().equals(TYPE_DETACHED_TEXTUAL))
+ {
+ if (id.getVersion().equals(VERSION_1_0_0))
+ {
+ return new DetachedTextualSignator_1_0_0();
+ }
+
+ throw new SignatorFactoryException("The version '" + id.getVersion() + "' of type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ throw new SignatorFactoryException("The type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/SignatureHolderHelper.java b/src/main/java/at/gv/egiz/pdfas/framework/SignatureHolderHelper.java
new file mode 100644
index 0000000..ab77092
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/SignatureHolderHelper.java
@@ -0,0 +1,34 @@
+package at.gv.egiz.pdfas.framework;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import at.knowcenter.wag.egov.egiz.pdf.EGIZDate;
+import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
+
+public final class SignatureHolderHelper
+{
+
+ /**
+ * Sorts the List of SignatureHolders by date.
+ *
+ * @param signatureHolders
+ * The List of SignatureHolders.
+ */
+ public static void sortByDate(List signatureHolders)
+ {
+ Collections.sort(signatureHolders, new Comparator() {
+ public int compare(Object o1, Object o2)
+ {
+ SignatureHolder sh1 = (SignatureHolder) o1;
+ SignatureHolder sh2 = (SignatureHolder) o2;
+
+ EGIZDate date1 = EGIZDate.parseFromString(sh1.getSignatureObject().getSignationDate());
+ EGIZDate date2 = EGIZDate.parseFromString(sh2.getSignatureObject().getSignationDate());
+
+ return date1.compareTo(date2);
+ }
+ });
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/VerificatorFactory.java b/src/main/java/at/gv/egiz/pdfas/framework/VerificatorFactory.java
new file mode 100644
index 0000000..f77ca23
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/VerificatorFactory.java
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework;
+
+import at.gv.egiz.pdfas.exceptions.framework.VerificatorFactoryException;
+import at.gv.egiz.pdfas.framework.verificator.Verificator;
+import at.gv.egiz.pdfas.impl.verificator.binary.BinaryVerificator_1_0_0;
+import at.gv.egiz.pdfas.impl.verificator.binary.BinaryVerificator_1_1_0;
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+
+/**
+ * @author wprinz
+ *
+ */
+public class VerificatorFactory
+{
+
+ public static Verificator createVerificator(PdfASID kz) throws VerificatorFactoryException
+ {
+ if (kz.getType().equals(SignatorFactory.TYPE_BINARY))
+ {
+ return createBinaryVerificator(kz);
+ }
+
+ return null;
+ }
+
+ public static Verificator createBinaryVerificator(PdfASID kz) throws VerificatorFactoryException
+ {
+ assert kz.getType().equals(SignatorFactory.TYPE_BINARY);
+
+ if (kz.equals(BinaryVerificator_1_0_0.MY_ID))
+ {
+ return new BinaryVerificator_1_0_0();
+ }
+ if (kz.equals(BinaryVerificator_1_1_0.MY_ID))
+ {
+ return new BinaryVerificator_1_1_0();
+ }
+
+ throw new VerificatorFactoryException("kz is not a known binary signator " + kz);
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/config/SettingsHelper.java b/src/main/java/at/gv/egiz/pdfas/framework/config/SettingsHelper.java
new file mode 100644
index 0000000..6f67d1d
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/config/SettingsHelper.java
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.config;
+
+import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
+import at.gv.egiz.pdfas.impl.vfilter.VerificationFilterParametersImpl;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+
+/**
+ * Contains helpful Settings functions.
+ * @author wprinz
+ */
+public final class SettingsHelper
+{
+ public static VerificationFilterParameters readVerificationFilterParametersFromSettings() throws SettingsException
+ {
+ boolean binaryOnly = getFlag("binary_only");
+ boolean assumeOnlySB = getFlag("assume_only_signauture_blocks");
+ boolean checkOld = getFlag("check_old_textual_sigs");
+
+ VerificationFilterParameters vfp = new VerificationFilterParametersImpl(binaryOnly, assumeOnlySB, checkOld);
+ return vfp;
+ }
+
+ protected static boolean getFlag (String settingsKey) throws SettingsException
+ {
+ String flag = SettingsReader.getInstance().getSetting(settingsKey, "false");
+ boolean b = true;
+ if (flag.equals("false"))
+ {
+ b = false;
+ }
+ return b;
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java b/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java
new file mode 100644
index 0000000..265cb0c
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.input;
+
+import java.io.InputStream;
+
+/**
+ * The input document data source.
+ *
+ * <p>
+ * Usually this is a PdfDataSource, but it may be a TextDataSource as well.
+ * </p>
+ *
+ * @author wprinz
+ *
+ */
+public interface DataSource
+{
+ /**
+ * Creates a new InputStream that allows to read out the document's binary
+ * data from the beginning.
+ *
+ * @return Returns the InputStream with the binary data.
+ */
+ public InputStream createInputStream();
+
+ /**
+ * Returns the length (number of bytes) of the stream.
+ *
+ * @return Returns the length (number of bytes) of the stream.
+ */
+ public int getLength();
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/ExtractionStage.java b/src/main/java/at/gv/egiz/pdfas/framework/input/ExtractionStage.java
new file mode 100644
index 0000000..36d9bd8
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/input/ExtractionStage.java
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.input;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.exceptions.framework.VerificationFilterException;
+import at.gv.egiz.pdfas.framework.vfilter.VerificationFilter;
+import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
+import at.gv.egiz.pdfas.impl.input.IncrementalUpdateParser;
+import at.gv.egiz.pdfas.impl.vfilter.VerificationFilterImpl;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+
+/**
+ * Extracts all signatures from a given input DataSource.
+ *
+ * @author wprinz
+ */
+public class ExtractionStage
+{
+ /**
+ * The log.
+ */
+ private static final Log log = LogFactory.getLog(ExtractionStage.class);
+
+ public List extractSignatureHolders(final DataSource dataSource, VerificationFilterParameters parameters) throws PresentableException
+ {
+ if (dataSource instanceof PdfDataSource)
+ {
+ PdfDataSource pdfDataSource = (PdfDataSource) dataSource;
+
+ List blocks = parsePdfIntoBlocks(pdfDataSource);
+
+ VerificationFilter vf = new VerificationFilterImpl();
+ List signatures = vf.extractSignatureHolders(pdfDataSource, blocks, parameters);
+
+ return signatures;
+ }
+
+ if (dataSource instanceof TextDataSource)
+ {
+ TextDataSource textDataSource = (TextDataSource) dataSource;
+
+ VerificationFilter vf = new VerificationFilterImpl();
+ List signatures = vf.extractSignaturHolders(textDataSource, parameters);
+
+ return signatures;
+ }
+
+ String msg = "The input DataSource is neither pdf nor text. class.name = " + dataSource.getClass().getName();
+ log.error(msg);
+ throw new VerificationFilterException(ErrorCode.DOCUMENT_CANNOT_BE_READ, msg);
+ }
+
+ protected List parsePdfIntoBlocks(PdfDataSource pdfDataSource) throws PDFDocumentException
+ {
+ List blocks = IncrementalUpdateParser.parsePdfIntoIUBlocks(pdfDataSource);
+ return blocks;
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/PdfDataSource.java b/src/main/java/at/gv/egiz/pdfas/framework/input/PdfDataSource.java
new file mode 100644
index 0000000..b03a67e
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/input/PdfDataSource.java
@@ -0,0 +1,21 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.input;
+
+
+/**
+ * Represents the binary data of a PDF document.
+ *
+ * <p>
+ * This interface allows Pdf data to be handled in an abstract way so that the
+ * storage (byta array, disk etc.) of pdf documents can be separated from the
+ * algorithms.
+ * </p>
+ *
+ * @author wprinz
+ */
+public interface PdfDataSource extends DataSource
+{
+ // jsut a marker interface
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/TextDataSource.java b/src/main/java/at/gv/egiz/pdfas/framework/input/TextDataSource.java
new file mode 100644
index 0000000..c5fd4b1
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/input/TextDataSource.java
@@ -0,0 +1,19 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.input;
+
+/**
+ * Represents a free-text input text to be processed.
+ *
+ * @author wprinz
+ */
+public interface TextDataSource extends DataSource
+{
+ /**
+ * Returns the text to be processed.
+ * @return Returns the text to be processed.
+ */
+ public String getText();
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java b/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java
new file mode 100644
index 0000000..d7d0cc4
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java
@@ -0,0 +1,15 @@
+package at.gv.egiz.pdfas.framework.output;
+
+import java.io.OutputStream;
+
+/**
+ * Output document data sink.
+ *
+ * @author wprinz
+ */
+public interface DataSink
+{
+ public OutputStream createOutputStream(String mimeType);
+
+ public OutputStream createOutputStream(String mimeType, String characterEncoding);
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SequentialSignatureDevice.java b/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SequentialSignatureDevice.java
new file mode 100644
index 0000000..70a28db
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SequentialSignatureDevice.java
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.sigdevice;
+
+/**
+ * A SignatureDevice that can be accessed in a sequential manner.
+ *
+ * <p>
+ * A sequential device handles all necessary steps in sequence. E.g. all the
+ * data is transformed into a http request and sent to a server. The server
+ * processes the request and answers. The response from the server is then
+ * analyzed and returned.
+ * </p>
+ *
+ * @author wprinz
+ */
+public interface SequentialSignatureDevice extends SignatureDevice
+{
+ // This is just a concept how it could be realized in future.
+ public void sign();
+
+ public void verify();
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SignatureDevice.java b/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SignatureDevice.java
new file mode 100644
index 0000000..735dd3c
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/sigdevice/SignatureDevice.java
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.sigdevice;
+
+/**
+ * Performs the task of passing the signature XML and data from the application
+ * to an external signature device and return the response in an form that the
+ * application can use.
+ *
+ * @author wprinz
+ */
+public interface SignatureDevice
+{
+ // Marker interface
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/signator/Signator.java b/src/main/java/at/gv/egiz/pdfas/framework/signator/Signator.java
new file mode 100644
index 0000000..e77ed08
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/signator/Signator.java
@@ -0,0 +1,56 @@
+/**
+ * <copyright> Copyright (c) 2006 by Know-Center, Graz, Austria </copyright>
+ *
+ * This software is the confidential and proprietary information of Know-Center,
+ * Graz, Austria. You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement you entered
+ * into with Know-Center.
+ *
+ * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
+ * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
+ * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES.
+ *
+ * $Id: Signator.java,v 1.1 2006/08/25 17:07:21 wprinz Exp $
+ */
+package at.gv.egiz.pdfas.framework.signator;
+
+import at.gv.egiz.pdfas.exceptions.framework.SignatorException;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.output.DataSink;
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.framework.SignResult;
+import at.knowcenter.wag.egov.egiz.pdf.TablePos;
+
+/**
+ * The basic interface for signator algorithms.
+ *
+ * @author wprinz
+ */
+public interface Signator
+{
+ /**
+ * Returns the PdfASID of this Connector.
+ *
+ * <p>
+ * This should always return the MY_ID static field of the connector. Dont't
+ * forget to override this.
+ * </p>
+ * <p>
+ * Within connector code always use this method so that code reuse through
+ * derivation can take place correctly.
+ * </p>
+ *
+ * @return Returns the PdfASID of this Connector.
+ */
+ public PdfASID getMyId();
+
+
+ public SignatorInformation prepareSign(PdfDataSource pdfDataSource,
+ String profile, TablePos pos, boolean has_SIG_ID) throws SignatorException;
+
+
+ public void finishSign(SignatorInformation signatorInformation, DataSink dataSink) throws SignatorException;
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/signator/SignatorInformation.java b/src/main/java/at/gv/egiz/pdfas/framework/signator/SignatorInformation.java
new file mode 100644
index 0000000..da81e87
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/signator/SignatorInformation.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.signator;
+
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+
+/**
+ * Encapsulates the Signator dependant information that needs to be passed from
+ * prepareSign to finishSign.
+ *
+ * <p>
+ * This supersedes the IncrementalUpdateInformation.
+ * </p>
+ *
+ * @author wprinz
+ */
+public interface SignatorInformation
+{
+ /**
+ * Returns the SignatureData to be signed.
+ * <p>
+ * This is passed on to the Connector and signature device for signing.
+ * </p>
+ *
+ * @return Returns the SignatureData to be signed.
+ */
+ public SignatureData getSignatureData();
+
+ /**
+ * Sets the SignSignatureObject with the signature data.
+ *
+ * <p>
+ * This is called by the framework to provide the finishSign with the
+ * signature data.
+ * </p>
+ *
+ * @param signSignatureObject
+ * The SignSignatureObject.
+ */
+ public void setSignSignatureObject(SignSignatureObject signSignatureObject);
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/verificator/Verificator.java b/src/main/java/at/gv/egiz/pdfas/framework/verificator/Verificator.java
new file mode 100644
index 0000000..b134d64
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/verificator/Verificator.java
@@ -0,0 +1,53 @@
+/**
+ * <copyright> Copyright (c) 2006 by Know-Center, Graz, Austria </copyright>
+ *
+ * This software is the confidential and proprietary information of Know-Center,
+ * Graz, Austria. You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement you entered
+ * into with Know-Center.
+ *
+ * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
+ * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
+ * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES.
+ *
+ * $Id: Verificator.java,v 1.1 2006/08/25 17:07:21 wprinz Exp $
+ */
+package at.gv.egiz.pdfas.framework.verificator;
+
+import java.util.List;
+
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.exactparser.parsing.results.FooterParseResult;
+
+
+/**
+ * Given an Incremental Update Block and the corresponding PDF, a verificator
+ * extracts all Signatures of its type and returns them as valitatable
+ * SignatureHolders.
+ *
+ * @author wprinz
+ */
+public interface Verificator
+{
+ /**
+ * Parses the given document/Block for signatures of this type.
+ *
+ * @param pdf
+ * The whole pdf document. A Verificator must only access the
+ * document up to its given block (block.next_index) and must not
+ * modify any byte in the pdf array.
+ * @param block
+ * The incremental update block.
+ * @param start_of_whole_block
+ * The start of the incremental update block (the end of the previous
+ * block) - If 0, this is the first block (the original Document).
+ * @return Returns the List of SignatureHolder objects found for this block.
+ */
+ public List parseBlock(PdfDataSource pdfDataSource, byte [] pdf, final FooterParseResult block,
+ int start_of_whole_block) throws PresentableException;
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilter.java b/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilter.java
new file mode 100644
index 0000000..1633b09
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilter.java
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.vfilter;
+
+import java.util.List;
+
+import at.gv.egiz.pdfas.exceptions.framework.VerificationFilterException;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.TextDataSource;
+
+/**
+ * Extracts all signatures from a given PDF document or text.
+ *
+ * @see VerificationFilterParameters
+ *
+ * @author wprinz
+ */
+public interface VerificationFilter
+{
+
+ /**
+ * Extracts the signatures from the given PDF.
+ *
+ * @param pdf
+ * The PDF.
+ * @param blocks
+ * The List of Incremental Update blocks. Usually this comes from a
+ * preprocessing step.
+ * @param parameters
+ * The algorithm parameters.
+ * @return Returns a List of SignatureHolders containing the signatures. May
+ * be empty in case no signatures have been found.
+ * @throws VerificationFilterException
+ * Thrown if something goes wrong.
+ */
+ public List extractSignatureHolders(PdfDataSource pdf, List blocks, VerificationFilterParameters parameters) throws VerificationFilterException;
+
+ /**
+ * Extracts the text signatures from the given free-text.
+ *
+ * @param text
+ * The free-text.
+ * @param parameters
+ * The algorithm parameters.
+ * @return Returns a List of SignatureHolders containing the signatures. May
+ * be empty in case no signatures have been found.
+ * @throws VerificationFilterException
+ * Thrown if something goes wrong.
+ */
+ public List extractSignaturHolders(TextDataSource text, VerificationFilterParameters parameters) throws VerificationFilterException;
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilterParameters.java b/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilterParameters.java
new file mode 100644
index 0000000..c518fef
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/framework/vfilter/VerificationFilterParameters.java
@@ -0,0 +1,76 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.framework.vfilter;
+
+/**
+ * The parameters of the VerificationFilter algorithm.
+ *
+ * @author wprinz
+ */
+public interface VerificationFilterParameters
+{
+
+ /**
+ * Tells the VerificationFilter to extract binary signatures only.
+ *
+ * <p>
+ * Not scanning for textual signatures allows the algorithm to skip text
+ * extraction and signature extraction, which are both time and memory
+ * intensive processes.
+ * </p>
+ *
+ * @return Returns true if the VerificationFilter should extract binary
+ * signatures only.
+ */
+ public boolean extractBinarySignaturesOnly();
+
+ /**
+ * Tells the VerificationFilter to assume that there are only singatures (and
+ * their Incremental Update blocks) younger than the original document.
+ *
+ * <p>
+ * This is equivalent to saying that the document was not updated using an
+ * Incremental update block other than a signature after being singed. The
+ * incremental update blocks after the original document contain only
+ * signatures (either text or binary).
+ * </p>
+ * <p>
+ * This is equivalent to saying that there exists no Incremental Update block
+ * that would render a text signature before it invalid.
+ * </p>
+ * <p>
+ * Under this assumption, the process of finding all text signatures
+ * simplifies to one text extraction of the whole document and one signature
+ * extraction. This is of course a massive performance gain.
+ * </p>
+ * <p>
+ * Actually the algorithm performs a text extraction of the whole document not
+ * including trailing binary signature Incremental Update blocks. This means
+ * that if a the last n Incremental Update blocks of a document are binary,
+ * there is no use extract text from them.
+ * </p>
+ * <p>
+ * Note that if there are Incremental Update blocks with text after a
+ * signature thus this assumption does not hold the signatures older than this
+ * block will break.
+ * </p>
+ *
+ * @return Returns true if the Verification filter should assume that there
+ * are only signature blocks after the original document.
+ */
+ public boolean assumeOnlySignatureUpdateBlocks();
+
+ /**
+ * Tells the VerificationFilter so scan for old signatures in the rest text.
+ *
+ * <p>
+ * The rest text is the text of the oldest text signature or the original
+ * document text if there is no text signature.
+ * </p>
+ *
+ * @return Returns true if the VerificationFilter should scan for old text
+ * signatures in the rest text.
+ */
+ public boolean scanForOldSignatures();
+}