/** * */ package at.knowcenter.wag.egov.egiz.sig.connectors.bku; import java.io.UnsupportedEncodingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.tools.CodingHelper; import at.knowcenter.wag.egov.egiz.tools.FileHelper; /** * *

* This is the old base64 connector. The difference is in the way the sign * response is parsed and the verify content_xml. *

* * @author wprinz * */ public class OldEnvelopingBase64BKUConnector extends EnvelopedBase64BKUConnector { /** * The log. */ private static Log log = LogFactory.getLog(OldEnvelopingBase64BKUConnector.class); // TODO implement signing - with old pre 2.7.2 BKUs... not really necessary // though because this connector is only used for verification public OldEnvelopingBase64BKUConnector(String profile) throws ConnectorException { super(profile); this.environment = new OverriddenEnvironment(profile); } /** * @see at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector#computeSignedPropertiesReplace(java.lang.String) */ protected String computeSignedPropertiesReplace(String verify_xml) { try { final String ETSI_QUALIFYING_PROPERTIES_START_TAG = "= 0; final int hash_end = verify_xml.indexOf(ETSI_QUALIFYING_PROPERTIES_END_TAG, hash_start) + ETSI_QUALIFYING_PROPERTIES_END_TAG.length(); assert hash_end - ETSI_QUALIFYING_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:QualifyingProperties 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); } } public static class OverriddenEnvironment extends EnvelopedBase64BKUConnector.Environment { /** * The configuration key of the verify template. */ protected static final String VERIFY_TEMPLATE_KEY = "bku.verify.template.base64old"; //$NON-NLS-1$ public OverriddenEnvironment(String profile) throws ConnectorException { super(profile); SettingsReader settings = null; try { settings = SettingsReader.getInstance(); } catch (SettingsException e) { throw new ConnectorException(300, e); } String verify_filename = getConnectorValueFromProfile(settings, profile, VERIFY_TEMPLATE_KEY); this.verify_template = FileHelper.readFromFile(SettingsReader.relocateFile(verify_filename)); if (this.verify_template == null) { // TODO make this a settings exception throw new ConnectorException(300, "Can not read the verify template"); //$NON-NLS-1$ } } } }