From 7fe464cc98d714179b907c142bdd2fabfd009aa3 Mon Sep 17 00:00:00 2001 From: bschnalzer Date: Wed, 9 Aug 2017 13:56:12 +0200 Subject: Fixed problem with PAdES Signatures, removed some attributes from CAdES signatures which are not required, minor bug fixes, implemented new style (lineCenter) --- .../sl/schema/CreateCMSSignatureRequestType.java | 37 +++++++---- .../java/at/gv/egiz/sl/util/BKUSLConnector.java | 9 +++ .../java/at/gv/egiz/sl/util/BaseSLConnector.java | 71 +++++++++++++++++++++- 3 files changed, 104 insertions(+), 13 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/sl') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/schema/CreateCMSSignatureRequestType.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/schema/CreateCMSSignatureRequestType.java index cbfb1f53..5d565d9d 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/schema/CreateCMSSignatureRequestType.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/schema/CreateCMSSignatureRequestType.java @@ -31,6 +31,8 @@ package at.gv.egiz.sl.schema; +import com.sun.org.apache.xpath.internal.operations.Bool; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -82,14 +84,17 @@ public class CreateCMSSignatureRequestType { protected CMSDataObjectRequiredMetaType dataObject; @XmlAttribute(name = "Structure", required = true) protected String structure; + //PAdES Signatures + @XmlAttribute(name = "PAdESCompatibility", required = false) + private Boolean PAdESFlag; /** * Gets the value of the keyboxIdentifier property. - * + * * @return * possible object is * {@link String } - * + * */ public String getKeyboxIdentifier() { return keyboxIdentifier; @@ -97,11 +102,11 @@ public class CreateCMSSignatureRequestType { /** * Sets the value of the keyboxIdentifier property. - * + * * @param value * allowed object is * {@link String } - * + * */ public void setKeyboxIdentifier(String value) { this.keyboxIdentifier = value; @@ -109,11 +114,11 @@ public class CreateCMSSignatureRequestType { /** * Gets the value of the dataObject property. - * + * * @return * possible object is * {@link CMSDataObjectRequiredMetaType } - * + * */ public CMSDataObjectRequiredMetaType getDataObject() { return dataObject; @@ -121,11 +126,11 @@ public class CreateCMSSignatureRequestType { /** * Sets the value of the dataObject property. - * + * * @param value * allowed object is * {@link CMSDataObjectRequiredMetaType } - * + * */ public void setDataObject(CMSDataObjectRequiredMetaType value) { this.dataObject = value; @@ -133,11 +138,11 @@ public class CreateCMSSignatureRequestType { /** * Gets the value of the structure property. - * + * * @return * possible object is * {@link String } - * + * */ public String getStructure() { return structure; @@ -145,14 +150,22 @@ public class CreateCMSSignatureRequestType { /** * Sets the value of the structure property. - * + * * @param value * allowed object is * {@link String } - * + * */ public void setStructure(String value) { this.structure = value; } + + public Boolean getPAdESFlag() { + return PAdESFlag; + } + + public void setPAdESFlag(Boolean PAdESFlag) { + this.PAdESFlag = PAdESFlag; + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java index 6383b89b..4a32390b 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BKUSLConnector.java @@ -164,14 +164,23 @@ public class BKUSLConnector extends BaseSLConnector { BKUHeader hdr = new BKUHeader(headers[i].getName(), headers[i].getValue()); logger.debug("Response Header : {}", hdr.toString()); + if (hdr.toString().contains("Server")) + { + BaseSLConnector.responseHeader=hdr.toString(); + } + holder.getProcessInfo().add(hdr); + } + } BKUHeader hdr = new BKUHeader( ErrorConstants.STATUS_INFO_SIGDEVICE, SIGNATURE_DEVICE); logger.debug("Response Header : {}", hdr.toString()); + holder.getProcessInfo().add(hdr); + } BufferedReader rd = new BufferedReader(new InputStreamReader( diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java index d6c21672..46857249 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java @@ -24,6 +24,9 @@ package at.gv.egiz.sl.util; import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +61,11 @@ public abstract class BaseSLConnector implements ISLConnector, public static final String XMLREQUEST = "XMLRequest"; + public static final String WHITELIST_VERSION_ENABLED = "whitelistVersion.enabled"; + public static final String WHITELIST_VALUE_PRE = "whiteListVersions"; + private static List whiteListregEx = new ArrayList(); + public static String responseHeader; + protected ObjectFactory of = new ObjectFactory(); public InfoboxReadRequestType createInfoboxReadRequest( @@ -92,7 +100,6 @@ public abstract class BaseSLConnector implements ISLConnector, logger.info("Exclude Byte Range: " + exclude_range[0] + " " + exclude_range[1]); - // == MetaInfoType MetaInfoType metaInfoType = new MetaInfoType(); metaInfoType.setMimeType(PDF_MIME_TYPE); @@ -122,12 +129,74 @@ public abstract class BaseSLConnector implements ISLConnector, } // == CreateCMSSignatureRequestType + CreateCMSSignatureRequestType request = new CreateCMSSignatureRequestType(); request.setKeyboxIdentifier(SecureSignatureKeypair); request.setDataObject(cmsDataObjectRequiredMetaType); request.setStructure(DETACHED); + + + //whiteListregEx.add("1.2 MOCCA"); + if (parameter.getConfiguration().hasValue(IConfigurationConstants.SIG_PADES_FORCE_FLAG)) + { + if (IConfigurationConstants.TRUE.equalsIgnoreCase(parameter.getConfiguration().getValue(IConfigurationConstants.SIG_PADES_FORCE_FLAG))) + { + request.setPAdESFlag(true); + } + } + else + if (parameter.getConfiguration().hasValue(IConfigurationConstants.SIG_PADES_INTELL_FLAG)){ + if (IConfigurationConstants.TRUE.equalsIgnoreCase(parameter.getConfiguration().getValue(IConfigurationConstants.SIG_PADES_INTELL_FLAG))) + { + boolean intellFlag=isProvidePdfVersionInWhitelist(responseHeader, parameter); + + if (intellFlag) + { + request.setPAdESFlag(true); + } + }} + pack.setRequestType(request); return pack; } + + + public static boolean isWhiteListEnabled(SignParameter parameter) { + + boolean whiteListConfig = parameter.getConfiguration().hasValue(WHITELIST_VERSION_ENABLED); + if (whiteListConfig) + { + String value = parameter.getConfiguration().getValue(WHITELIST_VERSION_ENABLED); + + if (value != null) { + if (value.equals("true")) { + whiteListregEx.add(parameter.getConfiguration().getValue(WHITELIST_VALUE_PRE)); + return true; + } + }} + return false; + + } + + public static synchronized boolean isProvidePdfVersionInWhitelist(String bkuVersionInformation, SignParameter parameter) { + if (isWhiteListEnabled(parameter)) { + + Iterator patterns = whiteListregEx.iterator(); + while (patterns.hasNext()) { + String pattern = patterns.next(); + try { + if (bkuVersionInformation.contains(pattern)) { + return true; + } + //TODO: extend with BlackList + + } catch (Throwable e) { + logger.warn("Error in matching regex: " + pattern, e); + } + } + return false; + } + return true; + } } -- cgit v1.2.3