From f9a64d885db5339164a34c4f365e2ee0cf082a05 Mon Sep 17 00:00:00 2001 From: knowcenter Date: Tue, 24 Jul 2007 13:05:39 +0000 Subject: Template Versioning, BKU and MOA 1.1.0 (detached) NOTE: MOA enveloping is still not fixed git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@149 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/sig/ConnectorFactory.java | 38 +++------- .../wag/egov/egiz/sig/SignatureObject.java | 9 --- .../egov/egiz/sig/connectors/ConnectorChooser.java | 86 +++++++++------------- .../sig/connectors/bku/DetachedBKUConnector.java | 24 +++--- .../bku/EnvelopedBase64BKUConnector.java | 4 + .../connectors/moa/DetachedLocRefMOAConnector.java | 8 +- .../egov/egiz/sig/sigid/DetachedIdFormatter.java | 33 +++------ .../sig/sigid/DetachedLocRefMOAIdFormatter.java | 34 ++++----- .../wag/egov/egiz/sig/sigid/OldMOAIdFormatter.java | 25 +------ .../wag/egov/egiz/sig/sigkz/SigKZIDHelper.java | 14 ++-- 10 files changed, 104 insertions(+), 171 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/sig') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java index 236f260..8d9a480 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java @@ -49,8 +49,6 @@ public abstract class ConnectorFactory *

