aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java227
1 files changed, 100 insertions, 127 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
index 9359c96..98a164d 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -19,6 +19,7 @@ package at.knowcenter.wag.egov.egiz;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -30,7 +31,6 @@ import org.apache.commons.logging.LogFactory;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
-import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
@@ -60,11 +60,8 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypeDefinition;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.DetachedBKUConnector;
-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.ConnectorChooser;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
-import at.knowcenter.wag.egov.egiz.sig.connectors.moa.EnvelopingBase64MOAConnector;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.Normalizer;
import at.knowcenter.wag.exactparser.ParseDocument;
@@ -773,6 +770,21 @@ public abstract class PdfAS
}
return results;
}
+
+ // TODO the choosing algorithm should be extracted into a visitor or factory design pattern.
+ public static List verifySignatureHoldersWeb(List signature_holders,
+ String connector, String loc_ref) throws PDFDocumentException, NormalizeException, SignatureException
+ {
+ List results = new ArrayList();
+ for (int i = 0; i < signature_holders.size(); i++)
+ {
+ SignatureHolder holder = (SignatureHolder) signature_holders.get(i);
+
+ SignatureResponse result = verifyWeb(holder, connector, loc_ref);
+ results.add(result);
+ }
+ return results;
+ }
/**
* Verifies a SignatureHolder using the given connector.
@@ -810,40 +822,95 @@ public abstract class PdfAS
throw new SignatureException(312, "Document can not be verified because no signature object are set.");
}
- try
+ // FIXME this has to be made better
+ SignatureData sd = null;
+ if (so_to_be_verified.isBinary())
+ {
+ byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+ sd = new SignatureDataImpl(data, "application/pdf");
+ }
+ else
{
- // FIXME this has to be made better
- SignatureData sd = null;
- if (so_to_be_verified.isBinary())
+ try
{
- byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
- sd = new SignatureDataImpl(data, "application/pdf");
+ sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
}
- else
+ catch (UnsupportedEncodingException e)
{
- sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
+ throw new RuntimeException("Very Strange: UTF-8 character encoding not supported???");
}
+ }
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = so_to_be_verified.getSignationDate();
+ so.signatureValue = so_to_be_verified.getSignationValue();
+ so.issuer = so_to_be_verified.getSignationIssuer();
+ so.x509Certificate = so_to_be_verified.getX509Cert().getX509Certificate();
+ so.id = so_to_be_verified.getSignationIds();
+ so.kz = so_to_be_verified.getKZ() == null ? null : so_to_be_verified.getKZ().toString();
+
+ String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
+ Connector c = ConnectorChooser.chooseCommandlineConnectorForVerify(connector, so_to_be_verified.getKZ(), so.id, profile);
- SignSignatureObject so = new SignSignatureObject();
- so.date = so_to_be_verified.getSignationDate();
- so.signatureValue = so_to_be_verified.getSignationValue();
- so.issuer = so_to_be_verified.getSignationIssuer();
- so.x509Certificate = so_to_be_verified.getX509Cert().getX509Certificate();
- so.id = so_to_be_verified.getSignationIds();
- so.kz = so_to_be_verified.getKZ().toString();
+ return c.doVerify(sd, so);
- String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
- Connector connector_impl = chooseConnector(profile, so_to_be_verified.getKZ(), so.getSigID(), connector);
+ }
+
+ // TODO make this better using the visitor DP.
+ public static SignatureResponse verifyWeb(SignatureHolder signature_holder,
+ String connector, String loc_ref) throws NormalizeException, PDFDocumentException, SignatureException
+ {
+ String text_to_be_verified = signature_holder.getSignedText();
+ // logger_.debug("verify text_to_be_verified"+text_to_be_verified);
+ SignatureObject so_to_be_verified = signature_holder.getSignatureObject();
- // Connector connector_impl = ConnectorFactory.createConnector(connector);
- return connector_impl.doVerify(sd, so);
+ if (text_to_be_verified == null)
+ {
+ throw new SignatureException(311, "Document can not be verified because the text to be verified is either null.");
}
- catch (Exception e)
+ if (text_to_be_verified.length() <= 0)
{
- throw new SignatureException(310, e);
+ throw new SignatureException(311, "Document can not be verified because the length of the text to be verified is 0. (length = " + text_to_be_verified.length() + ")");
}
- }
+ if (so_to_be_verified == null)
+ {
+ throw new SignatureException(312, "Document can not be verified because no signature object are set.");
+ }
+
+ // FIXME this has to be made better
+ SignatureData sd = null;
+ if (so_to_be_verified.isBinary())
+ {
+ byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+ sd = new SignatureDataImpl(data, "application/pdf");
+ }
+ else
+ {
+ try
+ {
+ sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException("Very Strange: UTF-8 character encoding not supported???");
+ }
+ }
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = so_to_be_verified.getSignationDate();
+ so.signatureValue = so_to_be_verified.getSignationValue();
+ so.issuer = so_to_be_verified.getSignationIssuer();
+ so.x509Certificate = so_to_be_verified.getX509Cert().getX509Certificate();
+ so.id = so_to_be_verified.getSignationIds();
+ so.kz = so_to_be_verified.getKZ() == null ? null : so_to_be_verified.getKZ().toString();
+
+ String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
+ Connector c = ConnectorChooser.chooseWebConnectorForVerify(connector, so_to_be_verified.getKZ(), so.id, profile, loc_ref);
+
+ return c.doVerify(sd, so);
+
+ }
/**
* Signs the given text with the provided connector using the given signature
* type.
@@ -861,7 +928,7 @@ public abstract class PdfAS
* F.e.
*/
public static SignSignatureObject sign(final SignatureData data_to_sign,
- final String signature_type, final String connector) throws SignatureException, PDFDocumentException
+ final Connector connector) throws SignatureException, PDFDocumentException
{
if (data_to_sign == null || data_to_sign.getData() == null)
{
@@ -872,17 +939,8 @@ public abstract class PdfAS
throw new SignatureException(301, "Signature can not be produced. Data is empty. (length = " + data_to_sign.getData().length + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
- try
- {
- Connector connector_impl = chooseDetachedMultipartConnector(signature_type, connector);
-
- SignSignatureObject signed_signature_object = connector_impl.doSign(data_to_sign);
- return signed_signature_object;
- }
- catch (ConnectorFactoryException e)
- {
- throw new SignatureException(300, e);
- }
+ SignSignatureObject signed_signature_object = connector.doSign(data_to_sign);
+ return signed_signature_object;
}
/**
@@ -937,7 +995,9 @@ public abstract class PdfAS
IncrementalUpdateInformation iui = signator.prepareSign(pdf, signature_type, pos, ConnectorFactory.needsSIG_ID(connector));
- iui.signed_signature_object = sign(iui.signature_data, signature_type, connector);
+ Connector c = ConnectorChooser.chooseCommandlineConnectorForSign(connector, signature_type);
+
+ iui.signed_signature_object = sign(iui.signature_data, c);
SignResult sign_result = signator.finishSign(iui);
@@ -1333,91 +1393,4 @@ public abstract class PdfAS
return pos;
}
- /**
- *
- * @param sig_kz
- * @param sig_id
- * @return Returns the chosen Connector.
- * @throws ConnectorFactoryException
- */
- public static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseConnector(
- String profile,
- PdfASID sig_kz, String sig_id, String sig_app) throws ConnectorFactoryException, ConnectorException
- {
- log.debug("chooseConnector:"); //$NON-NLS-1$
-
- log.debug("sig_kz = " + sig_kz); //$NON-NLS-1$
- log.debug("sig_id = " + sig_id); //$NON-NLS-1$
- log.debug("sig_app = " + sig_app); //$NON-NLS-1$
-
- if (sig_kz == null)
- {
- log.debug("sig_kz is null ==> alte Signatur"); //$NON-NLS-1$
-
- return chooseEnvelopedBase64Connector(profile, sig_app);
- }
-
- {
- log.debug("sig_kz is not null ==> one of the newer signatures");
-
- if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_0_0))
- {
- log.debug("Version is 1.0.0 ==> Base64 Signatur eventuell Hotfix.");
-
- return chooseEnvelopedBase64Connector(profile, sig_app);
- }
- if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_1_0))
- {
- log.debug("Version is 1.1.0 ==> Detached Multipart Signatur.");
-
- return chooseDetachedMultipartConnector(profile, sig_app);
- }
- }
-
- log.debug("chooseConnector."); //$NON-NLS-1$
- return null;
- }
-
- protected static final String BKU = "bku"; //$NON-NLS-1$
-
- protected static final String MOA = "moa"; //$NON-NLS-1$
-
- protected static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseEnvelopedBase64Connector(
- String profile, String sig_app) throws ConnectorFactoryException, ConnectorException
- {
- if (sig_app.equals(BKU))
- {
- log.debug("sig_app is BKU ==> EnvelopedBase64BKUConnector"); //$NON-NLS-1$
-
- return new EnvelopedBase64BKUConnector(profile);
- }
- if (sig_app.equals(MOA))
- {
- log.debug("sig_app is MOA ==> EnvelopedBase64MOAConnector"); //$NON-NLS-1$
-
- return new EnvelopingBase64MOAConnector(profile);
- }
- throw new ConnectorFactoryException("Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- protected static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseDetachedMultipartConnector(
- String profile, String sig_app) throws ConnectorException, ConnectorFactoryException
- {
- if (sig_app.equals(BKU))
- {
- log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$
-
- return new MultipartDetachedBKUConnector(profile);
- }
- if (sig_app.equals(MOA))
- {
- log.debug("sig_app is MOA ==> EnvelopedBase64MOAConnector"); //$NON-NLS-1$
-
- return null;
- }
- throw new ConnectorFactoryException("Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
}