aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag
diff options
context:
space:
mode:
authorknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-17 15:28:32 +0000
committerknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-17 15:28:32 +0000
commit527484bcc0a65c61d50209849f7b3db34f0128f7 (patch)
tree2fa9ddcbf42f0fae9137444f5950de25a1e53b0a /src/main/java/at/knowcenter/wag
parent0184c140614b99a5037cbd8f969b7512888cd37d (diff)
downloadpdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.tar.gz
pdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.tar.bz2
pdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.zip
web
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@87 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java5
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java4
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/LocalConnector.java66
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java33
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java (renamed from src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedMultipartBKUConnector.java)38
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java25
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/LocRefDetachedBKUConnector.java25
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/MultipartDetachedBKUConnector.java21
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java178
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/EnvelopingBase64MOAConnector.java166
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOAHelper.java190
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java25
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/OldMOAIdFormatter.java21
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/tools/DebugHelper.java70
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/AsynchronousRedirectResponder.java7
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java191
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/PdfASServletContextListener.java4
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/Sign.java544
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/Verify.java285
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java199
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java100
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java (renamed from src/main/java/at/knowcenter/wag/egov/egiz/web/SignPreview.java)29
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java576
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java (renamed from src/main/java/at/knowcenter/wag/egov/egiz/web/VerifyPreview.java)26
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java334
26 files changed, 2010 insertions, 1154 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 4f31d14..9359c96 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -60,8 +60,9 @@ 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.DetachedMultipartBKUConnector;
+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.bku.SignSignatureObject;
import at.knowcenter.wag.egov.egiz.sig.connectors.moa.EnvelopingBase64MOAConnector;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
@@ -1407,7 +1408,7 @@ public abstract class PdfAS
{
log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$
- return new DetachedMultipartBKUConnector(profile);
+ return new MultipartDetachedBKUConnector(profile);
}
if (sig_app.equals(MOA))
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
index e1284ce..614005e 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java
@@ -52,7 +52,7 @@ import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
import at.knowcenter.wag.egov.egiz.sig.ConnectorInformation;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
-import at.knowcenter.wag.egov.egiz.web.Verify;
+import at.knowcenter.wag.egov.egiz.web.servlets.VerifyServlet;
/**
* The main program entry point of the commandline tool.
@@ -498,7 +498,7 @@ public abstract class Main
List signature_holders = null;
- String extension = Verify.extractExtension(input);
+ String extension = VerifyServlet.extractExtension(input);
if (extension != null && extension.equals("txt"))
{
try
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/LocalConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/LocalConnector.java
new file mode 100644
index 0000000..05f8149
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/LocalConnector.java
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.connectors;
+
+import java.util.Properties;
+
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+
+/**
+ * @author wprinz
+ */
+public interface LocalConnector
+{
+ /**
+ * Prepares the sign request xml to be sent using the sign request template.
+ *
+ * @param data
+ * The SignatureData.
+ * @return Returns the sign request xml to be sent.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public String prepareSignRequest(SignatureData data) throws ConnectorException;
+
+ /**
+ * Analyzes the sign response xml and extracts the signature data.
+ *
+ * @param response_properties
+ * The response properties containing the response String and
+ * transport related information.
+ * @return Returns the extracted data encapsulated in a SignatureObject.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public SignSignatureObject analyzeSignResponse(Properties response_properties) throws ConnectorException;
+
+ /**
+ * Prepares the verify request xml to be sent using the verify request
+ * template.
+ *
+ * @param data
+ * The SignatureData.
+ * @param so
+ * The signature information object.
+ * @return Returns the verify request xml to be sent.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public String prepareVerifyRequest(SignatureData data, SignSignatureObject so) throws ConnectorException;
+
+ /**
+ * Analyzes the verify response string.
+ *
+ * @param response_properties
+ * The response properties containing the response XML.
+ * @return Returns the SignatureResponse containing the verification result.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public SignatureResponse analyzeVerifyResponse(Properties response_properties) throws ConnectorException;
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java
index 78165c2..c05c688 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java
@@ -50,10 +50,41 @@ public final class BKUHelper
String base64 = CodingHelper.encodeBase64(data.getData());
if (data.getMimeType().equals("application/pdf")) //$NON-NLS-1$
{
- log.debug("The data is application/pdf - so it is Base64 encoded again."); //$NON-NLS-1$
+ log.debug("The data is application/pdf - so the binary data is Base64 encoded."); //$NON-NLS-1$
base64 = CodingHelper.encodeUTF8AsBase64(base64);
}
return base64;
+
+ }
+
+ /**
+ * Prepares the enveloping data.
+ * <p>
+ * This is useful for building the hash.
+ * </p>
+ *
+ * @param data
+ * The data to be prepared.
+ * @return Returns the prepared data.
+ */
+ public static byte[] prepareEnvelopingData(SignatureData data)
+ {
+ byte[] enc = data.getData();
+ if (data.getMimeType().equals("application/pdf")) //$NON-NLS-1$
+ {
+ log.debug("The data is application/pdf - so the binary data is Base64 encoded."); //$NON-NLS-1$
+ String base64 = CodingHelper.encodeBase64(enc);
+ try
+ {
+ enc = base64.getBytes("US-ASCII"); //$NON-NLS-1$
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException("Very Strange: US-ASCII encoding not supported???", e); //$NON-NLS-1$
+ }
+ }
+ return enc;
}
/**
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedMultipartBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java
index 68ff62e..44beb40 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedMultipartBKUConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java
@@ -16,6 +16,7 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedIdFormatter;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
@@ -30,12 +31,12 @@ import at.knowcenter.wag.egov.egiz.tools.FileHelper;
*
* @author wprinz
*/
-public class DetachedMultipartBKUConnector implements Connector
+public class DetachedBKUConnector implements Connector, LocalConnector
{
/**
* The log.
*/
- private static Log log = LogFactory.getLog(DetachedMultipartBKUConnector.class);
+ private static Log log = LogFactory.getLog(DetachedBKUConnector.class);
/**
* The environemnt configuration of this connector containing templates and
@@ -57,9 +58,9 @@ public class DetachedMultipartBKUConnector implements Connector
* @throws ConnectorException
* f.e.
*/
- public DetachedMultipartBKUConnector(String profile) throws ConnectorException
+ public DetachedBKUConnector(String profile, String loc_ref_content) throws ConnectorException
{
- this.environment = new Environment(profile);
+ this.environment = new Environment(profile, loc_ref_content);
}
/**
@@ -71,7 +72,7 @@ public class DetachedMultipartBKUConnector implements Connector
* @throws ConnectorException
* f.e.
*/
- protected String prepareSignRequestDetached(SignatureData data) throws ConnectorException
+ public String prepareSignRequest(SignatureData data) throws ConnectorException
{
log.debug("prepareSignRequestDetached:"); //$NON-NLS-1$
@@ -79,14 +80,17 @@ public class DetachedMultipartBKUConnector implements Connector
String sign_keybox_identifier = this.environment.getSignKeyboxIdentifier();
String mime_type = data.getMimeType();
+ String loc_ref_content = this.environment.getLocRefContent();
if (log.isDebugEnabled())
{
log.debug("sign keybox identifier = " + sign_keybox_identifier); //$NON-NLS-1$
log.debug("mime type = " + mime_type); //$NON-NLS-1$
+ log.debug("loc_ref_content = " + loc_ref_content); //$NON-NLS-1$
}
String sign_request_xml = sign_request_template.replaceFirst(TemplateReplaces.KEYBOX_IDENTIFIER_REPLACE, sign_keybox_identifier);
sign_request_xml = sign_request_xml.replaceFirst(TemplateReplaces.MIME_TYPE_REPLACE, mime_type);
+ sign_request_xml = sign_request_xml.replaceFirst(TemplateReplaces.LOC_REF_CONTENT_REPLACE, loc_ref_content);
log.debug("prepareSignRequestDetached finished."); //$NON-NLS-1$
return sign_request_xml;
@@ -220,7 +224,7 @@ public class DetachedMultipartBKUConnector implements Connector
{
log.debug("doSign:"); //$NON-NLS-1$
- String sign_request_xml = prepareSignRequestDetached(data);
+ String sign_request_xml = prepareSignRequest(data);
log.debug("sign_request_xml = " + sign_request_xml); //$NON-NLS-1$
String url = this.environment.getSignURL();
@@ -250,7 +254,7 @@ public class DetachedMultipartBKUConnector implements Connector
{
log.debug("doVerify:"); //$NON-NLS-1$
- String verify_request_xml = prepareVerifyRequestDetached(data, so);
+ String verify_request_xml = prepareVerifyRequest(data, so);
log.debug("verify_request_xml = " + verify_request_xml); //$NON-NLS-1$
// TODO debug
@@ -288,7 +292,7 @@ public class DetachedMultipartBKUConnector implements Connector
* @throws ConnectorException
* f.e.
*/
- public String prepareVerifyRequestDetached(SignatureData data,
+ public String prepareVerifyRequest(SignatureData data,
SignSignatureObject so) throws ConnectorException
{
String verify_request_template = this.environment.getVerifyRequestTemplate();
@@ -309,7 +313,8 @@ public class DetachedMultipartBKUConnector implements Connector
// }
String verify_request_xml = verify_request_template.replaceFirst(TemplateReplaces.XML_CONTENT_REPLACE, xml_content);
-
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.LOC_REF_CONTENT_REPLACE, this.environment.getLocRefContent());
+
return verify_request_xml;
}
@@ -484,6 +489,8 @@ public class DetachedMultipartBKUConnector implements Connector
*/
protected static final String RSA_CERT_ALG_KEY = "cert.alg.rsa"; //$NON-NLS-1$
+ protected String loc_ref_content = null;
+
protected String sign_keybox_identifier = null;
protected String sign_request_template = null;
@@ -508,8 +515,10 @@ public class DetachedMultipartBKUConnector implements Connector
* @throws ConnectorException
* f.e.
*/
- public Environment(String profile) throws ConnectorException
+ public Environment(String profile, String loc_ref_content) throws ConnectorException
{
+ this.loc_ref_content = loc_ref_content;
+
SettingsReader settings = null;
try
{
@@ -556,6 +565,15 @@ public class DetachedMultipartBKUConnector implements Connector
}
/**
+ * Returns the LocRef content.
+ * @return Returns the LocRef content.
+ */
+ public String getLocRefContent()
+ {
+ return this.loc_ref_content;
+ }
+
+ /**
* Returns the sign keybox identifier.
*
* @return Returns the sign keybox identifier.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java
index cabfe92..1c628b1 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java
@@ -19,6 +19,7 @@ import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.sigid.HotfixIdFormatter;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+import at.knowcenter.wag.egov.egiz.tools.DebugHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
/**
@@ -66,11 +67,12 @@ public class EnvelopedBase64BKUConnector implements Connector
log.debug("doSign:"); //$NON-NLS-1$
String sign_request_xml = prepareSignRequest(data);
- log.debug("sign_request_xml = " + sign_request_xml); //$NON-NLS-1$
+ DebugHelper.debugStringToFile(sign_request_xml, "BKU_EnvB64_sign_request.xml"); //$NON-NLS-1$
String url = this.environment.getSignURL();
Properties response_properties = sendRequest(url, sign_request_xml);
+ DebugHelper.debugStringToFile(response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY), "BKU_EnvB64_sign_response.xml"); //$NON-NLS-1$
SignSignatureObject sso = analyzeSignResponse(response_properties);
// TODO this could be made more generic
@@ -89,25 +91,12 @@ public class EnvelopedBase64BKUConnector implements Connector
log.debug("doVerify:"); //$NON-NLS-1$
String verify_request_xml = prepareVerifyRequest(data, so);
- log.debug("verify_request_xml = " + verify_request_xml); //$NON-NLS-1$
-
- // TODO debug
- // try
- // {
- // FileOutputStream fos = new
- // FileOutputStream("C:\\wprinz\\Filer\\egiz2\\verify_request.utf8.xml");
- // //$NON-NLS-1$
- // fos.write(verify_request_xml.getBytes("UTF-8")); //$NON-NLS-1$
- // fos.close();
- // }
- // catch (Exception e)
- // {
- // log.error(e);
- // }
+ DebugHelper.debugStringToFile(verify_request_xml, "BKU_EnvB64_verify_request.xml"); //$NON-NLS-1$
String url = this.environment.getVerifyURL();
Properties response_properties = sendRequest(url, verify_request_xml);
+ DebugHelper.debugStringToFile(response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY), "BKU_EnvB64_verify_response.xml"); //$NON-NLS-1$
SignatureResponse signature_response = analyzeVerifyResponse(response_properties);
log.debug("doVerify finished."); //$NON-NLS-1$
@@ -180,8 +169,8 @@ public class EnvelopedBase64BKUConnector implements Connector
String verify_xml = verify_template.replaceFirst(TemplateReplaces.CERT_ALG_REPLACE, cert_alg);
// data digest replace
+ byte [] data_value = BKUHelper.prepareEnvelopingData(data);
{
- byte[] data_value = data.getData();
byte[] data_value_hash = CodingHelper.buildDigest(data_value);
String object_data_hash = CodingHelper.encodeBase64(data_value_hash);
@@ -203,7 +192,7 @@ public class EnvelopedBase64BKUConnector implements Connector
verify_xml = verify_xml.replaceFirst(TemplateReplaces.X509_CERTIFICATE_REPLACE, x509_cert_string);
// Base64 content replace
- String base64 = BKUHelper.prepareBase64Content(data);
+ String base64 = CodingHelper.encodeBase64(data_value);
verify_xml = verify_xml.replaceFirst(TemplateReplaces.BASE64_CONTENT_REPLACE, base64);
// Qualified Properties replaces
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/LocRefDetachedBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/LocRefDetachedBKUConnector.java
new file mode 100644
index 0000000..92b7b91
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/LocRefDetachedBKUConnector.java
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.connectors.bku;
+
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+
+/**
+ * @author wprinz
+ *
+ */
+public class LocRefDetachedBKUConnector extends DetachedBKUConnector
+{
+
+ /**
+ * @param profile
+ * @param loc_ref_content
+ * @throws ConnectorException
+ */
+ public LocRefDetachedBKUConnector(String profile, String loc_ref_content) throws ConnectorException
+ {
+ super(profile, loc_ref_content);
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/MultipartDetachedBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/MultipartDetachedBKUConnector.java
new file mode 100644
index 0000000..a2d4dc0
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/MultipartDetachedBKUConnector.java
@@ -0,0 +1,21 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.connectors.bku;
+
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+
+/**
+ * @author wprinz
+ *
+ */
+public class MultipartDetachedBKUConnector extends DetachedBKUConnector
+{
+ protected static final String MULTIPART_LOC_REF_CONTENT = "formdata:fileupload"; //$NON-NLS-1$
+
+ public MultipartDetachedBKUConnector(String profile) throws ConnectorException
+ {
+ super(profile, MULTIPART_LOC_REF_CONTENT);
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
index e5278b9..220a3d0 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
@@ -4,21 +4,23 @@
package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
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.SettingsException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
-import at.knowcenter.wag.egov.egiz.exceptions.WebException;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedLocRefMOAIdFormatter;
+import at.knowcenter.wag.egov.egiz.tools.DebugHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
/**
@@ -26,7 +28,7 @@ import at.knowcenter.wag.egov.egiz.tools.FileHelper;
*
* @author wprinz
*/
-public class DetachedLocRefMOAConnector
+public class DetachedLocRefMOAConnector implements Connector
{
/**
* The SIG_ID prefix.
@@ -60,31 +62,19 @@ public class DetachedLocRefMOAConnector
* @throws SignatureException
* f.e.
*/
- public DetachedLocRefMOAConnector(String profile) throws SignatureException, SettingsException
+ public DetachedLocRefMOAConnector(String profile, String signature_data_url) throws SignatureException, SettingsException
{
- this.environment = new Environment(profile);
+ this.environment = new Environment(profile, signature_data_url);
}
- /**
- * Prepares the sign request xml to be sent using the sign request template.
- *
- * @param data
- * The SignatureData.
- * @return Returns the sign request xml to be sent.
- * @throws SignatureException
- * f.e.
- */
- protected String prepareSignRequest(SignatureData data) throws SignatureException
+ protected String prepareSignRequest(SignatureData data) throws ConnectorException
{
log.debug("prepareSignRequestDetached:"); //$NON-NLS-1$
String sign_request_template = this.environment.getSignRequestTemplate();
String sign_key_identifier = this.environment.getSignKeyIdentifier();
- String loc_ref_content = // "http://wwwx.google.at";
- // this doesn't work - MOA always complains that file system access is
- // forbidden
- "file:///C:/wprinz/Filer/egiz2/test.utf8.txt";
+ String loc_ref_content = this.environment.getSignatureDataUrl();
String mime_type = data.getMimeType();
if (log.isDebugEnabled())
{
@@ -102,16 +92,9 @@ public class DetachedLocRefMOAConnector
}
/**
- * Analyzes the sign response xml and extracts the signature data.
- *
- * @param response_properties
- * The response properties containing the response String and
- * transport related information.
- * @return Returns the extracted data encapsulated in a SignatureObject.
- * @throws SignatureException
- * f.e.
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector#analyzeSignResponse(java.util.Properties)
*/
- public SignSignatureObject analyzeSignResponse(Properties response_properties) throws SignatureException
+ public SignSignatureObject analyzeSignResponse(Properties response_properties) throws ConnectorException
{
log.debug("analyzeSignResponse:"); //$NON-NLS-1$
@@ -119,33 +102,26 @@ public class DetachedLocRefMOAConnector
BKUHelper.checkResponseForError(response_string);
- // SignSignatureObject so = parseCreateXMLResponse(response_string);
+ SignSignatureObject so = MOAHelper.parseCreateXMLResponse(response_string, new DetachedLocRefMOAIdFormatter());
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
- return null;// so;
+ return so;
}
/**
- * Performs a sign.
- *
- * @param data
- * The data to be signed.
- * @return Returns the signature object containing the signature data.
- * @throws SignatureException
- * f.e.
- * @throws WebException
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.Connector#doSign(at.knowcenter.wag.egov.egiz.sig.SignatureData)
*/
- public SignSignatureObject doSign(SignatureData data) throws SignatureException, WebException
+ public SignSignatureObject doSign(SignatureData data) throws ConnectorException
{
log.debug("doSign:"); //$NON-NLS-1$
String sign_request_xml = prepareSignRequest(data);
- log.debug("sign_request_xml = " + sign_request_xml); //$NON-NLS-1$
+ DebugHelper.debugStringToFile(sign_request_xml, "MOA_DetLocRef_sign_request.xml"); //$NON-NLS-1$
String url = this.environment.getSignURL();
- Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_SIGN, sign_request_xml, data);
+ Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_SIGN, sign_request_xml);
- log.debug("response_string = " + response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY));; //$NON-NLS-1$
+ DebugHelper.debugStringToFile(response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY), "MOA_DetLocRef_sign_response.xml"); //$NON-NLS-1$
SignSignatureObject sso = analyzeSignResponse(response_properties);
// TODO this could be made more generic
@@ -155,8 +131,66 @@ public class DetachedLocRefMOAConnector
return sso;
}
+ /**
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.Connector#doVerify(at.knowcenter.wag.egov.egiz.sig.SignatureData,
+ * at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject)
+ */
+ public SignatureResponse doVerify(SignatureData data, SignSignatureObject so) throws ConnectorException
+ {
+ log.debug("doVerify:"); //$NON-NLS-1$
+
+ String verify_request_xml = prepareVerifyRequest(data, so);
+ log.debug("verify_request_xml = " + verify_request_xml); //$NON-NLS-1$
+
+ String url = this.environment.getVerifyURL();
+ Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_VERIFY, verify_request_xml);
+
+ // SignatureResponse signature_response =
+ // analyzeVerifyResponse(response_properties);
+
+ log.debug("doVerify finished."); //$NON-NLS-1$
+ return null; // signature_response;
+ }
+
+ /**
+ * Prepares the verify request xml to be sent using the verify request
+ * template.
+ *
+ * @param data
+ * The SignatureData.
+ * @param so
+ * The signature information object.
+ * @return Returns the verify request xml to be sent.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public String prepareVerifyRequest(SignatureData data, SignSignatureObject so) throws ConnectorException
+ {
+ String verify_request_template = this.environment.getVerifyRequestTemplate();
+
+ String xml_content = null;
+ // TODO implement BKU
+ // if (sigObject.isMOASigned())
+ // {
+ // MOAConnector moa_conn = new MOAConnector();
+ // // get the MOA-template
+ // verify_template_str = moa_conn.getVerifyTemplate(normalizedText,
+ // sigObject);
+ // }
+ // else
+ // {
+ // get the BKU-template
+// xml_content = prepareXMLContent(data, so);
+ // }
+
+ String verify_request_xml = verify_request_template.replaceFirst(TemplateReplaces.XML_CONTENT_REPLACE, xml_content);
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.TRUST_PROFILE_ID_REPLACE, this.environment.getVerifyTrustProfileId());
+
+ return verify_request_xml;
+ }
+
protected Properties sendRequest(String url, String mode,
- String request_string, SignatureData data) throws SignatureException
+ String request_string) throws ConnectorException
{
try
{
@@ -165,8 +199,7 @@ public class DetachedLocRefMOAConnector
}
catch (Exception e)
{
- SignatureException se = new SignatureException(320, e);
- throw se;
+ throw new ConnectorException(320, e);
}
}
@@ -208,6 +241,11 @@ public class DetachedLocRefMOAConnector
protected static final String VERIFY_URL_KEY = "moa.verify.url"; //$NON-NLS-1$
/**
+ * The configuration key of the trust profile id.
+ */
+ protected static final String VERIFY_TRUST_PROFILE_ID = "moa.verify.TrustProfileID"; //$NON-NLS-1$
+
+ /**
* The configuration key for the ECDSA cert alg property.
*/
protected static final String ECDSA_CERT_ALG_KEY = "cert.alg.ecdsa"; //$NON-NLS-1$
@@ -217,6 +255,8 @@ public class DetachedLocRefMOAConnector
*/
protected static final String RSA_CERT_ALG_KEY = "cert.alg.rsa"; //$NON-NLS-1$
+ protected String signature_data_url = null;
+
protected String sign_key_identifier = null;
protected String sign_request_template = null;
@@ -229,6 +269,8 @@ public class DetachedLocRefMOAConnector
protected String verify_url = null;
+ protected String verify_trust_profile_id = null;
+
protected String cert_alg_ecdsa = null;
protected String cert_alg_rsa = null;
@@ -240,12 +282,22 @@ public class DetachedLocRefMOAConnector
* The configuration profile.
* @throws SettingsException
* f.e.
- * @throws SignatureException
+ * @throws ConnectorException
* f.e.
*/
- public Environment(String profile) throws SettingsException, SignatureException
+ public Environment(String profile, String signature_data_url) throws ConnectorException
{
- SettingsReader settings = SettingsReader.getInstance();
+ this.signature_data_url = signature_data_url;
+
+ SettingsReader settings = null;
+ try
+ {
+ settings = SettingsReader.getInstance();
+ }
+ catch (SettingsException e)
+ {
+ throw new ConnectorException(300, e);
+ }
this.sign_key_identifier = getConnectorValueFromProfile(settings, profile, SIGN_KEY_IDENTIFIER_KEY);
@@ -254,7 +306,7 @@ public class DetachedLocRefMOAConnector
if (this.sign_request_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the create xml request template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the create xml request template"); //$NON-NLS-1$
}
this.sign_url = getConnectorValueFromProfile(settings, profile, SIGN_URL_KEY);
@@ -264,7 +316,7 @@ public class DetachedLocRefMOAConnector
if (this.verify_request_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the verify xml request template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the verify xml request template"); //$NON-NLS-1$
}
String verify_filename = getConnectorValueFromProfile(settings, profile, VERIFY_TEMPLATE_KEY);
@@ -272,11 +324,13 @@ public class DetachedLocRefMOAConnector
if (this.verify_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the verify template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the verify template"); //$NON-NLS-1$
}
this.verify_url = getConnectorValueFromProfile(settings, profile, VERIFY_URL_KEY);
+ this.verify_trust_profile_id = settings.getValueFromKey(VERIFY_TRUST_PROFILE_ID);
+
this.cert_alg_ecdsa = settings.getValueFromKey(ECDSA_CERT_ALG_KEY);
this.cert_alg_rsa = settings.getValueFromKey(RSA_CERT_ALG_KEY);
@@ -284,6 +338,16 @@ public class DetachedLocRefMOAConnector
}
/**
+ * Returns the URL where to load the detached data from.
+ *
+ * @return Returns the URL where to load the detached data from.
+ */
+ public String getSignatureDataUrl()
+ {
+ return this.signature_data_url;
+ }
+
+ /**
* Returns the sign key identifier.
*
* @return Returns the sign key identifier.
@@ -344,6 +408,16 @@ public class DetachedLocRefMOAConnector
}
/**
+ * Returns the verify trust profile id.
+ *
+ * @return Returns the verify trust profile id.
+ */
+ public String getVerifyTrustProfileId()
+ {
+ return this.verify_trust_profile_id;
+ }
+
+ /**
* Returns the ecdsa cert alg property.
*
* @return Returns the ecdsa cert alg property.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/EnvelopingBase64MOAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/EnvelopingBase64MOAConnector.java
index 4e9dd04..f6580af 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/EnvelopingBase64MOAConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/EnvelopingBase64MOAConnector.java
@@ -3,15 +3,8 @@
*/
package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -20,14 +13,13 @@ import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
-import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
-import at.knowcenter.wag.egov.egiz.sig.X509Cert;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.sigid.OldMOAIdFormatter;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
@@ -205,7 +197,7 @@ public class EnvelopingBase64MOAConnector implements Connector
BKUHelper.checkResponseForError(response_string);
- SignSignatureObject so = parseCreateXMLResponse(response_string);
+ SignSignatureObject so = MOAHelper.parseCreateXMLResponse(response_string, new OldMOAIdFormatter());
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
return so;
@@ -268,8 +260,8 @@ public class EnvelopingBase64MOAConnector implements Connector
String verify_xml = verify_template.replaceFirst(TemplateReplaces.CERT_ALG_REPLACE, cert_alg);
// data digest replace
+ byte[] data_value = BKUHelper.prepareEnvelopingData(data);
{
- byte[] data_value = data.getData();
byte[] data_value_hash = CodingHelper.buildDigest(data_value);
String object_data_hash = CodingHelper.encodeBase64(data_value_hash);
@@ -286,7 +278,7 @@ public class EnvelopingBase64MOAConnector implements Connector
verify_xml = verify_xml.replaceFirst(TemplateReplaces.X509_CERTIFICATE_REPLACE, x509_cert_string);
// Base64 content replace
- String base64 = BKUHelper.prepareBase64Content(data);
+ String base64 = CodingHelper.encodeBase64(data_value);
verify_xml = verify_xml.replaceFirst(TemplateReplaces.BASE64_CONTENT_REPLACE, base64);
// Qualified Properties replaces
@@ -327,156 +319,6 @@ public class EnvelopingBase64MOAConnector implements Connector
}
}
-
- /**
- * This method parses the MOA-Response string. It separates the
- * SignatureValue, X509IssuerName, SigningTime, X509SerialNumber,
- * X509Certificate, CertDigest and DigestValues. If the X509Certificate is
- * extracted it would be stored in the certificates directory.
- *
- * @param xmlResponse
- * the response string from the MOA sign-request
- * @throws ConnectorException
- * ErrorCode (303, 304)
- * @see SignatureObject
- * @see CodingHelper
- * @see X509Cert
- */
- public static SignSignatureObject parseCreateXMLResponse(String xmlResponse) throws ConnectorException
- {
- Pattern sig_val_p_s = Pattern.compile("<[\\w]*:?SignatureValue>"); //$NON-NLS-1$
- Pattern sig_val_p_e = Pattern.compile("</[\\w]*:?SignatureValue>"); //$NON-NLS-1$
- Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>"); //$NON-NLS-1$
- Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>"); //$NON-NLS-1$
- Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>"); //$NON-NLS-1$
- Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>"); //$NON-NLS-1$
- Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>"); //$NON-NLS-1$
- Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>"); //$NON-NLS-1$
- Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>"); //$NON-NLS-1$
- Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>"); //$NON-NLS-1$
-
- // Pattern sig_cer_d_p_s = Pattern.compile("<[\\w]*:?CertDigest>");
- // //$NON-NLS-1$
- // Pattern sig_cer_d_p_e = Pattern.compile("</[\\w]*:?CertDigest>");
- // //$NON-NLS-1$
- // Pattern dig_val_p_s = Pattern.compile("<[\\w]*:?DigestValue>");
- // //$NON-NLS-1$
- // Pattern dig_val_p_e = Pattern.compile("</[\\w]*:?DigestValue>");
- // //$NON-NLS-1$
-
- Matcher sig_val_m_s = sig_val_p_s.matcher(xmlResponse);
- Matcher sig_val_m_e = sig_val_p_e.matcher(xmlResponse);
- Matcher iss_nam_m_s = iss_nam_p_s.matcher(xmlResponse);
- Matcher iss_nam_m_e = iss_nam_p_e.matcher(xmlResponse);
- Matcher sig_tim_m_s = sig_tim_p_s.matcher(xmlResponse);
- Matcher sig_tim_m_e = sig_tim_p_e.matcher(xmlResponse);
- Matcher ser_num_m_s = ser_num_p_s.matcher(xmlResponse);
- Matcher ser_num_m_e = ser_num_p_e.matcher(xmlResponse);
- Matcher sig_cer_m_s = sig_cer_p_s.matcher(xmlResponse);
- Matcher sig_cer_m_e = sig_cer_p_e.matcher(xmlResponse);
-
- // Matcher sig_cer_d_m_s = sig_cer_d_p_s.matcher(xmlResponse);
- // Matcher sig_cer_d_m_e = sig_cer_d_p_e.matcher(xmlResponse);
- // Matcher dig_val_m_s = dig_val_p_s.matcher(xmlResponse);
- // Matcher dig_val_m_e = dig_val_p_e.matcher(xmlResponse);
-
- // SignatureValue
- String sig_val = null;
- if (sig_val_m_s.find() && sig_val_m_e.find())
- {
- sig_val = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_val_m_s.end(), sig_val_m_e.start()));
- }
- log.debug("sig_val = " + sig_val); //$NON-NLS-1$
-
- // X509IssuerName
- String iss_nam = null;
- if (iss_nam_m_s.find() && iss_nam_m_e.find())
- {
- iss_nam = xmlResponse.substring(iss_nam_m_s.end(), iss_nam_m_e.start());
- }
- log.debug("iss_nam = " + iss_nam); //$NON-NLS-1$
-
- // X509SerialNumber
- String ser_num = null;
- if (ser_num_m_s.find() && ser_num_m_e.find())
- {
- ser_num = BKUHelper.removeAllWhitespace(xmlResponse.substring(ser_num_m_s.end(), ser_num_m_e.start()));
- }
- log.debug("ser_num = " + ser_num); //$NON-NLS-1$
-
- // SigningTime
- String sig_tim = null;
- if (sig_tim_m_s.find() && sig_tim_m_e.find())
- {
- sig_tim = xmlResponse.substring(sig_tim_m_s.end(), sig_tim_m_e.start());
- }
- log.debug("sig_tim = " + sig_tim); //$NON-NLS-1$
-
- // CertDigest
- // if (sig_cer_d_m_s.find() && sig_cer_d_m_e.find())
- // {
- // String cert_digest = xmlResponse.substring(sig_cer_d_m_s.end(),
- // sig_cer_d_m_e.start());
- // if (dig_val_m_s.find() && dig_val_m_e.find())
- // {
- // sig_dig = cert_digest.substring(dig_val_m_s.end(), dig_val_m_e.start());
- // //sigObj.setX509CertificateDigest(sig_dig);
- // }
- // }
-
- // X509Certificate
- X509Certificate cert = null;
- if (sig_cer_m_s.find() && sig_cer_m_e.find())
- {
- String sig_cer = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_cer_m_s.end(), sig_cer_m_e.start()));
-
- try
- {
- byte[] der = CodingHelper.decodeBase64(sig_cer);
- ByteArrayInputStream bais = new ByteArrayInputStream(der);
- CertificateFactory cf = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
- cert = (X509Certificate) cf.generateCertificate(bais);
- bais.close();
- }
- catch (UnsupportedEncodingException e)
- {
- log.error(e);
- throw new ConnectorException(300, e);
- }
- catch (CertificateException e)
- {
- log.error(e);
- throw new ConnectorException(300, e);
- }
- catch (IOException e)
- {
- log.error(e);
- throw new ConnectorException(300, e);
- }
- }
- log.debug("X509Certificate = " + cert); //$NON-NLS-1$
-
- if (log.isDebugEnabled())
- {
-
- String cert_iss = cert.getIssuerDN().getName();
- log.debug("certificate's issuer = " + cert_iss); //$NON-NLS-1$
- log.debug("response's issuer = " + iss_nam); //$NON-NLS-1$
- log.debug("issuer matches = " + cert_iss.equals(iss_nam)); //$NON-NLS-1$
- log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num)); //$NON-NLS-1$
- }
-
- SignSignatureObject so = new SignSignatureObject();
- so.date = sig_tim;
- so.issuer = iss_nam;
- so.signatureValue = sig_val;
- so.x509Certificate = cert;
-
- so.id = null;
-
- return so;
- }
-
/**
* Holds environment configuration information like templates.
*
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOAHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOAHelper.java
new file mode 100644
index 0000000..e05d55c
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOAHelper.java
@@ -0,0 +1,190 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.X509Cert;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+
+/**
+ * @author wprinz
+ *
+ */
+public class MOAHelper
+{
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(MOAHelper.class);
+
+ /**
+ * This method parses the MOA-Response string.
+ *
+ * <p>
+ * It separates the SignatureValue, X509IssuerName, SigningTime,
+ * X509SerialNumber, X509Certificate, CertDigest and DigestValues. If the
+ * X509Certificate is extracted it would be stored in the certificates
+ * directory.
+ * </p>
+ *
+ * @param xmlResponse
+ * the response string from the MOA sign-request
+ * @throws ConnectorException
+ * ErrorCode (303, 304)
+ * @see SignatureObject
+ * @see CodingHelper
+ * @see X509Cert
+ */
+ public static SignSignatureObject parseCreateXMLResponse(String xmlResponse, IdFormatter id_formatter) throws ConnectorException
+ {
+ Pattern sig_val_p_s = Pattern.compile("<[\\w]*:?SignatureValue>"); //$NON-NLS-1$
+ Pattern sig_val_p_e = Pattern.compile("</[\\w]*:?SignatureValue>"); //$NON-NLS-1$
+ Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>"); //$NON-NLS-1$
+ Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>"); //$NON-NLS-1$
+ Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>"); //$NON-NLS-1$
+ Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>"); //$NON-NLS-1$
+ Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>"); //$NON-NLS-1$
+ Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>"); //$NON-NLS-1$
+ Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>"); //$NON-NLS-1$
+ Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>"); //$NON-NLS-1$
+
+ // Pattern sig_cer_d_p_s = Pattern.compile("<[\\w]*:?CertDigest>");
+ // //$NON-NLS-1$
+ // Pattern sig_cer_d_p_e = Pattern.compile("</[\\w]*:?CertDigest>");
+ // //$NON-NLS-1$
+ // Pattern dig_val_p_s = Pattern.compile("<[\\w]*:?DigestValue>");
+ // //$NON-NLS-1$
+ // Pattern dig_val_p_e = Pattern.compile("</[\\w]*:?DigestValue>");
+ // //$NON-NLS-1$
+
+ Matcher sig_val_m_s = sig_val_p_s.matcher(xmlResponse);
+ Matcher sig_val_m_e = sig_val_p_e.matcher(xmlResponse);
+ Matcher iss_nam_m_s = iss_nam_p_s.matcher(xmlResponse);
+ Matcher iss_nam_m_e = iss_nam_p_e.matcher(xmlResponse);
+ Matcher sig_tim_m_s = sig_tim_p_s.matcher(xmlResponse);
+ Matcher sig_tim_m_e = sig_tim_p_e.matcher(xmlResponse);
+ Matcher ser_num_m_s = ser_num_p_s.matcher(xmlResponse);
+ Matcher ser_num_m_e = ser_num_p_e.matcher(xmlResponse);
+ Matcher sig_cer_m_s = sig_cer_p_s.matcher(xmlResponse);
+ Matcher sig_cer_m_e = sig_cer_p_e.matcher(xmlResponse);
+
+ // Matcher sig_cer_d_m_s = sig_cer_d_p_s.matcher(xmlResponse);
+ // Matcher sig_cer_d_m_e = sig_cer_d_p_e.matcher(xmlResponse);
+ // Matcher dig_val_m_s = dig_val_p_s.matcher(xmlResponse);
+ // Matcher dig_val_m_e = dig_val_p_e.matcher(xmlResponse);
+
+ // SignatureValue
+ String sig_val = null;
+ if (sig_val_m_s.find() && sig_val_m_e.find())
+ {
+ sig_val = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_val_m_s.end(), sig_val_m_e.start()));
+ }
+ log.debug("sig_val = " + sig_val); //$NON-NLS-1$
+
+ // X509IssuerName
+ String iss_nam = null;
+ if (iss_nam_m_s.find() && iss_nam_m_e.find())
+ {
+ iss_nam = xmlResponse.substring(iss_nam_m_s.end(), iss_nam_m_e.start());
+ }
+ log.debug("iss_nam = " + iss_nam); //$NON-NLS-1$
+
+ // X509SerialNumber
+ String ser_num = null;
+ if (ser_num_m_s.find() && ser_num_m_e.find())
+ {
+ ser_num = BKUHelper.removeAllWhitespace(xmlResponse.substring(ser_num_m_s.end(), ser_num_m_e.start()));
+ }
+ log.debug("ser_num = " + ser_num); //$NON-NLS-1$
+
+ // SigningTime
+ String sig_tim = null;
+ if (sig_tim_m_s.find() && sig_tim_m_e.find())
+ {
+ sig_tim = xmlResponse.substring(sig_tim_m_s.end(), sig_tim_m_e.start());
+ }
+ log.debug("sig_tim = " + sig_tim); //$NON-NLS-1$
+
+ // CertDigest
+ // if (sig_cer_d_m_s.find() && sig_cer_d_m_e.find())
+ // {
+ // String cert_digest = xmlResponse.substring(sig_cer_d_m_s.end(),
+ // sig_cer_d_m_e.start());
+ // if (dig_val_m_s.find() && dig_val_m_e.find())
+ // {
+ // sig_dig = cert_digest.substring(dig_val_m_s.end(), dig_val_m_e.start());
+ // //sigObj.setX509CertificateDigest(sig_dig);
+ // }
+ // }
+
+ // X509Certificate
+ X509Certificate cert = null;
+ if (sig_cer_m_s.find() && sig_cer_m_e.find())
+ {
+ String sig_cer = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_cer_m_s.end(), sig_cer_m_e.start()));
+
+ try
+ {
+ byte[] der = CodingHelper.decodeBase64(sig_cer);
+ ByteArrayInputStream bais = new ByteArrayInputStream(der);
+ CertificateFactory cf = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
+ cert = (X509Certificate) cf.generateCertificate(bais);
+ bais.close();
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.error(e);
+ throw new ConnectorException(300, e);
+ }
+ catch (CertificateException e)
+ {
+ log.error(e);
+ throw new ConnectorException(300, e);
+ }
+ catch (IOException e)
+ {
+ log.error(e);
+ throw new ConnectorException(300, e);
+ }
+ }
+ log.debug("X509Certificate = " + cert); //$NON-NLS-1$
+
+ if (log.isDebugEnabled())
+ {
+
+ String cert_iss = cert.getIssuerDN().getName();
+ log.debug("certificate's issuer = " + cert_iss); //$NON-NLS-1$
+ log.debug("response's issuer = " + iss_nam); //$NON-NLS-1$
+ log.debug("issuer matches = " + cert_iss.equals(iss_nam)); //$NON-NLS-1$
+ log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num)); //$NON-NLS-1$
+ }
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = sig_tim;
+ so.issuer = iss_nam;
+ so.signatureValue = sig_val;
+ so.x509Certificate = cert;
+
+ so.id = id_formatter.formatIds(null);
+
+ return so;
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java
new file mode 100644
index 0000000..d37ead0
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java
@@ -0,0 +1,25 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.sigid;
+
+/**
+ * @author wprinz
+ *
+ */
+public class DetachedLocRefMOAIdFormatter implements IdFormatter
+{
+ /**
+ * The SIG_ID prefix.
+ */
+ public static final String SIG_ID_PREFIX = "etsi-moa-detached@"; //$NON-NLS-1$
+
+ /**
+ * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[])
+ */
+ public String formatIds(String[] ids)
+ {
+ return SIG_ID_PREFIX;
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/OldMOAIdFormatter.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/OldMOAIdFormatter.java
new file mode 100644
index 0000000..05f5db8
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/OldMOAIdFormatter.java
@@ -0,0 +1,21 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.sig.sigid;
+
+/**
+ * @author wprinz
+ *
+ */
+public class OldMOAIdFormatter implements IdFormatter
+{
+
+ /**
+ * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[])
+ */
+ public String formatIds(String[] ids)
+ {
+ return null;
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/DebugHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/DebugHelper.java
new file mode 100644
index 0000000..e273437
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/DebugHelper.java
@@ -0,0 +1,70 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.tools;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.knowcenter.wag.egov.egiz.sig.connectors.moa.EnvelopingBase64MOAConnector;
+
+/**
+ * Contains useful helper methods for debugging.
+ *
+ * @author wprinz
+ */
+public final class DebugHelper
+{
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(DebugHelper.class);
+
+ /**
+ * Tells, if Strings should be debugged to a file.
+ *
+ * <p>
+ * If set to false, the corresponding methods will simply do nothing.
+ * </p>
+ */
+ public static boolean debug_to_file = true;
+
+ /**
+ * The directory under which the debug files are to be stored.
+ */
+ public static File debug_dir = new File("C:\\wprinz\\Filer\\egiz2"); //$NON-NLS-1$
+
+ /**
+ * Writes the given String to a file with the given file name in UTF-8
+ * encoding.
+ *
+ * @param str
+ * The String to be written.
+ * @param file_name
+ * The file the String will be written to.
+ */
+ public static void debugStringToFile(String str, String file_name)
+ {
+ if (!debug_to_file)
+ {
+ return;
+ }
+
+ try
+ {
+ File file = new File(debug_dir, file_name);
+ FileOutputStream fos = new FileOutputStream(file);
+ OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); //$NON-NLS-1$
+ osw.write(str);
+ osw.close();
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ }
+ }
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/AsynchronousRedirectResponder.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/AsynchronousRedirectResponder.java
index b98c83e..58d0773 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/AsynchronousRedirectResponder.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/AsynchronousRedirectResponder.java
@@ -39,6 +39,7 @@ import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.connectors.BKUConnector;
+import at.knowcenter.wag.egov.egiz.web.servlets.SignServlet;
/**
* Servlet that responds to the redirect requests of the local service (e.g.
@@ -111,7 +112,7 @@ public class AsynchronousRedirectResponder extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
return;
@@ -185,7 +186,7 @@ public class AsynchronousRedirectResponder extends HttpServlet
si.sign_result = signator.finishSign(si.iui);
}
- Sign.returnSignResponse(si, response);
+ SignServlet.returnSignResponse(si, response);
}
}
@@ -195,7 +196,7 @@ public class AsynchronousRedirectResponder extends HttpServlet
//SessionTable.remove(si.session_id);
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
index 6331a54..2285cc6 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
@@ -84,7 +84,7 @@ public abstract class FormFields
* The signator mode form field.
* @return Returns the corresponding PDFASID.
*/
- protected static PdfASID translateSignatureModeToPdfASID(String signature_mode)
+ public static PdfASID translateSignatureModeToPdfASID(String signature_mode)
{
if (signature_mode.equals(VALUE_MODE_BINARY))
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
index 2008fdc..723bc90 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/LocalRequestHelper.java
@@ -32,7 +32,13 @@ import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
-import at.knowcenter.wag.egov.egiz.sig.LocalConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
/**
* Contains commonly used helper functions for the local request procedure.
@@ -42,15 +48,20 @@ import at.knowcenter.wag.egov.egiz.sig.LocalConnector;
public abstract class LocalRequestHelper
{
/**
+ * The resource of the null request page jsp.
+ */
+ public static final String NULL_REQUEST_PAGE_JSP = "/jsp/null_request_page.jsp";
+
+ /**
* The resource of the local connection page jsp.
*/
public static final String LOCAL_CONNECTION_PAGE_JSP = "/jsp/local_connection_page.jsp";
-
+
/**
* The resource of the redirect refresh page jsp.
*/
public static final String REDIRECT_REFRESH_PAGE_JSP = "/jsp/redirect_refresh_page.jsp";
-
+
/**
* Sets up the local sign procedure.
*
@@ -61,40 +72,72 @@ public abstract class LocalRequestHelper
* @throws PresentableException
* Forwarded exception.
*/
- public static void processLocalSign(SessionInformation si,
+ public static String processLocalSign(SessionInformation si,
HttpServletRequest request, HttpServletResponse response) throws IOException, PresentableException
{
- LocalConnector local_conn = (LocalConnector) ConnectorFactory.createConnector(si.connector);
-
-
- // FIXME refactor WEB
- String document_text = "fixme"; //si.iui.document_text;
- String request_string = local_conn.prepareSignRequest(si.user_name, document_text, si.type);
- String request_url = local_conn.getSignURL(si.type);
-
- LocalRequest local_request = new LocalRequest(request_url, request_string);
- List local_requests = new ArrayList();
- local_requests.add(local_request);
+ String host = request.getServerName(); // "129.27.153.77"
+ URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
+ String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
- // ByteArrayOutputStream baos = new ByteArrayOutputStream();
- // ObjectOutputStream oos = new ObjectOutputStream(baos);
- // oos.writeObject(local_requests);
- // oos.close();
- // baos.close();
+ LocalConnector c = new LocRefDetachedBKUConnector(si.type, loc_ref_url);
+ String sign_request = c.prepareSignRequest(si.iui.signature_data);
+ // TODO local URL
+ String local_request_url = "http://127.0.0.1:3495/http-security-layer-request";
si.requests = new LocalRequest[1];
- si.requests[0] = new LocalRequest(local_conn.getSignURL(si.type), request_string);
+ si.requests[0] = new LocalRequest(local_request_url, sign_request);
si.current_operation = 0;
si.response_properties = new Properties[1];
si.response_properties[0] = null;
- // SessionTable.put(si);
- request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
+ URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
+ String data_url = response.encodeURL(data_URL.toString());
- // byte [] requests_bytes = baos.toByteArray();
- // String base64 = CodingHelper.encodeBase64(requests_bytes);
+ request.setAttribute("local_request_url", local_request_url);
+ request.setAttribute("data_url", data_url);
- LocalRequestHelper.prepareDispatchToLocalConnectionPage(si.requests[0], request, response);
+ return NULL_REQUEST_PAGE_JSP;
+
+
+ // TODO make better
+ //
+ // LocalConnector local_conn = (LocalConnector)
+ // ConnectorFactory.createConnector(si.connector);
+ //
+ //
+ // // FIXME refactor WEB
+ // String document_text = "fixme"; //si.iui.document_text;
+ // String request_string = local_conn.prepareSignRequest(si.user_name,
+ // document_text, si.type);
+ // String request_url = local_conn.getSignURL(si.type);
+ //
+ // LocalRequest local_request = new LocalRequest(request_url,
+ // request_string);
+ // List local_requests = new ArrayList();
+ // local_requests.add(local_request);
+ //
+ // // ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ // // ObjectOutputStream oos = new ObjectOutputStream(baos);
+ // // oos.writeObject(local_requests);
+ // // oos.close();
+ // // baos.close();
+ //
+ // si.requests = new LocalRequest[1];
+ // si.requests[0] = new LocalRequest(local_conn.getSignURL(si.type),
+ // request_string);
+ // si.current_operation = 0;
+ // si.response_properties = new Properties[1];
+ // si.response_properties[0] = null;
+ //
+ // // SessionTable.put(si);
+ // request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION,
+ // si);
+ //
+ // // byte [] requests_bytes = baos.toByteArray();
+ // // String base64 = CodingHelper.encodeBase64(requests_bytes);
+ //
+ // LocalRequestHelper.prepareDispatchToLocalConnectionPage(si.requests[0],
+ // request, response);
}
/**
@@ -102,6 +145,8 @@ public abstract class LocalRequestHelper
*
* @param response
* The HttpServletResponse the local request page is written to.
+ * @return Returns the JSP location where the calling servlet should dispatch
+ * to.
* @throws SignatureException
* Forwarded exception.
* @throws NormalizeException
@@ -111,7 +156,7 @@ public abstract class LocalRequestHelper
* @throws ConnectorFactoryException
* Forwarded exception.
*/
- public static void processLocalVerify(SessionInformation si,
+ public static String processLocalVerify(SessionInformation si,
List holders_to_verify, HttpServletRequest request,
HttpServletResponse response) throws SignatureException, NormalizeException, IOException, ConnectorFactoryException
{
@@ -120,36 +165,98 @@ public abstract class LocalRequestHelper
si.current_operation = 0;
si.finished = false;
- request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
- // SessionTable.put(si);
+ String host = request.getServerName();
+ URL loc_ref_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
+ String loc_ref_url = response.encodeURL(loc_ref_URL.toString());
- LocalConnector local_conn = (LocalConnector) ConnectorFactory.createConnector(si.connector);
+ LocalConnector local_conn = new LocRefDetachedBKUConnector(si.type, loc_ref_url);
for (int i = 0; i < si.requests.length; i++)
{
SignatureHolder holder = (SignatureHolder) holders_to_verify.get(i);
+ SignatureObject s = holder.getSignatureObject();
+
+ // TODO This whole processing is unnecessary here because only the mime
+ // type is used.
String text_to_be_verified = holder.getSignedText();
- // Normalizer normalizer = new Normalizer();
- // String normalized = normalizer.normalize(holder.signed_text);
+ SignatureData sd = null;
+ if (holder.getSignatureObject().isBinary())
+ {
+ byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+ sd = new SignatureDataImpl(data, "application/pdf");
+ }
+ else
+ {
+ sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
+ }
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = s.getSignationDate();
+ so.signatureValue = s.getSignationValue();
+ so.issuer = s.getSignationIssuer();
+ so.x509Certificate = s.getX509Cert().getX509Certificate();
+ so.id = s.getSignationIds();
+ so.kz = s.getKZ().toString();
- String request_string = local_conn.prepareVerifyRequest(text_to_be_verified, holder.getSignatureObject());
+ String request_string = local_conn.prepareVerifyRequest(sd, so);
- LocalRequest local_request = new LocalRequest(local_conn.getVerifyURL(holder.getSignatureObject().getSignationType()), request_string);
+ LocalRequest local_request = new LocalRequest("not-needed", request_string);
si.requests[i] = local_request;
si.response_properties[i] = null;
}
- // ByteArrayOutputStream baos = new ByteArrayOutputStream();
- // ObjectOutputStream oos = new ObjectOutputStream(baos);
- // oos.writeObject(local_requests);
- // oos.close();
- // baos.close();
+ String local_request_url = "http://127.0.0.1:3495/http-security-layer-request";
+
+ URL data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/DataURL");
+ String data_url = response.encodeURL(data_URL.toString());
+
+ request.setAttribute("local_request_url", local_request_url);
+ request.setAttribute("data_url", data_url);
- // byte [] requests_bytes = baos.toByteArray();
- // String base64 = CodingHelper.encodeBase64(requests_bytes);
+ return NULL_REQUEST_PAGE_JSP;
- prepareDispatchToLocalConnectionPage(si.requests[0], request, response);
+ // si.requests = new LocalRequest[holders_to_verify.size()];
+ // si.response_properties = new Properties[si.requests.length];
+ // si.current_operation = 0;
+ // si.finished = false;
+ //
+ // request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION,
+ // si);
+ // // SessionTable.put(si);
+ //
+ // LocalConnector local_conn = (LocalConnector)
+ // ConnectorFactory.createConnector(si.connector);
+ //
+ // for (int i = 0; i < si.requests.length; i++)
+ // {
+ // SignatureHolder holder = (SignatureHolder) holders_to_verify.get(i);
+ //
+ // String text_to_be_verified = holder.getSignedText();
+ // // Normalizer normalizer = new Normalizer();
+ // // String normalized = normalizer.normalize(holder.signed_text);
+ //
+ // String request_string =
+ // local_conn.prepareVerifyRequest(text_to_be_verified,
+ // holder.getSignatureObject());
+ //
+ // LocalRequest local_request = new
+ // LocalRequest(local_conn.getVerifyURL(holder.getSignatureObject().getSignationType()),
+ // request_string);
+ // si.requests[i] = local_request;
+ // si.response_properties[i] = null;
+ // }
+ //
+ // // ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ // // ObjectOutputStream oos = new ObjectOutputStream(baos);
+ // // oos.writeObject(local_requests);
+ // // oos.close();
+ // // baos.close();
+ //
+ // // byte [] requests_bytes = baos.toByteArray();
+ // // String base64 = CodingHelper.encodeBase64(requests_bytes);
+ //
+ // prepareDispatchToLocalConnectionPage(si.requests[0], request, response);
}
/**
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/PdfASServletContextListener.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/PdfASServletContextListener.java
index 4412c21..0fafca4 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/PdfASServletContextListener.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/PdfASServletContextListener.java
@@ -24,6 +24,7 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
@@ -73,7 +74,8 @@ public class PdfASServletContextListener implements ServletContextListener
}
SettingsReader.initializeForWeb(base_dir);
-
+ PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties");
+
SettingsReader.clearTemporaryDirectory();
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/Sign.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/Sign.java
deleted file mode 100644
index 2b1c2a4..0000000
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/Sign.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/**
- * <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: Sign.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $
- */
-package at.knowcenter.wag.egov.egiz.web;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.apache.log4j.Logger;
-
-import at.knowcenter.wag.egov.egiz.PdfAS;
-import at.knowcenter.wag.egov.egiz.PdfASID;
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
-import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
-import at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
-import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
-import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
-import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.framework.SignResult;
-import at.knowcenter.wag.egov.egiz.framework.Signator;
-import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
-import at.knowcenter.wag.egov.egiz.framework.signators.DetachedSignator_1_0_0;
-import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
-import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
-
-/**
- * This method is the sign servlet for the pdf-as web application. It takes get
- * and post requests fill out jsp templates and give the user feedback about the
- * results of the sign process
- *
- * @author wlackner
- * @author wprinz
- */
-public class Sign extends HttpServlet
-{
-
- /**
- * SVUID.
- */
- private static final long serialVersionUID = -4156938216903740438L;
-
- /**
- * Authorisation marker for the http header string.
- */
- protected static final String AUTH = "authorization";
-
- /**
- * Authorisation marker for the http header string.
- */
- protected static final String AUTH_BASIC = "Basic";
-
- /**
- * The logger.
- */
- private static final Logger logger_ = ConfigLogger.getLogger(Sign.class);
-
- protected void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource) throws ServletException, IOException
- {
- dispatch(request, response, resource, getServletContext());
- }
-
- protected static void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
- {
- response.setContentType("text/html");
- response.setCharacterEncoding("UTF-8");
-
- RequestDispatcher disp = context.getRequestDispatcher(resource);
- disp.forward(request, response);
- }
-
- /**
- * @author modified by tknall
- */
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- String authenticate = request.getHeader(AUTH);
- if (authenticate != null)
- {
- logger_.info("authenticate:" + authenticate);
- if (authenticate.indexOf(AUTH_BASIC) == 0)
- {
- authenticate = authenticate.substring(AUTH_BASIC.length() + 1);
- logger_.info("authenticate:" + authenticate);
- authenticate = new String(CodingHelper.decodeBase64(authenticate), "UTF-8");
- logger_.info("authenticate:" + authenticate);
-
- String[] auth_value = authenticate.split(":");
- String user_name = auth_value[0];
- String user_password = auth_value[1];
- logger_.info("username:" + user_name);
- // start modification tknall
-// logger_.info("password:" + user_password);
- logger_.info("password:XXXXXXXXXXXX");
- // stop modification tknall
-
- HttpSession session = request.getSession();
- session.setAttribute(SessionAttributes.ATTRIBUTE_USER_NAME, user_name);
- session.setAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD, user_password);
-
- dispatch(request, response, "/jsp/signupload.jsp");
- return;
- }
- // start modification tknall
- } else {
- String user_name = "";
- String user_password = "";
- logger_.info("authenticate:User has not been authenticated!");
- logger_.info("username: UNKNOWN");
- logger_.info("password: XXXXXXXXXXXX");
- HttpSession session = request.getSession();
- session.setAttribute("uname", user_name);
- session.setAttribute("upass", user_password);
- dispatch(request, response, "/jsp/signupload.jsp");
- }
-
-// request.setAttribute("error", "Falsche Authentifikation");
-// request.setAttribute("cause", "Passwort oder Benutzername ist falsch");
-// dispatch(request, response, "/jsp/error.jsp");
- // stop modification tknall
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- DiskFileItemFactory fif = new DiskFileItemFactory();
- fif.setRepository(SettingsReader.getTemporaryDirectory());
- ServletFileUpload sfu = new ServletFileUpload(fif);
-
- try
- {
- List items = sfu.parseRequest(request);
-
- FileItem preview_fi = null;
- FileItem sig_type_fi = null;
- FileItem sig_app_fi = null;
- FileItem mode_fi = null;
- FileItem file_upload_fi = null;
- FileItem download_fi = null;
-
- Iterator it = items.iterator();
- while (it.hasNext())
- {
- FileItem item = (FileItem) it.next();
- logger_.debug("item = " + item.getFieldName());
-
- if (item.isFormField())
- {
- byte[] item_data = item.get();
- String item_string = new String(item_data, "UTF-8");
- logger_.debug(" form field string = " + item_string);
- }
- else
- {
- logger_.debug(" filename = " + item.getName());
- logger_.debug(" filesize = " + item.getSize());
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_PREVIEW))
- {
- preview_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
- {
- sig_type_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
- {
- sig_app_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_MODE))
- {
- mode_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_UPLOAD))
- {
- file_upload_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD))
- {
- download_fi = item;
- continue;
- }
-
- throw new ServletException("unrecognized POST data.");
-
- }
-
- if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || file_upload_fi == null || download_fi == null)
- {
- throw new ServletException("Unsufficient data provided in request");
- }
-
- String mode = mode_fi.getString("UTF-8");
- if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL) && !mode.equals(FormFields.VALUE_MODE_DETACHED))
- {
- throw new ServletException("The mode '" + mode + "' is unrecognized.");
- }
-
- String preview_str = preview_fi.getString("UTF-8");
- boolean preview = false;
- if (preview_str.equals("true"))
- {
- preview = true;
- }
-
- boolean download_inline = true;
- if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT))
- {
- download_inline = false;
- }
-
- String sig_type = sig_type_fi.getString("UTF-8");
- String connector = sig_app_fi.getString("UTF-8");
-
- String doc_file_name = file_upload_fi.getName();
- logger_.debug(" file content type =" + file_upload_fi.getContentType());
-
- String extension = Verify.extractExtension(doc_file_name);
- if (extension != null && !extension.equals("pdf"))
- {
- throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf).");
- }
-
- byte[] pdf = file_upload_fi.get();
- if (file_upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty.");
- }
- PdfAS.applyStrictMode(pdf);
-
- String user_name = (String) request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_NAME);
- String user_password = (String) request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD);
-
- SessionInformation si = new SessionInformation(); // SessionTable.generateSessionInformationObject();
- si.connector = connector;
- si.application = "sign";
- si.mode = mode;
- si.pdf = pdf;
- si.type = sig_type;
- si.user_name = user_name;
- si.user_password = user_password;
- si.filename = formatFileName(file_upload_fi.getName());
- si.download_inline = download_inline;
-
- prepareSign(si);
-
- if (preview)
- {
- request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
-
- String submit_url = response.encodeURL(request.getContextPath() + "/SignPreview");
-
- request.setAttribute("submit_url", submit_url);
-
- dispatch(request, response, "/jsp/signpreview.jsp");
-
- return;
- }
-
- finishSign(si, request, response, getServletContext());
- }
- catch (FileUploadException e)
- {
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
- dispatch(request, response, "/jsp/error.jsp");
- }
- catch (PresentableException e)
- {
- e.printStackTrace();
- prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
- }
- }
-
- public static void prepareSign(SessionInformation si) throws PresentableException
- {
- PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
- Signator signator = SignatorFactory.createSignator(algorithm);
- si.iui = signator.prepareSign(si.pdf, si.type, null, ConnectorFactory.needsSIG_ID(si.connector));
- }
-
- public static void finishSign(SessionInformation si,
- HttpServletRequest request, HttpServletResponse response, ServletContext context) throws PresentableException, IOException, ServletException
- {
- if (ConnectorFactory.isConnectorLocal(si.connector))
- {
- LocalRequestHelper.processLocalSign(si, request, response);
- dispatch(request, response, LocalRequestHelper.LOCAL_CONNECTION_PAGE_JSP, context);
- return;
- }
-
- PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
- Signator signator = SignatorFactory.createSignator(algorithm);
-
- // FIXME refactor WEB
- si.iui.signed_signature_object = null; //PdfAS.sign(si.iui.document_text, si.type, si.connector, si.user_name, si.user_password);
-
- si.sign_result = signator.finishSign(si.iui);
-
- returnSignResponse(si, response);
- }
-
- public static void prepareDispatchToErrorPage(PresentableException pe,
- HttpServletRequest request)
- {
- if (pe instanceof ErrorCodeException)
- {
- ErrorCodeException ece = (ErrorCodeException) pe;
- request.setAttribute("error", "Fehler " + ece.getErrorCode());
-
- String cause = ece.getErrorCodeMessage();
- if (ece.hasExternalErrorMessage())
- {
- cause = ece.getExternalErrorCode() + ": " + ece.getExternalErrorMessage();
- }
- request.setAttribute("cause", cause);
-
- if (pe instanceof PlaceholderException)
- {
- PlaceholderException phe = (PlaceholderException) ece;
-
- request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + ece.getErrorCodeMessage());
- }
- }
- else
- {
- request.setAttribute("error", "PresentableException");
- request.setAttribute("cause", pe.toString());
- }
- }
-
- public void dispatchToPreview(String document_text, String connector,
- String mode, String signature_type, String submit_url,
- HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- request.setAttribute("document_text", document_text);
- request.setAttribute("connector", connector);
- request.setAttribute("mode", mode);
- request.setAttribute("signature_type", signature_type);
- request.setAttribute("submit_url", submit_url);
-
- dispatch(request, response, "/jsp/signpreview.jsp");
- }
-
- // public static void formatPreview(String document_text, String connector,
- // String mode, String signature_type, String submit_url,
- // HttpServletResponse response) throws ServletException, IOException
- // {
- // response.setContentType("text/html");
- // response.setCharacterEncoding("UTF-8");
- //
- // PrintWriter writer = response.getWriter();
- //
- // writer.println("<html>");
- // writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
- // Transitional//EN\"
- // \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
- // writer.println("<html>");
- // writer.println("<head>");
- // writer.println("<meta http-equiv=\"content-type\" content=\"text/html;
- // charset=UTF-8\" />");
- // writer.println("<title>PDF-AS Amtssignaturen Vorschau</title>");
- // writer.println("<link rel=\"stylesheet\" type=\"text/css\"
- // href=\"/pdf-as/css/styles.css\" />");
- // writer.println("</head>");
- //
- // writer.println("<body>");
- // writer.println("<div>");
- //
- // writer.println("<h1>PDF-AS Amtssignaturen</h1>");
- //
- // writer.println("<div id=\"nav\">");
- // writer.println("<div id=\"nh\">Vorschau: Dokument Pr&uuml;fen</div>");
- // writer.println("<form action=\"" + submit_url + "\"");
- // writer.println(" name=\"submitform\"");
- // writer.println(" enctype=\"multipart/form-data\"");
- // writer.println(" accept-charset=\"UTF-8\"");
- // writer.println(" method=\"post\">");
- // writer.println("<div id=\"ct\">");
- //
- // writer.println("<input type=\"hidden\" name=\"" + FormFields.FIELD_PREVIEW
- // + "\" value=\"" + FormFields.VALUE_FALSE + "\" />");
- // writer.println("<input type=\"hidden\" name=\"" +
- // FormFields.FIELD_SIGNATURE_TYPE + "\" value=\"" + signature_type + "\"
- // />");
- // writer.println("<input type=\"hidden\" name=\"" +
- // FormFields.FIELD_CONNECTOR + "\" value=\"" + connector + "\" />");
- // writer.println("<input type=\"hidden\" name=\"" + FormFields.FIELD_MODE +
- // "\" value=\"" + mode + "\" />");
- // writer.println("<input type=\"hidden\" name=\"" + "after_preview" + "\"
- // value=\"" + "yes" + "\" />");
- //
- // writer.println("<textarea class=\"pr\" cols=\"80\" rows=\"14\" name=\"" +
- // FormFields.FIELD_UPLOAD + "\" readonly=\"readonly\">" + document_text +
- // "</textarea>");
- // writer.println("<br/>");
- //
- // writer.println("<input class=\"ip\" type=\"submit\" value=\"Signieren...\"
- // />");
- //
- // writer.println("</div>");
- // writer.println("</form>");
- // writer.println("</div>");
- //
- // writer.println("<a class=\"big\" href=\"/pdf-as/\">zurück</a>");
- //
- // writer.println("</div>");
- // writer.println("</body>");
- //
- // writer.println("</html>");
- // }
-
- /**
- * This class is just used to put the pdf byte array into the session.
- *
- * @author wprinz
- */
- protected class SignPreviewInfo implements Serializable
- {
- /**
- * SVUID.
- */
- private static final long serialVersionUID = 3102824040163616332L;
-
- public byte[] pdf = null;
-
- public String mode = null;
- }
-
- /**
- * Formats the file name so that it is suitable for content disposition.
- *
- * @param file_name
- * The file name.
- * @return Returns the formatted file name.
- */
- public static String formatFileName(String file_name)
- {
- File file = new File(file_name);
- String file_name_only = file.getName();
- // the file_name contains \\ ==> remove them so Internet Explorer works
- // correctly.
- return file_name_only;
- }
-
- /**
- * Formats the file name according to the SignResult.
- *
- * @param file_name
- * The file name.
- * @param sign_result
- * The sign result.
- * @return Returns the formatted file name.
- */
- public static String formatFileNameForSignResult(String file_name,
- SignResult sign_result)
- {
- String output = file_name + "_signed";
- if (sign_result.getMimeType().equals(DetachedSignator_1_0_0.MIME_TYPE))
- {
- output += ".xml";
- }
- else
- {
- output += ".pdf";
- }
-
- return output;
- }
-
- /**
- * Returns the data in the SignResult with proper content disposition.
- *
- * @param si
- * SessionInformation.
- * @param response
- * The servlet response.
- * @throws IOException
- * The IO Exception.
- */
- public static void returnSignResponse(SessionInformation si,
- HttpServletResponse response) throws IOException
- {
- SignResult sign_result = si.sign_result;
-
- String file_name = formatFileNameForSignResult(si.filename, sign_result);
-
- // The name parameter is actually deprecated in favour of Content-Disposition filename
- // Unfortunately Acrobat reader does recognize neither of these parameters
- // with its inline save-as. It always takes the page name.
- response.setContentType(sign_result.getMimeType() + "; name=\"" + file_name + "\"");
- if (si.download_inline)
- {
- response.addHeader("Content-Disposition", "inline; filename=\"" + file_name + "\"");
- }
- else
- {
- response.addHeader("Content-Disposition", "attachment; filename=\"" + file_name + "\"");
- }
- response.getOutputStream().write(sign_result.getData());
-
- }
-} \ No newline at end of file
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/Verify.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/Verify.java
deleted file mode 100644
index a8a5a5b..0000000
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/Verify.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * <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: Verify.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $
- */
-package at.knowcenter.wag.egov.egiz.web;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileUploadException;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload.servlet.ServletFileUpload;
-import org.apache.log4j.Logger;
-
-import at.knowcenter.wag.egov.egiz.PdfAS;
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
-import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
-import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
-import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
-import at.knowcenter.wag.egov.egiz.framework.VerificationFilter;
-import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
-
-/**
- * This method is the verify servlet for the pdf-as web application. It takes
- * get and post requests fill out jsp templates and give the user feedback about
- * the results of the verify process.
- *
- * @author wlackner
- * @author wprinz
- */
-public class Verify extends HttpServlet
-{
-
- /**
- * SVUID.
- */
- private static final long serialVersionUID = 309198792358636766L;
-
- /**
- * The logger.
- */
- private static final Logger logger_ = ConfigLogger.getLogger(Verify.class);
-
- protected void dispatch(HttpServletRequest request,
- HttpServletResponse response, String resource) throws ServletException, IOException
- {
- response.setContentType("text/html");
- response.setCharacterEncoding("UTF-8");
-
- RequestDispatcher disp = getServletContext().getRequestDispatcher(resource);
- disp.forward(request, response);
- }
-
- protected void dispatchToResults(List results, HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException
- {
- request.setAttribute("results", results);
- dispatch(request, response, "/jsp/results.jsp");
- }
-
-
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- dispatch(request, response, "/jsp/verifyupload.jsp");
- }
-
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
-
- DiskFileItemFactory fif = new DiskFileItemFactory();
- fif.setRepository(SettingsReader.getTemporaryDirectory());
- ServletFileUpload sfu = new ServletFileUpload(fif);
-
- try
- {
-
- List items = sfu.parseRequest(request);
-
- FileItem upload_fi = null;
- FileItem connector_fi = null;
-// FileItem mode_fi = null;
- FileItem preview_fi = null;
-
- {
- Iterator it = items.iterator();
- while (it.hasNext())
- {
- FileItem item = (FileItem) it.next();
- logger_.debug("item = " + item.getFieldName());
-
- if (item.isFormField())
- {
- byte[] item_data = item.get();
- String item_string = new String(item_data, "UTF-8");
- logger_.debug(" form field string = " + item_string);
- }
- else
- {
- logger_.debug(" filename = " + item.getName());
- logger_.debug(" filesize = " + item.getSize());
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_UPLOAD))
- {
- upload_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
- {
- connector_fi = item;
- continue;
- }
-
-// if (item.getFieldName().equals(FormFields.FIELD_MODE))
-// {
-// mode_fi = item;
-// continue;
-// }
-
- if (item.getFieldName().equals(FormFields.FIELD_PREVIEW))
- {
- preview_fi = item;
- continue;
- }
-
- throw new ServletException("unrecognized POST data.");
- }
- }
-
- if (upload_fi == null || connector_fi == null || /*mode_fi == null ||*/ preview_fi == null)
- {
- throw new ServletException("Unsufficient data provided in request.");
- }
-
- String connector = connector_fi.getString("UTF-8");
-
-// String mode = mode_fi.getString("UTF-8");
-// if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL))
-// {
-// throw new ServletException("The mode '" + mode + "' is unrecognized.");
-// }
-
- String preview_str = preview_fi.getString("UTF-8");
- if (!preview_str.equals(FormFields.VALUE_TRUE) && !preview_str.equals(FormFields.VALUE_FALSE))
- {
- throw new ServletException("The preview '" + preview_str + "' is unrecognized.");
- }
- boolean preview = false;
- if (preview_str.equals(FormFields.VALUE_TRUE))
- {
- preview = true;
- }
-
- // process the request
- logger_.debug("file content type =" + upload_fi.getContentType());
- logger_.debug("file size = " + upload_fi.getSize());
- if (upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty.");
- }
- byte[] document_bytes = upload_fi.get();
-
- VerificationFilter vf = new VerificationFilter();
- List signature_holders = null;
-
- String doc_file_name = upload_fi.getName();
- String extension = extractExtension(doc_file_name);
-
- String raw_text = null;
- if (doc_file_name == null || (extension != null && extension.equals("txt")))
- {
- raw_text = new String(document_bytes, "UTF-8");
- signature_holders = vf.extractSignaturesFromPlainText(raw_text);
- }
- else
- {
- signature_holders = vf.extractSignaturesFromPdf(document_bytes);
- }
-
- if (signature_holders.size() == 0)
- {
- throw new PDFDocumentException(206, "PDF document not signed.");
- }
-
- if (preview)
- {
- SessionInformation si = new SessionInformation();
- si.application = "verify";
- si.connector = connector;
- si.signature_holders = signature_holders;
- request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
-
- dispatch(request, response, "/jsp/verifylist.jsp");
- //VerifyPreview.formatPreview(signature_holders, connector, request, response);
- }
- else
- {
- if (ConnectorFactory.isConnectorLocal(connector))
- {
- SessionInformation si = new SessionInformation(); //SessionTable.generateSessionInformationObject();
- si.connector = connector;
- si.application = "verify";
- si.mode = null;
- si.pdf = null;
- si.type = null;
- si.user_name = null;
- si.user_password = null;
-
- si.signature_holders = signature_holders;
-
- LocalRequestHelper.processLocalVerify(si, si.signature_holders, request, response);
- dispatch(request, response, LocalRequestHelper.LOCAL_CONNECTION_PAGE_JSP);
- return;
- }
-
- List results = PdfAS.verifySignatureHolders(signature_holders, connector);
- dispatchToResults(results, request, response);
- }
-
- }
- catch (FileUploadException e)
- {
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
- dispatch(request, response, "/jsp/error.jsp");
- }
- catch (PresentableException e)
- {
- e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
- dispatch(request, response, "/jsp/error.jsp");
- }
-
- }
-
- /**
- * Extracts the extension from a file name string.
- *
- * <p>
- * The extension of a file name is whatever text follows the last '.'.
- * </p>
- *
- * @param file_name
- * The file name.
- * @return Returns the extension. If the file name ends with the '.', then an
- * empty string is returned. If the file name doesn't contain any '.'
- * or file_name is null, null is returned.
- */
- public static String extractExtension(String file_name)
- {
- if (file_name == null)
- {
- return null;
- }
-
- int dot_index = file_name.lastIndexOf('.');
- if (dot_index < 0)
- {
- return null;
- }
- return file_name.substring(dot_index + 1);
- }
-} \ No newline at end of file
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java
new file mode 100644
index 0000000..7d7220c
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java
@@ -0,0 +1,199 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.framework.Signator;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+import at.knowcenter.wag.egov.egiz.web.LocalRequest;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
+
+/**
+ * @author wprinz
+ *
+ */
+public class DataURLServlet extends HttpServlet
+{
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -5846618335843762752L;
+
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(DataURLServlet.class);
+
+ protected void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource) throws ServletException, IOException
+ {
+ dispatch(request, response, resource, getServletContext());
+ }
+
+ protected static void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setCharacterEncoding("UTF-8");
+
+ RequestDispatcher disp = context.getRequestDispatcher(resource);
+ disp.forward(request, response);
+ }
+
+ protected void dispatchToResults(List results, HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException
+ {
+ request.setAttribute("results", results);
+ dispatch(request, response, "/jsp/results.jsp");
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ log.debug("Data URL is accessed."); //$NON-NLS-1$
+
+ HttpSession session = request.getSession(false);
+ if (session == null)
+ {
+ String msg = "There is no session associated with this request."; //$NON-NLS-1$
+ log.error(msg);
+ throw new ServletException(msg);
+ }
+
+ SessionInformation si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
+ if (si == null)
+ {
+ String msg = "The session is not found or no longer valid."; //$NON-NLS-1$
+ log.error(msg);
+ throw new ServletException(msg);
+ }
+
+ try
+ {
+ log.debug("Request character encoding = " + request.getCharacterEncoding()); //$NON-NLS-1$
+ if (request.getCharacterEncoding() == null || request.getCharacterEncoding().equals("UTF-8")) //$NON-NLS-1$
+ {
+ log.error("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$
+
+ log.warn("Manually setting character encoding to UTF-8"); //$NON-NLS-1$
+ request.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+ }
+
+ String xml_response = request.getParameter("XMLResponse"); //$NON-NLS-1$
+ log.debug("xml_response = " + xml_response); //$NON-NLS-1$
+
+ if (isNullResponse(xml_response))
+ {
+ log.debug("Received a NullOperationResponse -> answering with the first request."); //$NON-NLS-1$
+
+ assert si.current_operation == 0;
+ }
+ else
+ {
+ log.debug("Recieved a normal response -> storing the response."); //$NON-NLS-1$
+
+ Properties response_properties = new Properties();
+ response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
+ si.response_properties[si.current_operation] = response_properties;
+
+ si.current_operation++;
+ }
+
+ if (si.current_operation < si.requests.length)
+ {
+ log.debug("There are still requests to be performed -> answering with request #" + si.current_operation); //$NON-NLS-1$
+
+ LocalRequest local_request = si.requests[si.current_operation];
+
+ String request_string = local_request.getRequestString();
+
+ response.setContentType("text/xml");
+ response.setCharacterEncoding("UTF-8");
+ response.getWriter().println(request_string);
+ }
+ else
+ {
+ log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
+
+ if (si.application.equals("sign"))
+ {
+ // Sign
+
+ if (si.sign_result == null)
+ {
+ LocalConnector c = new LocRefDetachedBKUConnector(si.type, "loc ref content not needed here"); //$NON-NLS-1$
+
+ si.iui.signed_signature_object = c.analyzeSignResponse(si.response_properties[0]);
+
+ PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
+ Signator signator = SignatorFactory.createSignator(algorithm);
+
+ si.sign_result = signator.finishSign(si.iui);
+ }
+
+ SignServlet.returnSignResponse(si, response);
+ }
+ else
+ {
+ // Verify
+
+ List results = new ArrayList();
+
+ for (int i = 0; i < si.response_properties.length; i++)
+ {
+ LocalConnector c = new LocRefDetachedBKUConnector(si.type, "loc ref content not needed here"); //$NON-NLS-1$
+
+ SignatureResponse sig_resp = c.analyzeVerifyResponse(si.response_properties[i]);
+ results.add(sig_resp);
+ }
+
+ dispatchToResults(results, request, response);
+ }
+ }
+ }
+ catch (PresentableException e)
+ {
+ log.error(e);
+ SignServlet.prepareDispatchToErrorPage(e, request);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+
+ log.debug("DataURL access finished."); //$NON-NLS-1$
+ }
+
+ protected boolean isNullResponse(String xml_response)
+ {
+ return xml_response.indexOf("NullOperationResponse") >= 0;
+ }
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java
new file mode 100644
index 0000000..402170c
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/RetrieveSignatureDataServlet.java
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
+
+/**
+ * Retrieves the Signature Data from the session and returns it.
+ *
+ * @author wprinz
+ */
+public class RetrieveSignatureDataServlet extends HttpServlet
+{
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -5387006236836240538L;
+
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(RetrieveSignatureDataServlet.class);
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ log.debug("Request for receiving signature data."); //$NON-NLS-1$
+
+ HttpSession session = request.getSession(false);
+ if (session == null)
+ {
+ String msg = "There is no session associated with this request."; //$NON-NLS-1$
+ log.error(msg);
+ throw new ServletException(msg);
+ }
+
+ SessionInformation si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
+ if (si == null)
+ {
+ String msg = "The session is not found or no longer valid."; //$NON-NLS-1$
+ log.error(msg);
+ throw new ServletException(msg);
+ }
+
+ SignatureData sd = null;
+ if (si.application.equals("sign"))
+ {
+ sd = si.iui.signature_data;
+ }
+ else
+ {
+ SignatureHolder holder = (SignatureHolder) si.signature_holders.get(si.current_operation);
+ SignatureObject s = holder.getSignatureObject();
+
+ // TODO make better
+ String text_to_be_verified = holder.getSignedText();
+ if (holder.getSignatureObject().isBinary())
+ {
+ byte[] data = CodingHelper.decodeBase64(text_to_be_verified);
+ sd = new SignatureDataImpl(data, "application/pdf");
+ }
+ else
+ {
+ sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
+ }
+
+ }
+
+ log.debug("Writing " + sd.getMimeType() + " data:"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ response.setContentType(sd.getMimeType());
+ response.setCharacterEncoding(sd.getCharacterEncoding());
+ response.getOutputStream().write(sd.getData());
+
+ log.debug("Writing SignatureData finished."); //$NON-NLS-1$
+ }
+
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/SignPreview.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java
index 1b32bdf..1d8ee0b 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/SignPreview.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignPreviewServlet.java
@@ -15,7 +15,7 @@
*
* $Id: SignPreview.java,v 1.2 2006/10/11 07:39:13 wprinz Exp $
*/
-package at.knowcenter.wag.egov.egiz.web;
+package at.knowcenter.wag.egov.egiz.web.servlets;
import java.io.IOException;
@@ -28,11 +28,14 @@ import javax.servlet.http.HttpSession;
import at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* @author wprinz
*/
-public class SignPreview extends HttpServlet
+public class SignPreviewServlet extends HttpServlet
{
/**
@@ -53,19 +56,15 @@ public class SignPreview extends HttpServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
SessionInformation si = null;
- HttpSession session = null;
try
{
- session = request.getSession(false);
- // String session_id_string = request.getParameter("session");
+ HttpSession session = request.getSession(false);
if (session == null)
{
throw new ErrorCodeException(600, "The session is missing.");
}
si = (SessionInformation) session.getAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION);
- // long session_id = Long.parseLong(session_id_string);
- // si = SessionTable.get(session_id);
if (si == null)
{
throw new ErrorCodeException(600, "The session is not found or is no longer valid.");
@@ -75,7 +74,7 @@ public class SignPreview extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
return;
@@ -83,22 +82,12 @@ public class SignPreview extends HttpServlet
try
{
- String preview = request.getParameter(FormFields.FIELD_PREVIEW);
- if (preview != null && preview.equals(FormFields.VALUE_TRUE))
- {
- response.setContentType("application/pdf");
- response.getOutputStream().write(si.iui.signed_pdf);
- return;
- }
- else
- {
- Sign.finishSign(si, request, response, getServletContext());
- }
+ SignServlet.finishSign(si, request, response, getServletContext());
}
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
}
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
new file mode 100644
index 0000000..f2cbde8
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
@@ -0,0 +1,576 @@
+/**
+ * <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: Sign.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Logger;
+
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.ErrorCodeException;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
+import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.framework.SignResult;
+import at.knowcenter.wag.egov.egiz.framework.Signator;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.framework.signators.DetachedSignator_1_0_0;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
+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.LocRefDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.moa.DetachedLocRefMOAConnector;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+import at.knowcenter.wag.egov.egiz.web.LocalRequest;
+import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
+
+/**
+ * This method is the sign servlet for the pdf-as web application. It takes get
+ * and post requests fill out jsp templates and give the user feedback about the
+ * results of the sign process
+ *
+ * @author wlackner
+ * @author wprinz
+ */
+public class SignServlet extends HttpServlet
+{
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -4156938216903740438L;
+
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(SignServlet.class);
+
+ protected void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource) throws ServletException, IOException
+ {
+ dispatch(request, response, resource, getServletContext());
+ }
+
+ protected static void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource, ServletContext context) throws ServletException, IOException
+ {
+ response.setContentType("text/html");
+ response.setCharacterEncoding("UTF-8");
+
+ RequestDispatcher disp = context.getRequestDispatcher(resource);
+ disp.forward(request, response);
+ }
+
+ // The sign servlet is used for processing the upload only.
+ // Authentication is deactivated. if required - make an own servlet.
+ // /**
+ // * @author modified by tknall
+ // */
+ // public void doGet(HttpServletRequest request, HttpServletResponse response)
+ // throws ServletException, IOException
+ // {
+ // String authenticate = request.getHeader(AUTH);
+ // if (authenticate != null)
+ // {
+ // logger_.info("authenticate:" + authenticate);
+ // if (authenticate.indexOf(AUTH_BASIC) == 0)
+ // {
+ // authenticate = authenticate.substring(AUTH_BASIC.length() + 1);
+ // logger_.info("authenticate:" + authenticate);
+ // authenticate = new String(CodingHelper.decodeBase64(authenticate),
+ // "UTF-8");
+ // logger_.info("authenticate:" + authenticate);
+ //
+ // String[] auth_value = authenticate.split(":");
+ // String user_name = auth_value[0];
+ // String user_password = auth_value[1];
+ // logger_.info("username:" + user_name);
+ // // start modification tknall
+ // // logger_.info("password:" + user_password);
+ // logger_.info("password:XXXXXXXXXXXX");
+ // // stop modification tknall
+ //
+ // HttpSession session = request.getSession();
+ // session.setAttribute(SessionAttributes.ATTRIBUTE_USER_NAME, user_name);
+ // session.setAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD,
+ // user_password);
+ //
+ // dispatch(request, response, "/jsp/signupload.jsp");
+ // return;
+ // }
+ // // start modification tknall
+ // } else {
+ // String user_name = "";
+ // String user_password = "";
+ // logger_.info("authenticate:User has not been authenticated!");
+ // logger_.info("username: UNKNOWN");
+ // logger_.info("password: XXXXXXXXXXXX");
+ // HttpSession session = request.getSession();
+ // session.setAttribute("uname", user_name);
+ // session.setAttribute("upass", user_password);
+ // dispatch(request, response, "/jsp/signupload.jsp");
+ // }
+
+ // request.setAttribute("error", "Falsche Authentifikation");
+ // request.setAttribute("cause", "Passwort oder Benutzername ist falsch");
+ // dispatch(request, response, "/jsp/error.jsp");
+ // // stop modification tknall
+ // }
+
+ /**
+ * Processes the sign upload.
+ *
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ try
+ {
+ UploadedData ud = retrieveUploadedDataFromRequest(request);
+
+ PdfAS.applyStrictMode(ud.pdf);
+
+ SessionInformation si = new SessionInformation(); // SessionTable.generateSessionInformationObject();
+ si.connector = ud.sig_app;
+ si.application = "sign";
+ si.mode = ud.sig_mode;
+ si.pdf = ud.pdf;
+ si.type = ud.sig_type;
+ si.filename = formatFileName(ud.file_name);
+ si.download_inline = ud.download_inline;
+
+ request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
+
+ // String user_name = (String)
+ // request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_NAME);
+ // String user_password = (String)
+ // request.getSession().getAttribute(SessionAttributes.ATTRIBUTE_USER_PASSWORD);
+ // si.user_name = user_name;
+ // si.user_password = user_password;
+
+ prepareSign(si);
+
+ if (ud.preview)
+ {
+ String submit_url = response.encodeURL(request.getContextPath() + "/SignPreview");
+ String signature_data_url = response.encodeURL(request.getContextPath() + "/RetrieveSignatureData");
+
+ request.setAttribute("submit_url", submit_url);
+ request.setAttribute("signature_data_url", signature_data_url);
+
+ dispatch(request, response, "/jsp/signpreview.jsp");
+
+ return;
+ }
+
+ finishSign(si, request, response, getServletContext());
+ }
+ catch (FileUploadException e)
+ {
+ request.setAttribute("error", "Fehler beim Upload der Daten");
+ request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+ catch (PresentableException e)
+ {
+ e.printStackTrace();
+ prepareDispatchToErrorPage(e, request);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+ }
+
+ protected UploadedData retrieveUploadedDataFromRequest(
+ HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
+ {
+ DiskFileItemFactory fif = new DiskFileItemFactory();
+ fif.setRepository(SettingsReader.getTemporaryDirectory());
+ ServletFileUpload sfu = new ServletFileUpload(fif);
+
+ List items = sfu.parseRequest(request);
+
+ FileItem preview_fi = null;
+ FileItem sig_type_fi = null;
+ FileItem sig_app_fi = null;
+ FileItem mode_fi = null;
+ FileItem file_upload_fi = null;
+ FileItem download_fi = null;
+
+ Iterator it = items.iterator();
+ while (it.hasNext())
+ {
+ FileItem item = (FileItem) it.next();
+ log.debug("item = " + item.getFieldName()); //$NON-NLS-1$
+
+ if (log.isDebugEnabled())
+ {
+ if (item.isFormField())
+ {
+ String item_string = item.getString("UTF-8"); //$NON-NLS-1$
+ log.debug(" form field string = " + item_string); //$NON-NLS-1$
+ }
+ else
+ {
+ log.debug(" filename = " + item.getName()); //$NON-NLS-1$
+ log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$
+ }
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_PREVIEW))
+ {
+ preview_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
+ {
+ sig_type_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
+ {
+ sig_app_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_MODE))
+ {
+ mode_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_UPLOAD))
+ {
+ file_upload_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD))
+ {
+ download_fi = item;
+ continue;
+ }
+
+ throw new ServletException("unrecognized POST data."); //$NON-NLS-1$
+
+ }
+
+ if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || file_upload_fi == null || download_fi == null)
+ {
+ throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$
+ }
+
+ String mode = mode_fi.getString("UTF-8"); //$NON-NLS-1$
+ if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL) && !mode.equals(FormFields.VALUE_MODE_DETACHED))
+ {
+ throw new ServletException("The mode '" + mode + "' is unrecognized."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$
+ boolean preview = false;
+ if (preview_str.equals("true")) //$NON-NLS-1$
+ {
+ preview = true;
+ }
+
+ boolean download_inline = true;
+ if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT)) //$NON-NLS-1$
+ {
+ download_inline = false;
+ }
+
+ String sig_type = sig_type_fi.getString("UTF-8"); //$NON-NLS-1$
+ String sig_app = sig_app_fi.getString("UTF-8"); //$NON-NLS-1$
+
+ String doc_file_name = file_upload_fi.getName();
+ log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
+
+ String extension = VerifyServlet.extractExtension(doc_file_name);
+ if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
+ {
+ throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ byte[] pdf = file_upload_fi.get();
+ if (file_upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
+
+ UploadedData ud = new UploadedData();
+
+ ud.preview = preview;
+ ud.download_inline = download_inline;
+ ud.sig_type = sig_type;
+ ud.sig_app = sig_app;
+ ud.sig_mode = mode;
+ ud.file_name = doc_file_name;
+ ud.pdf = pdf;
+
+ return ud;
+ }
+
+ /**
+ * Prepares the sign.
+ *
+ * <p>
+ * This prepares the data for both being signed or being previewed.
+ * </p>
+ *
+ * @param si
+ * The SessionInformation to be prepared.
+ * @throws PresentableException
+ * f.e.
+ */
+ public static void prepareSign(SessionInformation si) throws PresentableException
+ {
+ log.debug("prepareSign:"); //$NON-NLS-1$
+
+ PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
+ Signator signator = SignatorFactory.createSignator(algorithm);
+ si.iui = signator.prepareSign(si.pdf, si.type, null, ConnectorFactory.needsSIG_ID(si.connector));
+
+ log.debug("prepareSign finished."); //$NON-NLS-1$
+ }
+
+ /**
+ * Finishes the sign.
+ *
+ * <p>
+ * For non local connectors this concludes the sign process, signs the
+ * document and returns the result. For local connectors this initializes the
+ * local sign process and redirects to following servlets.
+ * </p>
+ *
+ * @param si
+ * The SessionInformation.
+ * @param request
+ * The servlet request for dispatching.
+ * @param response
+ * The servlet response for dispatching.
+ * @param context
+ * The servlet context for dispatching.
+ * @throws PresentableException
+ * f.e.
+ * @throws IOException
+ * f. e.
+ * @throws ServletException
+ * f. e.
+ */
+ public static void finishSign(SessionInformation si,
+ HttpServletRequest request, HttpServletResponse response,
+ ServletContext context) throws PresentableException, IOException, ServletException
+ {
+ log.debug("finishSign:"); //$NON-NLS-1$
+
+ log.debug("connector = " + si.connector); //$NON-NLS-1$
+ if (ConnectorFactory.isConnectorLocal(si.connector))
+ {
+ log.debug("Connector is local -> dispatching to local processing."); //$NON-NLS-1$
+
+ String dispatch_to = LocalRequestHelper.processLocalSign(si, request, response);
+ dispatch(request, response, dispatch_to, context);
+ return;
+ }
+ log.debug("Connector is not local -> finishing the sign."); //$NON-NLS-1$
+
+ PdfASID algorithm = FormFields.translateSignatureModeToPdfASID(si.mode);
+ Signator signator = SignatorFactory.createSignator(algorithm);
+
+ log.debug("RequestURL = " + request.getRequestURL());
+ log.debug("ContextPath = " + request.getContextPath());
+ String host = request.getServerName();
+ URL signature_data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
+ String signature_data_url = response.encodeURL(signature_data_URL.toString());
+
+ Connector c = new DetachedLocRefMOAConnector(si.type, signature_data_url);
+ si.iui.signed_signature_object = c.doSign(si.iui.signature_data);
+
+ si.sign_result = signator.finishSign(si.iui);
+
+ returnSignResponse(si, response);
+
+ log.debug("finishSign finished."); //$NON-NLS-1$
+ }
+
+ public static void prepareDispatchToErrorPage(PresentableException pe,
+ HttpServletRequest request)
+ {
+ if (pe instanceof ErrorCodeException)
+ {
+ ErrorCodeException ece = (ErrorCodeException) pe;
+ request.setAttribute("error", "Fehler " + ece.getErrorCode());
+
+ String cause = ece.getErrorCodeMessage();
+ if (ece.hasExternalErrorMessage())
+ {
+ cause = ece.getExternalErrorCode() + ": " + ece.getExternalErrorMessage();
+ }
+ request.setAttribute("cause", cause);
+
+ if (pe instanceof PlaceholderException)
+ {
+ PlaceholderException phe = (PlaceholderException) ece;
+
+ request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + ece.getErrorCodeMessage());
+ }
+ }
+ else
+ {
+ request.setAttribute("error", "PresentableException");
+ request.setAttribute("cause", pe.toString());
+ }
+ }
+
+ public void dispatchToPreview(String document_text, String connector,
+ String mode, String signature_type, String submit_url,
+ HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ request.setAttribute("document_text", document_text);
+ request.setAttribute("connector", connector);
+ request.setAttribute("mode", mode);
+ request.setAttribute("signature_type", signature_type);
+ request.setAttribute("submit_url", submit_url);
+
+ dispatch(request, response, "/jsp/signpreview.jsp");
+ }
+
+ /**
+ * Formats the file name so that it is suitable for content disposition.
+ *
+ * @param file_name
+ * The file name.
+ * @return Returns the formatted file name.
+ */
+ public static String formatFileName(String file_name)
+ {
+ File file = new File(file_name);
+ String file_name_only = file.getName();
+ // the file_name contains \\ ==> remove them so Internet Explorer works
+ // correctly.
+ return file_name_only;
+ }
+
+ /**
+ * Formats the file name according to the SignResult.
+ *
+ * @param file_name
+ * The file name.
+ * @param sign_result
+ * The sign result.
+ * @return Returns the formatted file name.
+ */
+ public static String formatFileNameForSignResult(String file_name,
+ SignResult sign_result)
+ {
+ String output = file_name + "_signed";
+ if (sign_result.getMimeType().equals(DetachedSignator_1_0_0.MIME_TYPE))
+ {
+ output += ".xml";
+ }
+ else
+ {
+ output += ".pdf";
+ }
+
+ return output;
+ }
+
+ /**
+ * Returns the data in the SignResult with proper content disposition.
+ *
+ * @param si
+ * SessionInformation.
+ * @param response
+ * The servlet response.
+ * @throws IOException
+ * The IO Exception.
+ */
+ public static void returnSignResponse(SessionInformation si,
+ HttpServletResponse response) throws IOException
+ {
+ SignResult sign_result = si.sign_result;
+
+ String file_name = formatFileNameForSignResult(si.filename, sign_result);
+
+ // The name parameter is actually deprecated in favour of
+ // Content-Disposition filename
+ // Unfortunately Acrobat reader does recognize neither of these parameters
+ // with its inline save-as. It always takes the page name.
+ response.setContentType(sign_result.getMimeType() + "; name=\"" + file_name + "\"");
+ if (si.download_inline)
+ {
+ response.addHeader("Content-Disposition", "inline; filename=\"" + file_name + "\"");
+ }
+ else
+ {
+ response.addHeader("Content-Disposition", "attachment; filename=\"" + file_name + "\"");
+ }
+ response.getOutputStream().write(sign_result.getData());
+
+ }
+
+ protected static class UploadedData
+ {
+ protected boolean preview = false;
+
+ protected boolean download_inline = false;
+
+ protected String sig_type = null;
+
+ protected String sig_app = null;
+
+ protected String sig_mode = null;
+
+ protected String file_name = null;
+
+ protected byte[] pdf = null;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/VerifyPreview.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java
index c39fd91..98f582e 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/VerifyPreview.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java
@@ -15,7 +15,7 @@
*
* $Id: VerifyPreview.java,v 1.4 2006/10/11 07:39:13 wprinz Exp $
*/
-package at.knowcenter.wag.egov.egiz.web;
+package at.knowcenter.wag.egov.egiz.web.servlets;
import java.io.IOException;
import java.io.PrintWriter;
@@ -52,11 +52,15 @@ import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
import at.knowcenter.wag.egov.egiz.sig.SignatureEntry;
import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
/**
* @author wprinz
*/
-public class VerifyPreview extends HttpServlet
+public class VerifyPreviewServlet extends HttpServlet
{
/**
* SVUID.
@@ -66,7 +70,7 @@ public class VerifyPreview extends HttpServlet
/**
* The logger.
*/
- private static final Logger logger_ = ConfigLogger.getLogger(VerifyPreview.class);
+ private static final Logger logger_ = ConfigLogger.getLogger(VerifyPreviewServlet.class);
protected void dispatch(HttpServletRequest request,
HttpServletResponse response, String resource) throws ServletException, IOException
@@ -476,7 +480,7 @@ public class VerifyPreview extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
return;
@@ -547,8 +551,8 @@ public class VerifyPreview extends HttpServlet
if (ConnectorFactory.isConnectorLocal(si.connector))
{
- LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response);
- dispatch(request, response, LocalRequestHelper.LOCAL_CONNECTION_PAGE_JSP);
+ String dispatch_to = LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response);
+ dispatch(request, response, dispatch_to);
return;
}
@@ -564,7 +568,7 @@ public class VerifyPreview extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
}
}
@@ -594,7 +598,7 @@ public class VerifyPreview extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
return;
@@ -679,8 +683,8 @@ public class VerifyPreview extends HttpServlet
if (ConnectorFactory.isConnectorLocal(si.connector))
{
- LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response);
- dispatch(request, response, LocalRequestHelper.LOCAL_CONNECTION_PAGE_JSP);
+ String dispatch_to = LocalRequestHelper.processLocalVerify(si, holders_to_verify, request, response);
+ dispatch(request, response, dispatch_to);
return;
}
@@ -696,7 +700,7 @@ public class VerifyPreview extends HttpServlet
catch (PresentableException e)
{
e.printStackTrace();
- Sign.prepareDispatchToErrorPage(e, request);
+ SignServlet.prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java
new file mode 100644
index 0000000..ee20498
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyServlet.java
@@ -0,0 +1,334 @@
+/*
+ * <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: Verify.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Logger;
+
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+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;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
+import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
+import at.knowcenter.wag.egov.egiz.framework.VerificationFilter;
+import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
+import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+import at.knowcenter.wag.egov.egiz.web.LocalRequest;
+import at.knowcenter.wag.egov.egiz.web.LocalRequestHelper;
+import at.knowcenter.wag.egov.egiz.web.SessionAttributes;
+import at.knowcenter.wag.egov.egiz.web.SessionInformation;
+import at.knowcenter.wag.egov.egiz.web.servlets.SignServlet.UploadedData;
+
+/**
+ * This method is the verify servlet for the pdf-as web application. It takes
+ * get and post requests fill out jsp templates and give the user feedback about
+ * the results of the verify process.
+ *
+ * @author wlackner
+ * @author wprinz
+ */
+public class VerifyServlet extends HttpServlet
+{
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = 309198792358636766L;
+
+ /**
+ * The log.
+ */
+ private static Log log = LogFactory.getLog(SignServlet.class);
+
+ protected void dispatch(HttpServletRequest request,
+ HttpServletResponse response, String resource) throws ServletException, IOException
+ {
+ response.setContentType("text/html"); //$NON-NLS-1$
+ response.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
+
+ RequestDispatcher disp = getServletContext().getRequestDispatcher(resource);
+ disp.forward(request, response);
+ }
+
+ protected void dispatchToResults(List results, HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException
+ {
+ request.setAttribute("results", results); //$NON-NLS-1$
+ dispatch(request, response, "/jsp/results.jsp"); //$NON-NLS-1$
+ }
+
+ /**
+ * Processes the verify upload.
+ *
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ try
+ {
+ UploadedData ud = retrieveUploadedDataFromRequest(request);
+
+ List signature_holders = extractSignatureHoldersFromFile(ud.file_name, ud.file_data);
+
+ SessionInformation si = new SessionInformation(); // SessionTable.generateSessionInformationObject();
+ si.connector = ud.sig_app;
+ si.application = "verify";
+ si.mode = null;
+ si.pdf = null;
+ si.type = null;
+ si.user_name = null;
+ si.user_password = null;
+
+ si.signature_holders = signature_holders;
+
+ request.getSession().setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
+
+ if (ud.preview)
+ {
+ dispatch(request, response, "/jsp/verifylist.jsp");
+ // VerifyPreview.formatPreview(signature_holders, connector, request,
+ // response);
+ }
+ else
+ {
+ if (ConnectorFactory.isConnectorLocal(si.connector))
+ {
+ String dispatch_to = LocalRequestHelper.processLocalVerify(si, si.signature_holders, request, response);
+ dispatch(request, response, dispatch_to);
+ return;
+ }
+
+ List results = PdfAS.verifySignatureHolders(signature_holders, si.connector);
+ dispatchToResults(results, request, response);
+ }
+
+ }
+ catch (FileUploadException e)
+ {
+ request.setAttribute("error", "Fehler beim Upload der Daten");
+ request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+ catch (PresentableException e)
+ {
+ e.printStackTrace();
+ SignServlet.prepareDispatchToErrorPage(e, request);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+
+ }
+
+ protected UploadedData retrieveUploadedDataFromRequest(
+ HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
+ {
+ DiskFileItemFactory fif = new DiskFileItemFactory();
+ fif.setRepository(SettingsReader.getTemporaryDirectory());
+ ServletFileUpload sfu = new ServletFileUpload(fif);
+
+ List items = sfu.parseRequest(request);
+
+ FileItem upload_fi = null;
+ FileItem connector_fi = null;
+ // FileItem mode_fi = null;
+ FileItem preview_fi = null;
+
+ {
+ Iterator it = items.iterator();
+ while (it.hasNext())
+ {
+ FileItem item = (FileItem) it.next();
+ log.debug("item = " + item.getFieldName()); //$NON-NLS-1$
+
+ if (item.isFormField())
+ {
+ String item_string = item.getString("UTF-8"); //$NON-NLS-1$
+ log.debug(" form field string = " + item_string); //$NON-NLS-1$
+ }
+ else
+ {
+ log.debug(" filename = " + item.getName()); //$NON-NLS-1$
+ log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_UPLOAD))
+ {
+ upload_fi = item;
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
+ {
+ connector_fi = item;
+ continue;
+ }
+
+ // if (item.getFieldName().equals(FormFields.FIELD_MODE))
+ // {
+ // mode_fi = item;
+ // continue;
+ // }
+
+ if (item.getFieldName().equals(FormFields.FIELD_PREVIEW))
+ {
+ preview_fi = item;
+ continue;
+ }
+
+ throw new ServletException("unrecognized POST data."); //$NON-NLS-1$
+ }
+ }
+
+ if (upload_fi == null || connector_fi == null || /* mode_fi == null || */preview_fi == null)
+ {
+ throw new ServletException("Unsufficient data provided in request."); //$NON-NLS-1$
+ }
+
+ String connector = connector_fi.getString("UTF-8"); //$NON-NLS-1$
+
+ // String mode = mode_fi.getString("UTF-8");
+ // if (!mode.equals(FormFields.VALUE_MODE_BINARY) &&
+ // !mode.equals(FormFields.VALUE_MODE_TEXTUAL))
+ // {
+ // throw new ServletException("The mode '" + mode + "' is unrecognized.");
+ // }
+
+ String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$
+ if (!preview_str.equals(FormFields.VALUE_TRUE) && !preview_str.equals(FormFields.VALUE_FALSE))
+ {
+ throw new ServletException("The preview '" + preview_str + "' is unrecognized."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ boolean preview = false;
+ if (preview_str.equals(FormFields.VALUE_TRUE))
+ {
+ preview = true;
+ }
+
+ // process the request
+ log.debug("file content type =" + upload_fi.getContentType()); //$NON-NLS-1$
+ log.debug("file size = " + upload_fi.getSize()); //$NON-NLS-1$
+ if (upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
+ byte[] document_bytes = upload_fi.get();
+
+ UploadedData ud = new UploadedData();
+ ud.preview = preview;
+ ud.sig_app = connector;
+ ud.file_name = upload_fi.getName();
+ ud.file_data = document_bytes;
+
+ return ud;
+ }
+
+ protected List extractSignatureHoldersFromFile (String file_name, byte [] data) throws UnsupportedEncodingException, PresentableException
+ {
+ VerificationFilter vf = new VerificationFilter();
+ List signature_holders = null;
+
+ String extension = extractExtension(file_name);
+
+ String raw_text = null;
+ if (file_name == null || (extension != null && extension.equals("txt"))) //$NON-NLS-1$
+ {
+ raw_text = new String(data, "UTF-8"); //$NON-NLS-1$
+ signature_holders = vf.extractSignaturesFromPlainText(raw_text);
+ }
+ else
+ {
+ signature_holders = vf.extractSignaturesFromPdf(data);
+ }
+
+ if (signature_holders.size() == 0)
+ {
+ throw new PDFDocumentException(206, "PDF document not signed."); //$NON-NLS-1$
+ }
+
+ return signature_holders;
+ }
+
+ /**
+ * Extracts the extension from a file name string.
+ *
+ * <p>
+ * The extension of a file name is whatever text follows the last '.'.
+ * </p>
+ *
+ * @param file_name
+ * The file name.
+ * @return Returns the extension. If the file name ends with the '.', then an
+ * empty string is returned. If the file name doesn't contain any '.'
+ * or file_name is null, null is returned.
+ */
+ public static String extractExtension(String file_name)
+ {
+ if (file_name == null)
+ {
+ return null;
+ }
+
+ int dot_index = file_name.lastIndexOf('.');
+ if (dot_index < 0)
+ {
+ return null;
+ }
+ return file_name.substring(dot_index + 1);
+ }
+
+ protected static class UploadedData
+ {
+ protected boolean preview = false;
+
+ protected String sig_app = null;
+
+ protected String file_name = null;
+
+ protected byte[] file_data = null;
+ }
+} \ No newline at end of file