*/ protected static final String CONNECTOR_INFORMATION_FIELD_NAME = "CONNECTOR_INFORMATION"; - - protected static final String MOA_SIG_ID_VISIBLE_KEY = "moa.sign.id.active"; /** * The list of available Connector implementations. @@ -322,30 +320,18 @@ public abstract class ConnectorFactory */ public static boolean needsSIG_ID(String connector) { - //boolean return_result = true; - - if(connector.contains("moa")) - { - String moa_sig_id_visible = null; - - try - { - moa_sig_id_visible = SettingsReader.getInstance().getValueFromKey(MOA_SIG_ID_VISIBLE_KEY); - - if(moa_sig_id_visible == null) - return false; - - if(!moa_sig_id_visible.equals("true")) - return false; - } - catch (SettingsException e) - { - String log_message = "Can not load signature settings. Cause:\n" + e.getMessage(); - logger_.error(log_message); - throw new RuntimeException(e); - } + // all modernn detached signatures have the SIG_ID field. + + try { + if(!SettingsReader.getInstance().getValueFromKey("moa.id.field.visible").equals("true")) + return false; + } catch (SettingsException e) { + e.printStackTrace(); } - - return true;//return_result; + + + return true; + //return !connector.equals("moa"); } + } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java index a9fad94..62944e4 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java @@ -1606,15 +1606,6 @@ public class SignatureObject implements Serializable setValueBruteForce(SignatureTypes.SIG_ID, null); continue; } -// else -// { -// try { -// setValueBruteForce(SignatureTypes.SIG_ID, -// SettingsReader.getInstance().getValueFromKey("default.moa.signature.id")); -// } catch (SettingsException e) { -// e.printStackTrace(); -// } -// } char[] placeholder_chars = new char[sfd.placeholder_length]; for (int i = 0; i < placeholder_chars.length; i++) 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 32dcb72..38680c4 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 @@ -9,7 +9,6 @@ import org.apache.commons.logging.LogFactory; import at.knowcenter.wag.egov.egiz.PdfASID; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; -import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.framework.SignatorFactory; import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector; @@ -31,19 +30,17 @@ public final class ConnectorChooser /** * The log. */ - private static Log log = LogFactory.getLog(ConnectorChooser.class); - private static final String MOA_CMD_LINE_SUPPORTED_KEY = "moa.sign.cmd.detached"; + private static Log log = LogFactory.getLog(ConnectorChooser.class); + + private static final String MOA_DETACHED_ENABLED_KEY = "moa.sign.console.detached.enabled"; - /* - * Called when we try to connect BKU over Web interface - */ public static LocalConnector chooseLocalConnectorForSign(String connector, String profile, String loc_ref_url) throws ConnectorException { log.debug("Choosing LocalConnector for signation..."); log.debug("connector type = " + connector); - + if (!connector.equals("bku")) { log.error("Currently only the BKU connector is fully implemented."); @@ -70,43 +67,37 @@ public final class ConnectorChooser } public static Connector chooseCommandlineConnectorForSign(String connector, - String profile) throws ConnectorException, SettingNotFoundException + String profile) throws ConnectorException { log.debug("Choosing Connector for commandline signation..."); log.debug("connector type = " + connector); if (connector.equals(BKU)) - { - log.debug("sig_app is BKU ==> MultipartDetachedBKUConnector"); //$NON-NLS-1 - + { + log.debug("sig_app is BKU ==> MultipartDetachedBKUConnector"); //$NON-NLS-1$ + return new MultipartDetachedBKUConnector(profile); } - if (connector.equals(MOA)) - { - try { - String cmd_supported = SettingsReader.getInstance().getValueFromKey(MOA_CMD_LINE_SUPPORTED_KEY); - - if(cmd_supported.equals("true")) - { - //TODO: replace hardcoded constants!!! - return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); - } - else - { - // TODO MOA detached signing is not allowed at the commandline - log.warn("Detached MOA is not supported on the commandline. -> choosing Base64 temporarily."); - - return new EnvelopingBase64MOAConnector(profile); - } - - } catch (SettingsException e) { + { + // is detached mode enabled from console + String detached_mode_enabled = null; + + try + { + detached_mode_enabled = SettingsReader.getInstance().getValueFromKey(MOA_DETACHED_ENABLED_KEY); + } catch (SettingsException e) + { e.printStackTrace(); - } - //if() - //return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); - //return new EnvelopingBase64MOAConnector(profile); + } + + // currently MOA does'nt support detached mode in command line + if(detached_mode_enabled == null || detached_mode_enabled.equals("true")) + return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); + + log.warn("Detached MOA is not supported on the commandline. -> choosing Base64 temporarily."); + return new EnvelopingBase64MOAConnector(profile); } throw new ConnectorException(300, "Unknown connector type '" + connector + "' specified."); @@ -232,6 +223,13 @@ public final class ConnectorChooser return chooseEnvelopedBase64ConnectorHotfix(profile, connector); } + // test + if (sig_id.equals("")) + { + log.debug("sig_id is null, which means that it is a MOA signature -> choose a hotfix base64 connector (thus it is moa - it doesn't matter)."); + + return chooseEnvelopedBase64ConnectorHotfix(profile, connector); + } String[] sig_id_parts = sig_id.split("@"); if (sig_id_parts.length == 2) @@ -249,7 +247,6 @@ public final class ConnectorChooser throw new ConnectorException(300, "The SIG_KZ version is 1.0.0, but SIG_ID is neither MOA nor Old base64 nor Hotfix base64 ???'"); } - if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_1_0)) { log.debug("Version is 1.1.0 -> chose a detached connector."); @@ -315,22 +312,9 @@ public final class ConnectorChooser { log.debug("sig_app is MOA ==> DetachedMOAConnector"); //$NON-NLS-1$ - try - { - if(SettingsReader.getInstance().getValueFromKey(MOA_CMD_LINE_SUPPORTED_KEY).equals("false")) - { - String msg = "A Detached signature cannot be verified with the MOA connector (yet)."; //$NON-NLS-1$ - log.error(msg); - throw new ConnectorException(370, msg); - } else - { - // TODO: replace hardcoded constants - return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); - } - } catch (SettingsException e) - { - e.printStackTrace(); - } + String msg = "A Detached signature cannot be verified with the MOA connector (yet)."; //$NON-NLS-1$ + log.error(msg); + throw new ConnectorException(370, msg); } throw new ConnectorException(310, "Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } 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 a48b04c..9713a4a 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 @@ -295,16 +295,16 @@ public class DetachedBKUConnector implements Connector, LocalConnector String verify_request_template = this.environment.getVerifyRequestTemplate(); String xml_content = null; -// if (SigKZIDHelper.isMOASigned(so)) -// { -// log.debug("The signature is MOA signed -> getting XML content from DetachedLocRefMOA connector."); -// DetachedLocRefMOAConnector moa_conn = new DetachedLocRefMOAConnector(this.environment.getProfile(), "loc ref not needed here"); -// xml_content = moa_conn.prepareXMLContent(data, so); -// } -// else -// { + if (SigKZIDHelper.isMOASigned(so)) + { + log.debug("The signature is MOA signed -> getting XML content from DetachedLocRefMOA connector."); + DetachedLocRefMOAConnector moa_conn = new DetachedLocRefMOAConnector(this.environment.getProfile(), "loc ref not needed here"); + 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); verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.LOC_REF_CONTENT_REPLACE, this.environment.getLocRefContent()); @@ -450,7 +450,7 @@ public class DetachedBKUConnector implements Connector, LocalConnector /** * The configuration key of the sign request template. */ - protected static final String SIGN_REQUEST_TEMPLATE_KEY = "bku.sign.request.template"; //$NON-NLS-1$ + protected static final String SIGN_REQUEST_TEMPLATE_KEY = "bku.sign.request.detached"; //$NON-NLS-1$ /** * The configuration key of the sign URL. @@ -460,12 +460,12 @@ public class DetachedBKUConnector implements Connector, LocalConnector /** * The configuration key of the verify request template. */ - protected static final String VERIFY_REQUEST_TEMPLATE_KEY = "bku.verify.request.template"; //$NON-NLS-1$ + protected static final String VERIFY_REQUEST_TEMPLATE_KEY = "bku.verify.request.detached"; //$NON-NLS-1$ /** * The configuration key of the verify template. */ - protected static final String VERIFY_TEMPLATE_KEY = "bku.verify.request.template.keys"; //$NON-NLS-1$ + protected static final String VERIFY_TEMPLATE_KEY = "bku.verify.template.detached"; //$NON-NLS-1$ /** * The configuration key of the verify URL. 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 4983da7..dc5d35b 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 @@ -300,6 +300,10 @@ public class EnvelopedBase64BKUConnector implements Connector, LocalConnector String xml_content = null; if (SigKZIDHelper.isMOASigned(so)) { + // + if(so.id.equals("") || so.id == null) + so.id = "temp"; + // 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); 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 eeb242f..98d381a 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 @@ -37,7 +37,7 @@ public class DetachedLocRefMOAConnector implements Connector /** * The SIG_ID prefix. */ - //public static final String SIG_ID_PREFIX = "etsi-bku-detached@"; //$NON-NLS-1$ + public static final String SIG_ID_PREFIX = "etsi-bku-detached@"; //$NON-NLS-1$ /** * The log. @@ -316,7 +316,7 @@ public class DetachedLocRefMOAConnector implements Connector /** * The configuration key of the sign request template. */ - protected static final String SIGN_REQUEST_TEMPLATE_KEY = "moa.sign.request.template"; //$NON-NLS-1$ + protected static final String SIGN_REQUEST_TEMPLATE_KEY = "moa.sign.request.detached"; //$NON-NLS-1$ /** * The configuration key of the sign URL. @@ -326,12 +326,12 @@ public class DetachedLocRefMOAConnector implements Connector /** * The configuration key of the verify request template. */ - protected static final String VERIFY_REQUEST_TEMPLATE_KEY = "moa.verify.request.template"; //$NON-NLS-1$ + protected static final String VERIFY_REQUEST_TEMPLATE_KEY = "moa.verify.request.detached"; //$NON-NLS-1$ /** * The configuration key of the verify template. */ - protected static final String VERIFY_TEMPLATE_KEY = "moa.verify.request.template.keys"; //$NON-NLS-1$ + protected static final String VERIFY_TEMPLATE_KEY = "moa.verify.template.detached"; //$NON-NLS-1$ /** * The configuration key of the verify URL. diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java index f951b47..7220857 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java @@ -15,12 +15,13 @@ import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; */ public class DetachedIdFormatter implements IdFormatter { - // last change: erno & arian; 16.07.2007 13:17 - public static final String DEFAULT_BKU_SIG_ID = "default.bku.signature.id"; /** * The SIG_ID prefix. + * Default value: etsi-bka-1.0 */ - public static String SIG_ID_PREFIX = null; + public static String SIG_ID_PREFIX = "etsi-bka-1.0"; //$NON-NLS-1$ + + public static final String SIG_ID_KEY = "default.bku.algorithm.id"; /** * The log. @@ -32,10 +33,13 @@ public class DetachedIdFormatter implements IdFormatter */ public String formatIds(String[] ids) { - // if SIG_ID_PREFIX null is, call read the config file and set the value from it - if(SIG_ID_PREFIX == null) - setPrefixId(); - + // read SIG_ID_PREFIX from config file + try { + SIG_ID_PREFIX = SettingsReader.getInstance().getValueFromKey(SIG_ID_KEY); + } catch (SettingsException e) { + e.printStackTrace(); + } + // ids algorithm: String join = ""; //$NON-NLS-1$ String base = null; @@ -63,18 +67,5 @@ public class DetachedIdFormatter implements IdFormatter String final_ids = SIG_ID_PREFIX + "@" + idstr; return final_ids; } - - /* - * Read configuration from file and set it to global variable - */ - public void setPrefixId() - { - try - { - SIG_ID_PREFIX = SettingsReader.getInstance().getValueFromKey(DEFAULT_BKU_SIG_ID); - } catch (SettingsException e) - { - e.printStackTrace(); - } - } + } 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 index c1d831e..ec6d054 100644 --- 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 @@ -5,7 +5,6 @@ package at.knowcenter.wag.egov.egiz.sig.sigid; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; -import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; /** * @author wprinz @@ -13,31 +12,28 @@ import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; */ public class DetachedLocRefMOAIdFormatter implements IdFormatter { - public static final String MOA_SIG_ID_KEY = "default.moa.signature.id"; + /** + * The SIG_ID prefix. + * Default value: etsi-bka-moa-1.0 + */ + public static String SIG_ID_PREFIX = "etsi-bka-moa-1.0"; //$NON-NLS-1$ + public static String SIG_ID_KEY = "default.moa.algorithm.id"; /** * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[]) */ public String formatIds(String[] ids) { - String sig_id_prefix = null; + String tmp = null; - try - { - //FIXME make better - //connector is hard coded since this method is called only when using MOA! - boolean sig_id_visible = ConnectorFactory.needsSIG_ID("moa"); - - if (sig_id_visible) - { - sig_id_prefix = SettingsReader.getInstance().getValueFromKey(MOA_SIG_ID_KEY); - } - } catch (SettingsException e) - { - e.printStackTrace(); - } + try { + tmp = SettingsReader.getInstance().getValueFromKey(SIG_ID_KEY); + if(tmp != null) + SIG_ID_PREFIX = tmp; + } catch (SettingsException e) { + e.printStackTrace(); + } - return sig_id_prefix; + 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 index d4bd166..05f5db8 100644 --- 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 @@ -3,10 +3,6 @@ */ package at.knowcenter.wag.egov.egiz.sig.sigid; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; -import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; - /** * @author wprinz * @@ -14,31 +10,12 @@ import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory; public class OldMOAIdFormatter implements IdFormatter { - public static final String MOA_SIG_ID_KEY = "default.moa.signature.id"; - /** * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[]) */ public String formatIds(String[] ids) { - String sig_id_prefix = null; - - try - { - // FIXME make better - //connector is hard coded since this method is called only when using MOA! - boolean sig_id_visible = ConnectorFactory.needsSIG_ID("moa"); - - if (sig_id_visible) - { - sig_id_prefix = SettingsReader.getInstance().getValueFromKey(MOA_SIG_ID_KEY); - } - } catch (SettingsException e) - { - e.printStackTrace(); - } - - return sig_id_prefix; + return null; } } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigkz/SigKZIDHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigkz/SigKZIDHelper.java index 8a831bd..e751248 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigkz/SigKZIDHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigkz/SigKZIDHelper.java @@ -4,7 +4,6 @@ package at.knowcenter.wag.egov.egiz.sig.sigkz; import at.knowcenter.wag.egov.egiz.PdfASID; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException; import at.knowcenter.wag.egov.egiz.framework.SignatorFactory; @@ -47,17 +46,22 @@ public final class SigKZIDHelper return sig_id == null; } - // new signatures may or may not have the SIG_ID value + // :begin + if(sig_id == null) return true; + if(sig_id.equals("")) + return true; + + // :end + // new signature - sig_id decides String [] ids = sig_id.split("@"); String prefix = ids[0]; - DetachedLocRefMOAIdFormatter moa_id_formater = new DetachedLocRefMOAIdFormatter(); - - if (prefix.equals(moa_id_formater.formatIds(null))) + if (prefix.equals(DetachedLocRefMOAIdFormatter.SIG_ID_PREFIX)) + //if(!prefix.equals("")) { return true; } -- cgit v1.2.3