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) --- .../java/at/gv/egiz/sl/util/BaseSLConnector.java | 71 +++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/sl/util/BaseSLConnector.java') 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