aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java41
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java36
-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/exceptions/PresentableException.java42
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/AbsoluteTextSignature.java8
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/ActualTablePos.java22
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java8
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/IncrementalUpdateInformation.java5
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureResponse.java12
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java10
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java21
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/TemplateReplaces.java10
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java51
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java17
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/LocRefDetachedBKUConnector.java7
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/MultipartDetachedBKUConnector.java5
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java5
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java64
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java19
19 files changed, 291 insertions, 96 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 6fc7b84..9aef071 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -17,31 +17,27 @@
*/
package at.knowcenter.wag.egov.egiz;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import java.util.Vector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
-import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
-import at.gv.egiz.pdfas.impl.input.DelimitedInputStream;
-import at.gv.egiz.pdfas.impl.input.TextDataSourceImpl;
-import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
-import at.gv.egiz.pdfas.framework.input.DataSource;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
-import at.gv.egiz.pdfas.framework.input.TextDataSource;
import at.gv.egiz.pdfas.framework.output.DataSink;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
+import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
import at.gv.egiz.pdfas.web.VerifySessionInformation;
-
-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.ConnectorFactoryException;
@@ -62,7 +58,6 @@ import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
import at.knowcenter.wag.egov.egiz.pdf.TextualSignature;
import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder;
-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;
@@ -740,7 +735,7 @@ public abstract class PdfAS
return true;
}
- public static List verifySignatureHolders(List signature_holders, String connectorType) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException, ConnectorFactoryException
+ public static List verifySignatureHolders(List signature_holders, String connectorType, boolean returnHashInputData, Date verificationTime) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException, ConnectorFactoryException
{
List results = new ArrayList();
for (int i = 0; i < signature_holders.size(); i++)
@@ -757,7 +752,7 @@ public abstract class PdfAS
// (holder.signature_object.isTextual() ? "textual" : "binary"));
// logger_.debug(holder.signature_object.toString());
- SignatureResponse result = verify(holder, connectorType);
+ SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime);
results.add(result);
// logger_.debug();
@@ -809,7 +804,7 @@ public abstract class PdfAS
* @throws ConnectorException
* @throws ConnectorFactoryException
*/
- public static SignatureResponse verify(SignatureHolder signature_holder, String connectorType) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException, ConnectorFactoryException
+ public static SignatureResponse verify(SignatureHolder signature_holder, String connectorType, boolean returnHashInputData, Date verificationTime) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException, ConnectorFactoryException
{
// String text_to_be_verified = signature_holder.getSignedText();
// logger_.debug("verify text_to_be_verified"+text_to_be_verified);
@@ -844,10 +839,14 @@ public abstract class PdfAS
String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
// Connector c = ConnectorChooser.chooseCommandlineConnectorForVerify(connector, so_to_be_verified.getKZ(), so.id, profile);
String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForVerify(connectorType, so_to_be_verified.getKZ(), so.id, profile);
- Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, profile, null);
+
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ cp.setReturnHashInputData(returnHashInputData);
+ cp.setVerificationTime(verificationTime);
+ Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp);
return c.doVerify(sd, so);
-
}
public static SignatureResponse verifyWeb(SignatureHolder signature_holder, String connector, String loc_ref) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException
@@ -992,11 +991,13 @@ public abstract class PdfAS
// signCommandline(pdfDataSource, dataSink, signatorId, connectorId, profile, pos);
// }
- public static void signCommandline(PdfDataSource pdfDataSource, DataSink dataSink, PdfASID signatorId, String connectorId, final String profile, TablePos pos) throws PresentableException
+ public static SignatorInformation signCommandline(PdfDataSource pdfDataSource, DataSink dataSink, PdfASID signatorId, String connectorId, final String profile, TablePos pos) throws PresentableException
{
at.gv.egiz.pdfas.framework.signator.Signator signator = at.gv.egiz.pdfas.framework.SignatorFactory.createSignator(signatorId);
- Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, profile, null);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp);
// SignatorInformation si = signator.prepareSign(pdfDataSource, profile, pos, ConnectorFactory.needsSIG_ID(connector));
SignatorInformation si = signator.prepareSign(pdfDataSource, profile, pos, CommandlineConnectorChooser.needsSigId(connectorId));
@@ -1006,6 +1007,8 @@ public abstract class PdfAS
si.setSignSignatureObject(sso);
signator.finishSign(si, dataSink);
+
+ return si;
}
/**
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
index 97929af..054da24 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
@@ -344,6 +344,21 @@ public class SettingsReader implements Serializable
{
return getInstance(null);
}
+
+ /**
+ * Reloads the Settings file.
+ *
+ * <p>
+ * Subsequent calls to getInstance will return the new settings.
+ * </p>
+ *
+ * @throws SettingsException f.e.
+ */
+ public synchronized static void createInstance () throws SettingsException
+ {
+ instance_ = null;
+ getInstance();
+ }
/**
* This method returns an synchronized instance of this class. The settings
@@ -663,6 +678,13 @@ public class SettingsReader implements Serializable
}
}
+ public static void initialize(String base_dir)
+ {
+ RESOURCES_PATH = base_dir + FILE_SEP; //CATALINA_HOME + FILE_SEP + WEB_APPL_DIR;
+ CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
+ CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ }
+
/**
* Initializes the paths of the SettingsReader for web application usage.
*
@@ -672,9 +694,10 @@ public class SettingsReader implements Serializable
*/
public static void initializeForWeb(String base_dir)
{
- RESOURCES_PATH = base_dir + FILE_SEP; //CATALINA_HOME + FILE_SEP + WEB_APPL_DIR;
- CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
- CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ initialize(base_dir);
+// RESOURCES_PATH = base_dir + FILE_SEP; //CATALINA_HOME + FILE_SEP + WEB_APPL_DIR;
+// CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
+// CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
}
/**
@@ -682,9 +705,10 @@ public class SettingsReader implements Serializable
*/
public static void initializeForCommandLine()
{
- RESOURCES_PATH = USER_DIR + FILE_SEP;
- CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
- CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ initialize(USER_DIR);
+// RESOURCES_PATH = USER_DIR + FILE_SEP;
+// CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
+// CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
}
static {
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 72565d9..11bd0e0 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
@@ -156,6 +156,8 @@ public abstract class Main
* @param args
* The commandline arguments.
* @throws IOException
+ *
+ * @deprecated use {@link at.gv.egiz.pdfas.commandline.Main} instead
*/
public static void main(String[] args) throws IOException
{
@@ -639,7 +641,7 @@ public abstract class Main
holders_to_verify.add(holder);
}
- List results = PdfAS.verifySignatureHolders(holders_to_verify, connector);
+ List results = PdfAS.verifySignatureHolders(holders_to_verify, connector, false, null);
return results;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/PresentableException.java b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/PresentableException.java
index 218109d..e8ef988 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/PresentableException.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/PresentableException.java
@@ -17,6 +17,8 @@
*/
package at.knowcenter.wag.egov.egiz.exceptions;
+import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
+
/**
* This exception should be the base for all exceptions that are to be presented
* to the user.
@@ -27,56 +29,32 @@ package at.knowcenter.wag.egov.egiz.exceptions;
* can present according texts.
* </p>
*
+ * @see PdfAsException
+ *
* @author wprinz
*/
-public class PresentableException extends Exception
+public class PresentableException extends PdfAsException
{
/**
* SVUID.
*/
private static final long serialVersionUID = -102406558526000792L;
-
- protected int errorCode = -1;
- /**
- * @param message
- */
- public PresentableException(int errorCode, String message)
+ public PresentableException(int errorCode, String message, Throwable cause)
{
- super(message);
-
- this.errorCode = errorCode;
+ super(errorCode, message, cause);
}
- /**
- * @param message
- * @param cause
- */
- public PresentableException(int errorCode, String message, Throwable cause)
+ public PresentableException(int errorCode, String message)
{
- super(message, cause);
-
- this.errorCode = errorCode;
+ super(errorCode, message);
}
- /**
- * @param cause
- */
public PresentableException(int errorCode, Throwable cause)
{
- super(cause);
-
- this.errorCode = errorCode;
+ super(errorCode, cause);
}
- /**
- * Returns the error code of this exception.
- * @return Returns the error code of this exception.
- */
- public int getErrorCode ()
- {
- return this.errorCode;
- }
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AbsoluteTextSignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AbsoluteTextSignature.java
index 4219475..4b9a2aa 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AbsoluteTextSignature.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/AbsoluteTextSignature.java
@@ -537,6 +537,14 @@ public class AbsoluteTextSignature
{
int block_start_index = ((FoundKey) block.found_keys.get(0)).getStartIndex();
int block_end_index = block.end_index;
+
+ if (block_start_index == 0 && block_end_index == text.length())
+ {
+ // the block is the whole text - the rest text is empty.
+ // This may happen if a (no-text) empty document contains a binary signature.
+ // Then the "signed text" of the binary signature is empty.
+ return "";
+ }
if (block_end_index == text.length())
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/ActualTablePos.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/ActualTablePos.java
new file mode 100644
index 0000000..f58e9f8
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/ActualTablePos.java
@@ -0,0 +1,22 @@
+/**
+ *
+ */
+package at.knowcenter.wag.egov.egiz.pdf;
+
+/**
+ * The actual table position where the signature was placed after signation.
+ * @author wprinz
+ */
+public class ActualTablePos
+{
+ public int page;
+
+ public float x;
+
+ public float y;
+
+ public float width;
+
+ public float height;
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
index 677990b..7a5af6b 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
@@ -737,6 +737,14 @@ public abstract class BinarySignature
// table_position, content);
content.addTemplate(table_template, pi.getX(), pi.getY() - pdf_table.getTotalHeight());
+
+ ActualTablePos atp = new ActualTablePos();
+ atp.page = pi.getPage();
+ atp.x = pi.getX();
+ atp.y = pi.getY(); // TODO is this correct or flipped?
+ atp.width = pdf_table.getTotalWidth();
+ atp.height = pdf_table.getTotalHeight();
+ iui.actualTablePos = atp;
// For debugging print a 100x100 grid
// {
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/IncrementalUpdateInformation.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/IncrementalUpdateInformation.java
index f818f59..77f1150 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/IncrementalUpdateInformation.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/IncrementalUpdateInformation.java
@@ -172,5 +172,10 @@ public class IncrementalUpdateInformation implements Serializable
* For signing: the profile.
*/
public String signProfile;
+
+ /**
+ * The actual position where the table was written.
+ */
+ public ActualTablePos actualTablePos;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureResponse.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureResponse.java
index 603e0fe..deedb6d 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureResponse.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureResponse.java
@@ -102,6 +102,8 @@ public class SignatureResponse
private boolean qualifiedCertificate = false;
// [tknall] stop qualified certificate
+ protected String hashInputData = null;
+
// /**
// * Flag the marks that the response is an error response
// */
@@ -423,6 +425,16 @@ public class SignatureResponse
this.certificate_ = certificate;
}
+ public String getHashInputData()
+ {
+ return this.hashInputData;
+ }
+
+ public void setHashInputData(String hashInputData)
+ {
+ this.hashInputData = hashInputData;
+ }
+
/**
* Returns a list of Strings each stating one public property of the
* certificate.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
index 19b28e7..13fdf2f 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureTypes.java
@@ -319,6 +319,16 @@ public class SignatureTypes
}
return instance_;
}
+
+ /**
+ * Reloads the instance.
+ * @throws SignatureTypesException
+ */
+ public static void createInstance() throws SignatureTypesException
+ {
+ instance_ = null;
+ getInstance();
+ }
/**
* This method load the signature definitions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java
index 5b16211..cbdee42 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java
@@ -6,6 +6,7 @@ package at.knowcenter.wag.egov.egiz.sig.connectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
@@ -46,7 +47,9 @@ public final class ConnectorChooser
}
log.debug("choosing locref detached BKU connector.");
- return new LocRefDetachedBKUConnector(profile, loc_ref_url);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new LocRefDetachedBKUConnector(cp, loc_ref_url);
}
public static Connector chooseWebConnectorForSign(String connector,
@@ -67,7 +70,9 @@ public final class ConnectorChooser
// Loc_Ref-Connector
// return new DetachedLocRefMOAConnector(profile, loc_ref_url);
// SwA-Connector
- return new MOASoapWithAttachmentConnector(profile);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new MOASoapWithAttachmentConnector(cp);
}
// public static Connector chooseCommandlineConnectorForSign(String connector,
@@ -147,7 +152,9 @@ public final class ConnectorChooser
{
log.debug("sig_kz version is 1.1.0 -> choosing detached (loc ref) connector.");
- return new LocRefDetachedBKUConnector(profile, loc_ref_url);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new LocRefDetachedBKUConnector(cp, loc_ref_url);
}
throw new ConnectorException(310, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown.");
@@ -183,7 +190,9 @@ public final class ConnectorChooser
// the following line is used in connection with LocRef-Connector
// return new DetachedLocRefMOAConnector(profile, loc_ref_url);
// the following line is uesed in connection with SwA-Connector
- return new MOASoapWithAttachmentConnector(profile);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new MOASoapWithAttachmentConnector(cp);
}
throw new ConnectorException(310, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown.");
@@ -293,7 +302,9 @@ public final class ConnectorChooser
{
log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$
- return new MultipartDetachedBKUConnector(profile);
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(profile);
+ return new MultipartDetachedBKUConnector(cp);
}
if (sig_app.equals(MOA))
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/TemplateReplaces.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/TemplateReplaces.java
index 18cf76d..149065c 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/TemplateReplaces.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/TemplateReplaces.java
@@ -117,6 +117,16 @@ public final class TemplateReplaces
* The placeholder text in the template to be replaced by the trust profile ID.
*/
public static final String TRUST_PROFILE_ID_REPLACE = "TrustProfileIDReplace"; //$NON-NLS-1$
+
+ /**
+ * The placeholder text in the template to be replaced by the return hash input data element.
+ */
+ public static final String RETURN_HASH_INPUT_DATA_REPLACE = "ReturnHashInputDataReplace"; //$NON-NLS-1$
+
+ /**
+ * The placeholder text in the template to be replaced by the dateTime element.
+ */
+ public static final String DATE_TIME_REPLACE = "DateTimeReplace"; // $NON-NLS-1$
/**
* The placeholder text in the template to be replaced by the Base64 content.
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 8f0b79e..1ddd327 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
@@ -7,12 +7,17 @@ import java.io.UnsupportedEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -421,12 +426,35 @@ public final class BKUHelper
Matcher cert_m_s = cert_p_s.matcher(xmlResponse);
Matcher cert_m_e = cert_p_e.matcher(xmlResponse);
+ Pattern hash_data_p_s = Pattern.compile("<HashInputData PartOf=\"SignedInfo\">"); //$NON-NLS-1$
+ Pattern hash_data_p_e = Pattern.compile("</HashInputData>"); //$NON-NLS-1$
+ Matcher hash_data_m_s = hash_data_p_s.matcher(xmlResponse);
+ Matcher hash_data_m_e = hash_data_p_e.matcher(xmlResponse);
+
+
SignatureResponse sig_res = new SignatureResponse();
// [tknall] start qualified certificate
sig_res.setQualifiedCertificate(cert_qualified_m.find());
// [tknall] stop qualified certificate
+ if (hash_data_m_s.find() && hash_data_m_e.find())
+ {
+ String hashInputData = xmlResponse.substring(hash_data_m_s.end(), hash_data_m_e.start());
+
+ Pattern b64_p_s = Pattern.compile("<Base64Content>"); //$NON-NLS-1$
+ Pattern b64_p_e = Pattern.compile("</Base64Content>"); //$NON-NLS-1$
+ Matcher b64_m_s = b64_p_s.matcher(hashInputData);
+ Matcher b64_m_e = b64_p_e.matcher(hashInputData);
+
+ b64_m_s.find();
+ b64_m_e.find();
+
+ String b64 = hashInputData.substring(b64_m_s.end(), b64_m_e.start());
+
+ sig_res.setHashInputData(b64);
+ }
+
if (sub_nam_m_s.find() && sub_nam_m_e.find())
{
String sub_nam = xmlResponse.substring(sub_nam_m_s.end(), sub_nam_m_e.start());
@@ -508,4 +536,27 @@ public final class BKUHelper
return sig_res;
}
+ public static String formDateTimeElement(Date verificationTime)
+ {
+ return formDateTimeElement(verificationTime, null);
+ }
+
+ public static String formDateTimeElement(Date verificationTime, String namespace)
+ {
+ String nsPrefix = StringUtils.isBlank(namespace) ? "" : (namespace + ":");
+
+ String dateTimeElement = "";
+ if (verificationTime != null)
+ {
+ log.debug("VerificationTime = " + verificationTime);
+
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String dateTime = df.format(verificationTime) + "Z";
+ log.debug("DateTime (VerificationTime in UTC) = " + dateTime);
+
+ dateTimeElement = "<" + nsPrefix + "DateTime>" + dateTime + "</" + nsPrefix + "DateTime>";
+ };
+ return dateTimeElement;
+ }
}
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 c84ce8a..f1896d7 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
@@ -11,6 +11,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+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;
@@ -43,6 +44,11 @@ public class DetachedBKUConnector implements Connector, LocalConnector
private static Log log = LogFactory.getLog(DetachedBKUConnector.class);
/**
+ * The connector parameters.
+ */
+ protected ConnectorParameters params = null;
+
+ /**
* The environemnt configuration of this connector containing templates and
* other configurable elements.
*/
@@ -57,14 +63,15 @@ public class DetachedBKUConnector implements Connector, LocalConnector
* parameters defined in the configuration are used.
* </p>
*
- * @param profile
- * The profile from which the Environment should be assembled.
+ * @param connectorParameters
+ * The connectot parameters.
* @throws ConnectorException
* f.e.
*/
- public DetachedBKUConnector(String profile, String loc_ref_content) throws ConnectorException
+ public DetachedBKUConnector(ConnectorParameters connectorParameters, String loc_ref_content) throws ConnectorException
{
- this.environment = new Environment(profile, loc_ref_content);
+ this.params = connectorParameters;
+ this.environment = new Environment(this.params.getProfileId(), loc_ref_content);
}
/**
@@ -119,6 +126,7 @@ public class DetachedBKUConnector implements Connector, LocalConnector
BKUHelper.checkResponseForError(response_string);
SignSignatureObject so = BKUHelper.parseCreateXMLResponse(response_string, new DetachedIdFormatter());
+ so.response_properties = response_properties;
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
return so;
@@ -309,6 +317,7 @@ public class DetachedBKUConnector implements Connector, LocalConnector
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());
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.DATE_TIME_REPLACE, BKUHelper.formDateTimeElement(this.params.getVerificationTime(), "sl"));
return verify_request_xml;
}
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
index 92b7b91..fc29457 100644
--- 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
@@ -3,6 +3,7 @@
*/
package at.knowcenter.wag.egov.egiz.sig.connectors.bku;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
/**
@@ -13,13 +14,13 @@ public class LocRefDetachedBKUConnector extends DetachedBKUConnector
{
/**
- * @param profile
+ * @param connectorParameters
* @param loc_ref_content
* @throws ConnectorException
*/
- public LocRefDetachedBKUConnector(String profile, String loc_ref_content) throws ConnectorException
+ public LocRefDetachedBKUConnector(ConnectorParameters connectorParameters, String loc_ref_content) throws ConnectorException
{
- super(profile, loc_ref_content);
+ super(connectorParameters, 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
index a2d4dc0..6f189af 100644
--- 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
@@ -3,6 +3,7 @@
*/
package at.knowcenter.wag.egov.egiz.sig.connectors.bku;
+import at.gv.egiz.pdfas.framework.ConnectorParameters;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
/**
@@ -13,9 +14,9 @@ public class MultipartDetachedBKUConnector extends DetachedBKUConnector
{
protected static final String MULTIPART_LOC_REF_CONTENT = "formdata:fileupload"; //$NON-NLS-1$
- public MultipartDetachedBKUConnector(String profile) throws ConnectorException
+ public MultipartDetachedBKUConnector(ConnectorParameters connectorParameters) throws ConnectorException
{
- super(profile, MULTIPART_LOC_REF_CONTENT);
+ super(connectorParameters, 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 3bf0719..b31d1ec 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
@@ -10,6 +10,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+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;
@@ -173,7 +174,9 @@ public class DetachedLocRefMOAConnector implements Connector
String xml_content = null;
if (!SigKZIDHelper.isMOASigned(so))
{
- DetachedBKUConnector bku_connector = new DetachedBKUConnector(this.environment.getProfile(), "not needed here");
+ ConnectorParameters cp = new ConnectorParameters();
+ cp.setProfileId(this.environment.getProfile());
+ DetachedBKUConnector bku_connector = new DetachedBKUConnector(cp, "not needed here");
xml_content = bku_connector.prepareXMLContent(data, so);
}
else
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 34bcdc6..4cb4ec2 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,12 +4,19 @@
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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+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;
@@ -25,7 +32,6 @@ 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.sig.sigkz.SigKZIDHelper;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
-import at.knowcenter.wag.egov.egiz.tools.DebugHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
/**
@@ -46,12 +52,20 @@ public class MOASoapWithAttachmentConnector implements Connector
protected static final String MULTIPART_LOC_REF_CONTENT = "formdata:fileupload"; //$NON-NLS-1$
+ protected static final String RETURN_HASH_INPUT_DATA = "<ReturnHashInputData/>"; //$NON-NLS-1$
+
+ /**
+ * The connector parameters.
+ */
+ protected ConnectorParameters params = null;
+
/**
* The environemnt configuration of this connector containing templates and
* other configurable elements.
*/
protected Environment environment = null;
-
+
+
/**
* Constructor that builds the configuration environment for this connector
* according to the given profile.
@@ -61,17 +75,15 @@ public class MOASoapWithAttachmentConnector implements Connector
* parameters defined in the configuration are used.
* </p>
*
- * @param profile
- * The profile from which the Environment should be assembled.
- * @throws SettingsException
- * f.e.
- * @throws SignatureException
+ * @param connectorParameters
+ * The parameters for this connector.
+ * @throws ConnectorException
* f.e.
*/
- public MOASoapWithAttachmentConnector(String profile) throws ConnectorException
+ public MOASoapWithAttachmentConnector(ConnectorParameters connectorParameters) throws ConnectorException
{
-
- this.environment = new Environment(profile, MULTIPART_LOC_REF_CONTENT);
+ this.params = connectorParameters;
+ this.environment = new Environment(this.params.getProfileId(), MULTIPART_LOC_REF_CONTENT);
}
protected String prepareSignRequest(SignatureData data) throws ConnectorException
@@ -176,7 +188,7 @@ public class MOASoapWithAttachmentConnector implements Connector
String xml_content = null;
if (!SigKZIDHelper.isMOASigned(so))
{
- DetachedBKUConnector bku_connector = new DetachedBKUConnector(this.environment.getProfile(), "not needed here");
+ DetachedBKUConnector bku_connector = new DetachedBKUConnector(this.params, "not needed here");
xml_content = bku_connector.prepareXMLContent(data, so);
}
else
@@ -187,12 +199,22 @@ public class MOASoapWithAttachmentConnector implements Connector
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());
verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.LOC_REF_CONTENT_REPLACE, this.environment.getSignatureDataUrl());
+
+ String returnHashInputDataElement = "";
+ if (this.params.isReturnHashInputData())
+ {
+ returnHashInputDataElement = RETURN_HASH_INPUT_DATA;
+ }
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.RETURN_HASH_INPUT_DATA_REPLACE, returnHashInputDataElement);
+
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.DATE_TIME_REPLACE, BKUHelper.formDateTimeElement(this.params.getVerificationTime()));
+
log.debug("\r\n\r\n" + verify_request_xml + "\r\n\r\n");
return verify_request_xml;
}
-
+
/**
* Analyzes the verify response string.
*
@@ -297,20 +319,20 @@ public class MOASoapWithAttachmentConnector implements Connector
try
{
// for performance measurement
- long startTime = 0;
- if (log.isInfoEnabled()) {
- startTime = System.currentTimeMillis();
- }
+// long startTime = 0;
+// if (log.isInfoEnabled()) {
+// startTime = System.currentTimeMillis();
+// }
// Properties response_properties = MOASoapConnection.connectMOA(request_string, MOASoapConnection.SERVICE_SIGN, url);
Properties response_properties = MOASoapConnection.doPostRequestMultipart(url,mode, request_string, data );
// for performance measurement
- if (log.isInfoEnabled()) {
- long endTime = System.currentTimeMillis();
- String toReport = "MOA-PROCESSING;-;-;" + (endTime - startTime) + ";";
- log.info(toReport);
- }
+// if (log.isInfoEnabled()) {
+// long endTime = System.currentTimeMillis();
+// String toReport = "MOA-PROCESSING;-;-;" + (endTime - startTime) + ";";
+// log.info(toReport);
+// }
return response_properties;
}
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 ed4fc7a..01e60fa 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
@@ -188,8 +188,23 @@ public class DataURLServlet extends HttpServlet
si.outputAvailable = true;
}
- SignServletHelper.returnSignResponse(si, response);
-
+ if (si.output.getMimeType().equals("text/xml") && si.outputAvailable)
+ {
+ // For "detached" signatures, the return value (data sink) is the response xml,
+ // but when passed through the BKU it is interpreted as another request
+ // which will generate a return code 1501
+ // Then PDF-AS would answer with the response as well generating
+ // another 1501 and so forth.
+ // Therefor return it as TXT.
+ response.setContentType("text/plain");
+ response.setCharacterEncoding("UTF-8");
+ response.getWriter().println("Das detached XML kann nicht direkt durch die BKU geschliffen werden, weil diese es als Request interpretieren würde. Daher das XML als Text:");
+ response.getWriter().println(si.si.getSignSignatureObject().response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY));
+ }
+ else
+ {
+ SignServletHelper.returnSignResponse(si, response);
+ }
}
}