aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java
diff options
context:
space:
mode:
authorknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-18 15:42:55 +0000
committerknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-18 15:42:55 +0000
commit8f2a983cb8e9be9e71e3df04edd00a4bc0673862 (patch)
tree141e477bd1086e21f80dba750b6f93036827c280 /src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java
parentdce5ed9e0a30ed7f03b21a8142029847a1194a2c (diff)
downloadpdf-as-3-8f2a983cb8e9be9e71e3df04edd00a4bc0673862.tar.gz
pdf-as-3-8f2a983cb8e9be9e71e3df04edd00a4bc0673862.tar.bz2
pdf-as-3-8f2a983cb8e9be9e71e3df04edd00a4bc0673862.zip
detached connectors
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@92 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/EnvelopedBase64BKUConnector.java93
1 files changed, 59 insertions, 34 deletions
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 1c628b1..3d5cf36 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
@@ -3,6 +3,7 @@
*/
package at.knowcenter.wag.egov.egiz.sig.connectors.bku;
+import java.io.UnsupportedEncodingException;
import java.security.cert.X509Certificate;
import java.util.Properties;
@@ -16,8 +17,11 @@ 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.connectors.moa.EnvelopingBase64MOAConnector;
import at.knowcenter.wag.egov.egiz.sig.sigid.HotfixIdFormatter;
+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;
@@ -26,7 +30,7 @@ import at.knowcenter.wag.egov.egiz.tools.FileHelper;
* @author wprinz
*
*/
-public class EnvelopedBase64BKUConnector implements Connector
+public class EnvelopedBase64BKUConnector implements Connector, LocalConnector
{
/**
@@ -49,6 +53,10 @@ public class EnvelopedBase64BKUConnector implements Connector
* parameters defined in the configuration are used.
* </p>
*
+ * <p>
+ * This is the new "hotfix" base64 connector.
+ * </p>
+ *
* @param profile
* The profile from which the Environment should be assembled.
* @throws ConnectorException
@@ -131,7 +139,6 @@ public class EnvelopedBase64BKUConnector implements Connector
}
return id;
}
-
/**
* Prepares the XML content the holds the actual signature data.
@@ -169,7 +176,7 @@ 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 = BKUHelper.prepareEnvelopingData(data);
{
byte[] data_value_hash = CodingHelper.buildDigest(data_value);
String object_data_hash = CodingHelper.encodeBase64(data_value_hash);
@@ -206,21 +213,7 @@ public class EnvelopedBase64BKUConnector implements Connector
// Signed Properties hash
{
- final String ETSI_SIGNED_PROPERTIES_START_TAG = "<etsi:SignedProperties"; //$NON-NLS-1$
- final String ETSI_SIGNED_PROPERTIES_END_TAG = "</etsi:SignedProperties>"; //$NON-NLS-1$
-
- final int hash_start = verify_xml.indexOf(ETSI_SIGNED_PROPERTIES_START_TAG);
- assert hash_start >= 0;
- final int hash_end = verify_xml.indexOf(ETSI_SIGNED_PROPERTIES_END_TAG, hash_start) + ETSI_SIGNED_PROPERTIES_END_TAG.length();
- assert hash_end - ETSI_SIGNED_PROPERTIES_END_TAG.length() >= 0;
- assert hash_end > hash_start;
-
- final String string_to_be_hashed = verify_xml.substring(hash_start, hash_end);
- log.debug("etsi:SignedProperties string to be hashed: " + string_to_be_hashed); //$NON-NLS-1$
-
- final byte[] bytes_to_be_hashed = string_to_be_hashed.getBytes("UTF-8"); //$NON-NLS-1$
- byte[] sig_prop_code = CodingHelper.buildDigest(bytes_to_be_hashed);
- String sig_prop_hash = CodingHelper.encodeBase64(sig_prop_code);
+ String sig_prop_hash = computeSignedPropertiesReplace(verify_xml);
verify_xml = verify_xml.replaceFirst(TemplateReplaces.DIGEST_VALUE_SIGNED_PROPERTIES_REPLACE, sig_prop_hash);
}
@@ -235,6 +228,34 @@ public class EnvelopedBase64BKUConnector implements Connector
}
}
+ protected String computeSignedPropertiesReplace(String verify_xml)
+ {
+ try
+ {
+ final String ETSI_SIGNED_PROPERTIES_START_TAG = "<etsi:SignedProperties"; //$NON-NLS-1$
+ final String ETSI_SIGNED_PROPERTIES_END_TAG = "</etsi:SignedProperties>"; //$NON-NLS-1$
+
+ final int hash_start = verify_xml.indexOf(ETSI_SIGNED_PROPERTIES_START_TAG);
+ assert hash_start >= 0;
+ final int hash_end = verify_xml.indexOf(ETSI_SIGNED_PROPERTIES_END_TAG, hash_start) + ETSI_SIGNED_PROPERTIES_END_TAG.length();
+ assert hash_end - ETSI_SIGNED_PROPERTIES_END_TAG.length() >= 0;
+ assert hash_end > hash_start;
+
+ final String string_to_be_hashed = verify_xml.substring(hash_start, hash_end);
+ log.debug("etsi:SignedProperties string to be hashed: " + string_to_be_hashed); //$NON-NLS-1$
+
+ final byte[] bytes_to_be_hashed = string_to_be_hashed.getBytes("UTF-8"); //$NON-NLS-1$
+ byte[] sig_prop_code = CodingHelper.buildDigest(bytes_to_be_hashed);
+ String sig_prop_hash = CodingHelper.encodeBase64(sig_prop_code);
+
+ return sig_prop_hash;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException("Very Strange: UTF-8 character encoding not supported.", e);
+ }
+ }
+
/**
* Prepares the sign request xml to be sent using the sign request template.
*
@@ -272,32 +293,27 @@ public class EnvelopedBase64BKUConnector implements Connector
* @throws ConnectorException
* f.e.
*/
- public String prepareVerifyRequest(SignatureData data,
- SignSignatureObject so) throws ConnectorException
+ public String prepareVerifyRequest(SignatureData data, SignSignatureObject so) throws ConnectorException
{
String verify_request_template = this.environment.getVerifyRequestTemplate();
String xml_content = null;
- // TODO implement MOA
- // 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);
- // }
+ if (SigKZIDHelper.isMOASigned(so))
+ {
+ log.debug("The signature is MOA signed -> getting XML content from Base64MOA connector.");
+ EnvelopingBase64MOAConnector moa_conn = new EnvelopingBase64MOAConnector(this.environment.getProfile());
+ xml_content = moa_conn.prepareXMLContent(data, so);
+ }
+ else
+ {
+ xml_content = prepareXMLContent(data, so);
+ }
String verify_request_xml = verify_request_template.replaceFirst(TemplateReplaces.XML_CONTENT_REPLACE, xml_content);
return verify_request_xml;
}
-
/**
* Sends the request to the given URL.
*
@@ -416,6 +432,8 @@ public class EnvelopedBase64BKUConnector implements Connector
*/
protected static final String RSA_CERT_ALG_KEY = "cert.alg.rsa"; //$NON-NLS-1$
+ protected String profile = null;
+
protected String sign_keybox_identifier = null;
protected String sign_request_template = null;
@@ -442,6 +460,8 @@ public class EnvelopedBase64BKUConnector implements Connector
*/
public Environment(String profile) throws ConnectorException
{
+ this.profile = profile;
+
SettingsReader settings = null;
try
{
@@ -487,6 +507,11 @@ public class EnvelopedBase64BKUConnector implements Connector
}
+ public String getProfile()
+ {
+ return this.profile;
+ }
+
/**
* Returns the sign keybox identifier.
*