/** * Copyright 2006 by Know-Center, Graz, Austria * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a * joint initiative of the Federal Chancellery Austria and Graz University of * Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ 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.gv.egiz.pdfas.algorithmSuite.AlgorithmSuiteObject; import at.gv.egiz.pdfas.exceptions.ErrorCode; 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, AlgorithmSuiteObject algSuite) { 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, algSuite.getPropertiesDigestMethod()); 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(ErrorCode.SETTING_NOT_FOUND, e); } String verify_filename = getConnectorValueFromProfile(settings, profile, VERIFY_TEMPLATE_KEY); //this.verify_template = FileHelper.readFromFile(SettingsReader.relocateFile(verify_filename)); this.verify_template = settings.readInternalResourceAsString(verify_filename); if (this.verify_template == null) { throw new ConnectorException(ErrorCode.SETTING_NOT_FOUND, "Can not read the verify template"); //$NON-NLS-1$ } } } }