aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java58
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java5
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java3
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java11
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java13
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java9
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java139
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java194
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java17
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java4
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java7
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java41
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java5
-rw-r--r--src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java3
15 files changed, 324 insertions, 187 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 2ffc7b2..3824a98 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -96,7 +96,7 @@ public abstract class PdfAS
* The current version of the pdf-as library. This version string is logged on every invocation
* of the api or the web application.
*/
- public static final String PDFAS_VERSION = "3.0.8-20081119";
+ public static final String PDFAS_VERSION = "3.0.8-20090113";
/**
* The key of the strict mode setting.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java
index d781577..1a41982 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java
@@ -29,28 +29,38 @@ import at.gv.egiz.pdfas.exceptions.ErrorCode;
*
* @author wprinz
*/
-public class SettingsException extends PresentableException
-{
-
- /**
- * SVUID.
- */
- private static final long serialVersionUID = -99979541706943372L;
-
- /**
- * @param message
- */
- public SettingsException(String message)
- {
- super(ErrorCode.SETTINGS_EXCEPTION, message);
- }
-
- /**
- * @param message
- * @param cause
- */
- public SettingsException(String message, Throwable cause)
- {
- super(ErrorCode.SETTINGS_EXCEPTION, message, cause);
- }
+public class SettingsException extends PresentableException {
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -99979541706943372L;
+
+ /**
+ * @param message
+ */
+ public SettingsException(String message) {
+ super(ErrorCode.SETTINGS_EXCEPTION, message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public SettingsException(String message, Throwable cause) {
+ super(ErrorCode.SETTINGS_EXCEPTION, message, cause);
+ }
+
+ public SettingsException(int errorCode, String message, Throwable cause) {
+ super(errorCode, message, cause);
+ }
+
+ public SettingsException(int errorCode, String message) {
+ super(errorCode, message);
+ }
+
+ public SettingsException(int errorCode, Throwable cause) {
+ super(errorCode, cause);
+ }
+
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
index b1b1a5a..0467bad 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java
@@ -359,8 +359,9 @@ public class PDFSignatureObjectIText implements PDFSignatureObject
}
else
{
- if(pdfaValid)
- throw new PDFDocumentException(0,"PDF/A modus requires an embedable true type font");
+ if (pdfaValid) {
+ throw new PDFDocumentException(ErrorCode.NO_EMBEDABLE_TTF_CONFIGURED_FOR_PDFA, "PDF/A modus requires an embedable true type font");
+ }
cell_font = getCellFont(font_string);
}
Phrase text_phrase = new Phrase(text, cell_font);
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 9253955..cec8d6f 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
@@ -156,6 +156,9 @@ public final class BKUHelper
public static SignSignatureObject parseCreateXMLResponse(String xmlResponse,
IdFormatter id_formatter) throws ConnectorException
{
+ if (log.isDebugEnabled()) {
+ log.debug("xmlResponse = " + xmlResponse);
+ }
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$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java
index 1a720d8..b582715 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java
@@ -41,6 +41,11 @@ public final class BKUPostConnection
public static final String BKU_SERVER_HEADER_KEY = "BKU-Server-Header"; //$NON-NLS-1$
/**
+ * The response Properties key that identifies the BKU User-Agent header.
+ */
+ public static final String BKU_USER_AGENT_HEADER_KEY = "BKU-User-Agent-Header"; //$NON-NLS-1$
+
+ /**
* The log.
*/
private static Log log = LogFactory.getLog(BKUPostConnection.class);
@@ -119,7 +124,11 @@ public final class BKUPostConnection
}
}
Header server_header = post_method.getResponseHeader("Server"); //$NON-NLS-1$
- response_properties.setProperty(BKU_SERVER_HEADER_KEY, server_header.getValue());
+ if (server_header != null) {
+ response_properties.setProperty(BKU_SERVER_HEADER_KEY, server_header.getValue());
+ } else {
+ log.warn("BKU response header \"Server\" is empty.");
+ }
log.debug(post_method.getResponseCharSet());
if (!post_method.getResponseCharSet().equals("UTF-8")) //$NON-NLS-1$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java
index 5dbc0a6..d10afc6 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java
@@ -21,7 +21,9 @@ 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.connectors.moa.DetachedLocRefMOAConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.mocca.MOCCAHelper;
import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedIdFormatter;
+import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedMOCIdFormatter;
import at.knowcenter.wag.egov.egiz.sig.sigkz.SigKZIDHelper;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
@@ -123,10 +125,19 @@ public class DetachedBKUConnector implements Connector, LocalConnector
log.debug("analyzeSignResponse:"); //$NON-NLS-1$
String response_string = response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY);
+ String bkuServerHeader = response_properties.getProperty(BKUPostConnection.BKU_SERVER_HEADER_KEY);
+ String bkuUserAgentHeader = response_properties.getProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY);
BKUHelper.checkResponseForError(response_string);
- SignSignatureObject so = BKUHelper.parseCreateXMLResponse(response_string, new DetachedIdFormatter());
+ SignSignatureObject so;
+ if (MOCCAHelper.isMOCCACCEId(bkuServerHeader == null ? bkuUserAgentHeader : bkuServerHeader)) {
+ log.debug("Evaluating response as MOCCA response.");
+ so = MOCCAHelper.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
+ } else {
+ so = BKUHelper.parseCreateXMLResponse(response_string, new DetachedIdFormatter());
+ }
+
so.response_properties = response_properties;
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java
index 44a7c38..b45303d 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java
@@ -4,15 +4,7 @@
package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
import java.security.cert.X509Certificate;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Properties;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -22,7 +14,6 @@ import at.gv.egiz.pdfas.framework.ConnectorParameters;
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.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java
index 8ae6d5f..fcfe006 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java
@@ -1,10 +1,5 @@
package at.knowcenter.wag.egov.egiz.sig.connectors.mocca;
-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;
@@ -15,16 +10,11 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.framework.ConnectorParameters;
-import at.gv.egiz.pdfas.web.helper.SigningTimeHelper;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
-import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
-import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
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.LocalConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
@@ -32,7 +22,6 @@ 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.DetachedMOCIdFormatter;
-import at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
@@ -126,139 +115,13 @@ public class LocRefDetachedMOCCAConnector implements Connector, LocalConnector {
log.debug("analyzeSignResponse:");
String response_string = response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY);
BKUHelper.checkResponseForError(response_string);
- SignSignatureObject so = this.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
+ SignSignatureObject so = MOCCAHelper.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
so.response_properties = response_properties;
log.debug("analyzeSignResponse finished.");
return so;
}
/**
- * This method parses the signature creation response of the signature device.
- * @param xmlResponse The response string.
- * @return Returns the parsed signature object holding the data.
- * @see SignatureObject
- * @see CodingHelper
- * @see X509Cert
- */
- public SignSignatureObject parseCreateXMLResponse(String xmlResponse, IdFormatter id_formatter) throws ConnectorException {
-
- Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>");
- Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>");
- Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>");
- Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>");
- Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>");
- Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>");
- Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>");
- Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>");
-
- 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);
-
- // SignatureValue
- String sig_val = null;
- Matcher signatureValueMatcher = Pattern.compile("<(\\w+:)?SignatureValue( Id=\"[\\w-]+\")?>\\s*(.*)\\s*</(\\w+:)?SignatureValue>").matcher(xmlResponse);
- if (signatureValueMatcher.find()) {
- sig_val = signatureValueMatcher.group(3);
- }
- log.debug("sig_val = " + sig_val);
-
- // 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);
-
- // 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);
-
- // 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);
-
- // 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");
- cert = (X509Certificate) cf.generateCertificate(bais);
- bais.close();
- } catch (UnsupportedEncodingException e) {
- throw new ConnectorException(300, e);
- } catch (CertificateException e) {
- throw new ConnectorException(300, e);
- } catch (IOException e) {
- throw new ConnectorException(300, e);
- }
- }
- log.debug("X509Certificate = " + cert);
-
- if (log.isDebugEnabled()) {
-
- String cert_iss = cert.getIssuerDN().getName();
- log.debug("certificate's issuer = " + cert_iss);
- log.debug("response's issuer = " + iss_nam);
- log.debug("issuer matches = " + cert_iss.equals(iss_nam));
- log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num));
- }
-
- // extract Signature Id's
- String[] ids = extractIds(xmlResponse);
- String final_ids = id_formatter.formatIds(ids);
-
- SignSignatureObject so = new SignSignatureObject();
- so.date = sig_tim;
- so.issuer = iss_nam;
- so.signatureValue = sig_val;
- so.x509Certificate = cert;
-
- so.id = final_ids;
-
- return so;
- }
-
- /**
- * Extraction of the id attributes from the xml response.
- * @param xmlResponse The xml response.
- * @return The parsed id attributes.
- */
- public final static String[] extractIds(String xmlResponse) {
- return new String[] { extractId(xmlResponse) };
- }
-
- /**
- * There is only one special common part of all id attributes of this connector that has to be
- * stored. This method returns that single part.
- * @param xmlResponse The xml response.
- * @return The parsed common part of all id attributes.
- */
- private final static String extractId(String xmlResponse) {
- final Pattern ID_PATTERN = Pattern.compile("Id\\s*=\\s*\"\\s*Signature-([\\p{XDigit}]+)-\\d+\\s*\"");
- Matcher matcher = ID_PATTERN.matcher(xmlResponse);
- if (matcher.find() && matcher.groupCount() > 0) {
- return matcher.group(1);
- }
- return null;
- }
-
- /**
* Verification is not supported by MOCCA. Therefore this method always throws a
* {@link ConnectorException} with error code {@link ErrorCode#SIGNATURE_VERIFICATION_NOT_SUPPORTED}.
*/
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java
new file mode 100644
index 0000000..1bb89be
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java
@@ -0,0 +1,194 @@
+package at.knowcenter.wag.egov.egiz.sig.connectors.mocca;
+
+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;
+
+/**
+ * Provides useful methods for the usage of the open source cce mocca.
+ *
+ * @author tknall
+ */
+public final class MOCCAHelper {
+
+ /**
+ * Prevents this plain util class from being instantiated.
+ */
+ private MOCCAHelper() {
+ }
+
+ /**
+ * The logging implementation.
+ */
+ private final static Log log = LogFactory.getLog(MOCCAHelper.class);
+
+ /**
+ * The pattern that identifies a mocca response (that matches the header value "Server" or "User-Agent").
+ */
+ private final static Pattern MOCCA_PATTERN = Pattern.compile("(citizen-card-environment/\\d+(\\.\\d+) MOCCA[ /].*)|(Jetty(.*))");
+
+ /**
+ * Checks if the given header value for "Server" or "User-Agent" respectively indicates that
+ * the response was from a mocca cce.
+ * @param cceId The value of the http header "Server" or "User-Agent".
+ * @see http://www.buergerkarte.at/konzept/securitylayer/spezifikation/aktuell/bindings/bindings.html#http.kodierung
+ * @return <code>true</code> if the id points to a mocca response, <code>false</code> if not.
+ */
+ public final static boolean isMOCCACCEId(String cceId) {
+ if (cceId == null) {
+ return false;
+ }
+ return MOCCA_PATTERN.matcher(cceId).matches();
+ }
+
+ /**
+ * This method parses the signature creation response of the signature
+ * device mocca.
+ *
+ * @param xmlResponse The response string.
+ * @return Returns the parsed signature object holding the data.
+ * @see SignatureObject
+ * @see CodingHelper
+ * @see X509Cert
+ */
+ public final static SignSignatureObject parseCreateXMLResponse(String xmlResponse, IdFormatter id_formatter) throws ConnectorException {
+
+ if (log.isDebugEnabled()) {
+ log.debug("xmlResponse = " + xmlResponse);
+ }
+
+ Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>");
+ Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>");
+ Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>");
+ Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>");
+ Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>");
+ Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>");
+ Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>");
+ Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>");
+
+ 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);
+
+ // SignatureValue
+ String sig_val = null;
+ Matcher signatureValueMatcher = Pattern.compile("<(\\w+:)?SignatureValue( Id=\"[\\w-]+\")?>\\s*(.*)\\s*</(\\w+:)?SignatureValue>").matcher(xmlResponse);
+ if (signatureValueMatcher.find()) {
+ sig_val = signatureValueMatcher.group(3);
+ }
+ log.debug("sig_val = " + sig_val);
+
+ // 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);
+
+ // 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);
+
+ // 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);
+
+ // 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");
+ cert = (X509Certificate) cf.generateCertificate(bais);
+ bais.close();
+ } catch (UnsupportedEncodingException e) {
+ throw new ConnectorException(300, e);
+ } catch (CertificateException e) {
+ throw new ConnectorException(300, e);
+ } catch (IOException e) {
+ throw new ConnectorException(300, e);
+ }
+ }
+ log.debug("X509Certificate = " + cert);
+
+ if (log.isDebugEnabled()) {
+
+ String cert_iss = cert.getIssuerDN().getName();
+ log.debug("certificate's issuer = " + cert_iss);
+ log.debug("response's issuer = " + iss_nam);
+ log.debug("issuer matches = " + cert_iss.equals(iss_nam));
+ log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num));
+ }
+
+ // extract Signature Id's
+ String[] ids = extractIds(xmlResponse);
+ String final_ids = id_formatter.formatIds(ids);
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = sig_tim;
+ so.issuer = iss_nam;
+ so.signatureValue = sig_val;
+ so.x509Certificate = cert;
+
+ so.id = final_ids;
+
+ return so;
+ }
+
+ /**
+ * Extraction of the id attributes from the xml response.
+ *
+ * @param xmlResponse The xml response.
+ * @return The parsed id attributes.
+ */
+ public final static String[] extractIds(String xmlResponse) {
+ return new String[] { extractId(xmlResponse) };
+ }
+
+ /**
+ * There is only one special common part of all id attributes of this
+ * connector that has to be stored. This method returns that single part.
+ *
+ * @param xmlResponse The xml response.
+ * @return The parsed common part of all id attributes.
+ */
+ private final static String extractId(String xmlResponse) {
+ final Pattern ID_PATTERN = Pattern.compile("Id\\s*=\\s*\"\\s*Signature-([\\p{XDigit}]+)-\\d+\\s*\"");
+ Matcher matcher = ID_PATTERN.matcher(xmlResponse);
+ if (matcher.find() && matcher.groupCount() > 0) {
+ return matcher.group(1);
+ }
+ return null;
+ }
+
+}
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
index 2adc4b1..16352de 100644
--- 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
@@ -126,6 +126,7 @@ public class DataURLServlet extends HttpServlet
{
Object sessionObject = SessionHelper.getSession(request);
+ // obsolete since EncodingFilter is set in web.xml
checkRequestCharacterEncoding(request);
if (sessionObject instanceof SignSessionInformation)
@@ -152,8 +153,6 @@ public class DataURLServlet extends HttpServlet
protected void checkRequestCharacterEncoding(HttpServletRequest request) throws UnsupportedEncodingException
{
- log.debug("Request character encoding = " + request.getCharacterEncoding()); //$NON-NLS-1$
-// if (request.getCharacterEncoding() == null || request.getCharacterEncoding().equals("UTF-8")) //$NON-NLS-1$
if (request.getCharacterEncoding() == null || request.getCharacterEncoding().length() <= 0) //$NON-NLS-1$
{
log.info("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$
@@ -220,12 +219,20 @@ public class DataURLServlet extends HttpServlet
response.setCharacterEncoding("UTF-8");
response.getWriter().println(request_string);
}
- else
+ else if (xml_response != null)
{
log.debug("Received a normal response -> storing the response."); //$NON-NLS-1$
Properties response_properties = new Properties();
response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
+
+ String userAgent = request.getHeader("User-Agent");
+ if (userAgent != null) {
+ response_properties.setProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY, userAgent);
+ } else {
+ log.warn("BKU request/response header \"User-Agent\" is empty.");
+ }
+
si.response_properties = response_properties;
log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
@@ -294,7 +301,9 @@ public class DataURLServlet extends HttpServlet
// do not insert any code within this else block !
}
- }
+ } else {
+ log.debug("No XMLResponse found. Do nothing.");
+ }
}
protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException, ConnectorException, InvalidIDException
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
index a8ff426..1efc64f 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java
@@ -59,8 +59,8 @@ public class ProvidePDFServlet extends HttpServlet {
log.debug("Signed pdf found.");
session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT);
log.debug("Returning signed pdf to browser.");
- log.debug("Invalidating session.");
- session.invalidate();
+// log.debug("Invalidating session.");
+// session.invalidate();
SignServletHelper.returnSignResponse(si, response);
return;
}
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
index 124b2a3..589de7c 100644
--- 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
@@ -244,8 +244,11 @@ public class SignServlet extends HttpServlet
catch (Exception e)
{
// Error retrieving data
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+// request.setAttribute("error", "Fehler beim Upload der Daten");
+// request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ request.setAttribute("error", "signservlet.error");
+ request.setAttribute("cause", "signservlet.cause");
+ request.setAttribute("resourcebundle", Boolean.TRUE);
dispatch(request, response, "/jsp/error.jsp");
return;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java
new file mode 100644
index 0000000..ba5d43e
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java
@@ -0,0 +1,41 @@
+package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+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 at.knowcenter.wag.egov.egiz.web.FormFields;
+
+public class UpdateFormServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String UPLOADFORM_SIGNATURE_TYPE_KEY = "signupload.jsp:signatureType";
+ public static final String UPLOADFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode";
+ public static final String UPLOADFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey";
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ this.doPost(request, response);
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String mode = request.getParameter(FormFields.FIELD_MODE);
+ String device = request.getParameter(FormFields.FIELD_CONNECTOR);
+ String type = request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
+
+ HttpSession session = request.getSession();
+ session.setAttribute(UPLOADFORM_SIGNATURE_DEVICE_KEY, device);
+ session.setAttribute(UPLOADFORM_SIGNATURE_MODE_KEY, mode);
+ session.setAttribute(UPLOADFORM_SIGNATURE_TYPE_KEY, type);
+
+ RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/signupload.jsp");
+ dispatcher.forward(request, response);
+// response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/jsp/signupload.jsp"));
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java
index 5e1819e..0eb417b 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java
@@ -699,8 +699,9 @@ public class VerifyPreviewServlet extends HttpServlet
}
catch (FileUploadException e)
{
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ request.setAttribute("error", "verifypreviewservlet.error");
+ request.setAttribute("cause", "verifypreviewservlet.cause");
+ request.setAttribute("resourcebundle", Boolean.TRUE);
dispatch(request, response, "/jsp/error.jsp");
}
catch (PresentableException e)
diff --git a/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java b/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java
index 1387fb2..88476be 100644
--- a/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java
+++ b/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java
@@ -387,7 +387,8 @@ public abstract class PDFUtils
while (isNumeric(pdf[index]) || pdf[index] == '.')
{
- number += (char) pdf[index];
+ char digit = (char) pdf[index];
+ number += digit;
index++;
}