From db52e4d66d60184d53a27ba4d6772461daacc03d Mon Sep 17 00:00:00 2001 From: tknall Date: Fri, 22 Mar 2013 08:57:51 +0000 Subject: Maintenance update (bugfixes, new features, cleanup...) Refer to /dok/RELEASE_NOTES-3.3.txt for further information. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/pdf-as/trunk@931 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/sig/SignatureObject.java | 171 ++++++++++----------- 1 file changed, 85 insertions(+), 86 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java') diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java index 9e28213..b5a05ed 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/sig/SignatureObject.java @@ -77,7 +77,7 @@ import at.knowcenter.wag.egov.egiz.tools.Normalizer; * All values that build or used by the signation creation process, call the * external services, can read or set separately. All other values are defined * in the settings file. - * + * * @author wlackner * @author modified by Thomas Knall */ @@ -138,7 +138,7 @@ public class SignatureObject implements Serializable public static final String SIG_CER_DIG = "SIG_CER_DIG"; private X509Cert x509Cert_ = null; - + private String timeStamp = null; // public static final String SIG_RES = "SIG_RES"; @@ -194,7 +194,7 @@ public class SignatureObject implements Serializable /** * The raw xml response from the connector that was used to set the values in * this SignatureObject. - * + * *

* This is set by the Connector so that signing Applications can use the * returned XML values. @@ -222,7 +222,7 @@ public class SignatureObject implements Serializable /** * The empty constructor. It initilize the normlizer, load the settings and * set the default styles. - * + * * @throws SignatureException * ErrorCode:101, 400 */ @@ -235,7 +235,7 @@ public class SignatureObject implements Serializable /** * This method initialize the normalizer - * + * * @throws SignatureException * ErrorCode:400 */ @@ -254,7 +254,7 @@ public class SignatureObject implements Serializable /** * This method load the signature definitions - * + * * @throws SignatureException * ErrorCode:101 */ @@ -296,7 +296,7 @@ public class SignatureObject implements Serializable /** * Dummy getter Method for debugging only - * + * * @return response string */ public String getSigResponse() @@ -306,7 +306,7 @@ public class SignatureObject implements Serializable /** * Dummy setter Method for debugging only - * + * * @param sigRespone * store the response string */ @@ -317,7 +317,7 @@ public class SignatureObject implements Serializable /** * This method set the signature type. - * + * * @param sigType * the signature type to be set * @throws SignatureTypesException @@ -331,7 +331,7 @@ public class SignatureObject implements Serializable /** * Returns the default signation type - * + * * @return the key for the default signature definition, if the key is not * found it returns null */ @@ -343,7 +343,7 @@ public class SignatureObject implements Serializable /** * This method checks if a given signature key is realy a defined signature * key. - * + * * @param sigKey * the key to check * @return true if the key is correct, false if the given key is not defined @@ -360,7 +360,7 @@ public class SignatureObject implements Serializable * The value that has to be set would be normalized!
* If the key equals to SIG_VALUE all whitespaces are * removed!
- * + * * @param key * the key to be set * @param value @@ -371,7 +371,7 @@ public class SignatureObject implements Serializable public boolean setSigValue(String key, String value) { return setSigValue(key, value, false); } - + public boolean setSigValue(String key, String value, boolean placeholder) { SignatureEntry sig_entry = null; @@ -416,7 +416,7 @@ public class SignatureObject implements Serializable /** * Set the value and the caption to given key. - * + * * @param key * the key of the signature object * @param value @@ -435,14 +435,14 @@ public class SignatureObject implements Serializable * This method returns a value for a given signature key. If the key equals to * SIG_NORM and the value is null the version * string of the current normalizer is returned! - * + * * @param key * the key to get the value for * @return a value for the given key */ public String getSigValue(String key) { - + String value = null; SignatureEntry sigEntry = null; if (sigEntries_.containsKey(key)) @@ -462,13 +462,13 @@ public class SignatureObject implements Serializable logger_.debug("Using override property for key '" + key + "' = " + value); } } - + return value; } /** * Sets the "Kennzeichnung". - * + * * @param kz * The "Kennzeichnung" to be set. */ @@ -479,7 +479,7 @@ public class SignatureObject implements Serializable /** * Returns the "Kennzeichnung" of this signature. - * + * * @return Returns the "Kennzeichnung" of this signature. Returns null if * there is no "Kennzeichnung" or it is not recognized by this * application. @@ -508,14 +508,14 @@ public class SignatureObject implements Serializable * and the coresponding value is null the key itself is * returned as caption! If the key does not exist the method returns * null. - * + * * @param key * the key to get the caption for * @return a caption for the given key */ private String getSigCaption(String key) { - + String caption = null; if (sigEntries_.containsKey(key)) { @@ -667,15 +667,15 @@ public class SignatureObject implements Serializable if (StringUtils.equals(nameFromText, nameFromCertificate)) { return nameFromText; } - + logger_.debug("Checking RFC2253 name."); - + // if we do not have a name from certificate just return the name from text if (nameFromCertificate == null) { logger_.debug("No certificate RFC2253 name provided. Applying less sophisticated workaround (does not cover all cases) without certificate usage."); return prepareRFC2253Name(nameFromText); } - + // no name from text extraction available, just return name from certificate if (nameFromText == null) { logger_.debug("No extracted/reconstructed name available. Just returning the name from certificate: \"" + nameFromCertificate + "\"."); @@ -762,13 +762,13 @@ public class SignatureObject implements Serializable result.append(rdnVP.getValue()); } else { // no BER encoding -> take value from certificate - // also take RDN from certificate if possible + // also take RDN from certificate if possible String certValue = values[values.length - 1 - i].getAVA() .getValueAsString(); String rdn = resolveRDN(nameFromCertificate, certValue, rdnVP.getRdn()); result.append(rdn + "=").append(certValue); } - + } String merged = result.toString(); if (logger_.isDebugEnabled()) { @@ -785,15 +785,15 @@ public class SignatureObject implements Serializable } return merged; } - + /** * This method tries to resolve the RDN corresponding to a given value from the certificate String. - * As values might occur multiple times for different RDNs, an unambiguous resolving cannot be assured. + * As values might occur multiple times for different RDNs, an unambiguous resolving cannot be assured. * In case of ambiguity, the RDN extracted from text is returned by default. - * + * * This method is a bug fix for a problem that caused the verification of ZID documents to fail as the RDN * from the extracted text ("EMAILADDRESS") was different to the RDN in the certificate ("EMAIL") - * + * * @param certString * The String obtained from the certificate * @param value @@ -804,42 +804,42 @@ public class SignatureObject implements Serializable * The resolved RDN from the certificate, or the RDN from text extraction */ private static String resolveRDN(String certString, String value, String extractedRDN) { - + if (!certString.contains(value)) { - + // given value cannot be found in certificate string return extractedRDN; } - + if (certString.indexOf(value) != certString.lastIndexOf(value)) { - + // given value is ambiguous - cannot resolve RDN from certificate string return extractedRDN; } - + String[] parts = certString.split(",|;"); String val = value.trim(); - + for (int i = 0; i < parts.length; i++) { - + String part = parts[i].trim(); - + if (part.endsWith(val)) { - + // found entry - extract RDN - String[] components = part.split("="); + String[] components = part.split("="); if (components.length != 2) { // unexpected format - return default - return extractedRDN; - } + return extractedRDN; + } String rdn = components[0].trim(); - return rdn; - } - } + return rdn; + } + } // default return extractedRDN; } - + /** * @return Returns the SignationIssuer. */ @@ -920,10 +920,10 @@ public class SignatureObject implements Serializable } // dferbas baik - + /** * signature algorithm if embedded - * @param sigAlg + * @param sigAlg */ public void setSigAlg(String sigAlg) { @@ -937,7 +937,7 @@ public class SignatureObject implements Serializable public String getSigAlg() { return getSigValue(SignatureTypes.SIG_ALG); - } + } /** * @param certDigest @@ -1016,7 +1016,7 @@ public class SignatureObject implements Serializable setSigValue(SIG_CER, x509Certificate); storeCertificate(getSignationSerialNumber(), getSignationIssuer(), x509Certificate); } - + public void setX509Certificate(X509Certificate cert) { try @@ -1037,7 +1037,7 @@ public class SignatureObject implements Serializable /** * return the 509v3 certificate of the given serialNumber and the given issuer * string - * + * * @param serialNumber * the serialNumber which the certificates should load * @param issuer @@ -1070,7 +1070,7 @@ public class SignatureObject implements Serializable /** * Set the signation id's build by a BKU signated SignatureObject. - * + * * @param sigIds * the string to store. */ @@ -1152,7 +1152,7 @@ public class SignatureObject implements Serializable String productVersion = response_properties.getProperty("productVersion"); logger_.debug("productVersion = " + productVersion); - boolean new_etsi = decideNewEtsiByBKUVersion(productVersion); + boolean new_etsi = decideNewEtsiByBKUVersion(productVersion); logger_.debug("verwende neue etsi properties = " + new_etsi); String etsi_prefix = ""; @@ -1183,7 +1183,7 @@ public class SignatureObject implements Serializable /** * Checks if the current SignatureObject is siganted by MOA. It checks if the * current SignatureObject has a signation id value. - * + * * @return true if no signation id value is found, false otherwise */ public boolean isMOASigned() @@ -1204,7 +1204,7 @@ public class SignatureObject implements Serializable /** * Tells if this SignatureObject is textual. - * + * * @return Returns true, if it is textual. */ public boolean isTextual() @@ -1223,7 +1223,7 @@ public class SignatureObject implements Serializable /** * Tells, if this SignatureObject is binary. - * + * * @return Returns true, if it is binary. */ public boolean isBinary() @@ -1237,14 +1237,14 @@ public class SignatureObject implements Serializable { logger_.error(e.getMessage(), e); } - + return SigKZIDHelper.isBinary(kz); } /** * Takes the signation id value of the current SignatureObject and split them * into the corresponding id array added with the id-base. - * + * * @return the id array */ // TODO hotifx @@ -1328,7 +1328,7 @@ public class SignatureObject implements Serializable real_ids[3] = "0-" + base + "-" + ids[3]; real_ids[4] = "0-" + base + "-" + ids[4]; real_ids[5] = etsi_string; - + if (logger_.isDebugEnabled()) { for (int id_idx = 0; id_idx < real_ids.length; id_idx++) @@ -1345,7 +1345,7 @@ public class SignatureObject implements Serializable * for equition. Used to store and find corresponting certificates. * Normalzing: normalizing the string using the normalizer, remove all white * spaces, encode as base64 and replace all "/" chars with "_". - * + * * @param issuer * the issuer string to normalize * @return the normalized issuer string @@ -1357,7 +1357,7 @@ public class SignatureObject implements Serializable { if (issuer != null) { - // use explicit method for normalization + // use explicit method for normalization issuer = normalizeIssuer(issuer); /* this block may be used to enhance normalization (tknall) try { @@ -1375,7 +1375,6 @@ public class SignatureObject implements Serializable } catch (UnsupportedEncodingException e) { - e.printStackTrace(); throw new RuntimeException(e); } } @@ -1443,7 +1442,7 @@ public class SignatureObject implements Serializable } } } - + private X509Cert loadCertificateFromCertstore(String serialNumber, String issuer) { String iss_hash = getIssuerFileHash(issuer); String cert_store_path = certPath_ + iss_hash; @@ -1476,10 +1475,10 @@ public class SignatureObject implements Serializable *

  • add the .txt extension to get the meta information of * the certificate
  • * - * + * * The certificate meta file is build by the base64 coded issuer string and * the cert digest value devided by the @ char. - * + * * @param serialNumber * the file name of the certificate .der|.txt * @param issuer @@ -1541,7 +1540,7 @@ public class SignatureObject implements Serializable /** * Writes the certificate data to a file and stores the file in the local * certificate store. - * + * * @param cert_data * The binary certificate data. */ @@ -1580,17 +1579,17 @@ public class SignatureObject implements Serializable /** * Connects to the LDAP server to look for the certificate. - * + * * @param serialNumber * The serial number String of the certificate being sought. E.g. * "123455676744123432". * @param issuer * The issuer String of the certificate being sought. - * + * * @return Returns the DER certificate file as can be stored in the local * repository. Returns null, if the document wasn't found on the * server. - * @throws ClassNotFoundException + * @throws ClassNotFoundException */ protected byte[] loadCertificateFromLDAP(String serialNumber, String issuer) { // START modification by TK @@ -1629,10 +1628,10 @@ public class SignatureObject implements Serializable *
  • add the .txt extension to get the meta information of * the certificate
  • * - * + * * The certificate meta file is build by the base64 coded issuer string and * the cert digest value devided by the @ char. - * + * * @param serialNumber * the file name of the certificate .der|.txt * @param issuer @@ -1650,7 +1649,7 @@ public class SignatureObject implements Serializable { return storeCertificate(serialNumber, issuer, x509Certificate); } - + /** * This method stores a X509v3 certificate to the filesystem. The reference to * the stored certificate is build by the serialNumber and the issuer string. @@ -1673,10 +1672,10 @@ public class SignatureObject implements Serializable *
  • add the .txt extension to get the meta information of * the certificate
  • * - * + * * The certificate meta file is build by the base64 coded issuer string and * the cert digest value devided by the @ char. - * + * * @param serialNumber * the file name of the certificate .der|.txt * @param issuer @@ -1723,7 +1722,7 @@ public class SignatureObject implements Serializable } return store_complete; } - + /** * @return Returns the AbstractTable. * @see at.knowcenter.wag.egov.egiz.table.Table @@ -1739,7 +1738,7 @@ public class SignatureObject implements Serializable /** * This method read the style definitions from the settings file. - * + * * @param styleKey * the key to read the style definitions * @return the defined style informations @@ -1762,7 +1761,7 @@ public class SignatureObject implements Serializable * This method creates an abstract signature table object. It takes all keys * and values set by the signature object to create the corresponding abstract * table object. The table definition is read from the settings file. - * + * * @param tableKey * is the name of the table definition in the settings file * @return a new abstract signature table @@ -1964,7 +1963,7 @@ public class SignatureObject implements Serializable /** * This method returns a signature entry object. - * + * * @param key * the corresponding key * @return the signature entry object of the given key, null if the key does @@ -1977,7 +1976,7 @@ public class SignatureObject implements Serializable /** * This method is a helper function to remove all white spaces from a text. - * + * * @param text * the white spaces should remove from * @return a text without white spaces @@ -1993,7 +1992,7 @@ public class SignatureObject implements Serializable } /** - * + * * @param placeholder * @return Returns the list of SignatureFieldDefinitions that's values in the * SignatureObject have been filled out with placeholders. @@ -2015,7 +2014,7 @@ public class SignatureObject implements Serializable setValueBruteForce(SignatureTypes.SIG_ID, null); continue; } - + if (sfd.field_name.equals(SignatureTypes.SIG_ALG) && !baikEnabled) { setValueBruteForce(SignatureTypes.SIG_ID, null); continue; @@ -2040,7 +2039,7 @@ public class SignatureObject implements Serializable /** * Returns the raw signature response XML string as set by the signing * Connector. - * + * * @return Returns the XML response String. */ public String getRawSignatureResponse() @@ -2050,12 +2049,12 @@ public class SignatureObject implements Serializable /** * Sets the raw signature response XML string. - * + * *

    * This should be used by the Connector to pass the response String to the * signer. *

    - * + * * @param raw_response_string * The new raw signature response string. */ @@ -2063,8 +2062,8 @@ public class SignatureObject implements Serializable { this.raw_signature_response = raw_response_string; } - - + + /** * get timestamp if available -- cgit v1.2.3