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) --- .../pdfas/lib/api/IConfigurationConstants.java | 16 ++--- .../configuration/PlaceholderConfiguration.java | 42 ++++++++++++- .../lib/impl/placeholder/PlaceholderFilter.java | 34 ++++++++++- .../at/gv/egiz/pdfas/lib/settings/Settings.java | 1 + .../sl/schema/CreateCMSSignatureRequestType.java | 37 +++++++---- .../java/at/gv/egiz/sl/util/BKUSLConnector.java | 9 +++ .../java/at/gv/egiz/sl/util/BaseSLConnector.java | 71 +++++++++++++++++++++- 7 files changed, 184 insertions(+), 26 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz') diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 14aca130..364acb44 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -50,14 +50,9 @@ public interface IConfigurationConstants { public static final String PLACEHOLDER_SEARCH_ENABLED = "enable_placeholder_search"; public static final String DEFAULT_SIGNATURE_PROFILE = SIG_OBJECT + SEPERATOR + TYPE + SEPERATOR + DEFAULT; - + public static final String CONFIG_BKU_URL = "bku.sign.url"; - /** - * Signature object Prefix - */ - public static final String SIG_OBJECT_PREFIX = "sig_obj."; - /** * MOA SS Signing Key Identifier */ @@ -103,10 +98,17 @@ public interface IConfigurationConstants { * Signature object Prefix */ public static final String SIG_RESERVED_SIZE = "signatureSize"; - + /** * Visual Signature placement */ public static final String BG_COLOR_DETECTION = "sigblock.placement.bgcolor.detection.enabled"; public static final String SIG_PLACEMENT_DEBUG_OUTPUT = "sigblock.placement.debug.file"; + + + /** + * PADES Constants + */ + public static final String SIG_PADES_FORCE_FLAG= SIG_OBJECT + SEPERATOR+"PAdESCompatibility"; + public static final String SIG_PADES_INTELL_FLAG = SIG_OBJECT + SEPERATOR+"CheckPAdESCompatibility"; } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java index ec030388..6e91e808 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/PlaceholderConfiguration.java @@ -24,7 +24,23 @@ package at.gv.egiz.pdfas.lib.impl.configuration; import at.gv.egiz.pdfas.common.settings.ISettings; +import at.gv.egiz.pdfas.common.settings.Profiles; +import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; +import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import at.gv.egiz.pdfas.lib.impl.PdfAsImpl; +import at.gv.egiz.pdfas.lib.impl.PdfAsParameterImpl; +import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData; +import at.gv.egiz.pdfas.lib.impl.status.OperationStatus; +import at.gv.egiz.pdfas.lib.settings.Settings; +import at.gv.egiz.pdfas.lib.util.SignatureUtils; +import at.gv.egiz.pdfas.lib.api.PdfAs; +import com.sun.corba.se.spi.orb.Operation; + +import java.security.Signature; +import java.util.Properties; + public class PlaceholderConfiguration extends SpecificBaseConfiguration implements IConfigurationConstants { @@ -34,13 +50,33 @@ public class PlaceholderConfiguration extends SpecificBaseConfiguration } public boolean isGlobalPlaceholderEnabled() { - if(configuration.hasValue(PLACEHOLDER_SEARCH_ENABLED)) { + if (configuration.hasValue(PLACEHOLDER_SEARCH_ENABLED)) { String value = configuration.getValue(PLACEHOLDER_SEARCH_ENABLED); - if(value.equalsIgnoreCase(TRUE)) { + if (value.equalsIgnoreCase(TRUE)) { + return true; + } + } + return false; + } + + + /** + * Match selected Profile for Placeholder + * Enables to activate placeholder search/match for different profiles + * @return + */ + public boolean isProfileConfigurationEnabled(String selectedProfileID) + { + String profileMatch = SIG_OBJECT+SEPERATOR+selectedProfileID+SEPERATOR+PLACEHOLDER_SEARCH_ENABLED; + if (configuration.hasValue(profileMatch)) { + String value = configuration.getValue(profileMatch); + if (value.equalsIgnoreCase(TRUE)) { return true; } } return false; } - } + + + diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java index 19ea496d..9906fd6a 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java @@ -63,7 +63,35 @@ public class PlaceholderFilter implements IConfigurationConstants, .extract(status.getPdfObject(), placeholderID, placeholderMode); return signaturePlaceholderData; - } + } else + //filter for local placeholder in selected profiles + if (status.getPlaceholderConfiguration().isProfileConfigurationEnabled(status.getRequestedSignature().getSignatureProfileID())) { + PlaceholderExtractor extractor = status.getBackend() + .getPlaceholderExtractor(); + String placeholderID = settings.getValue(PLACEHOLDER_ID); + String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; + if (placeholderModeString != null) { + try { + placeholderMode = Integer.parseInt(placeholderModeString); + + if (placeholderMode < PLACEHOLDER_MODE_MIN + || placeholderMode > PLACEHOLDER_MODE_MAX) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE)); + } + } catch (NumberFormatException e) { + throw new PdfAsErrorCarrier(new PDFASError( + PDFASError.ERROR_INVALID_PLACEHOLDER_MODE, e)); + } + } + SignaturePlaceholderData signaturePlaceholderData = extractor + .extract(status.getPdfObject(), placeholderID, placeholderMode); + + return signaturePlaceholderData; + + + + } return null; - } -} + }} \ No newline at end of file diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java index c5879783..c5b6dc57 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java @@ -399,6 +399,7 @@ public class Settings implements ISettings, IProfileConstants { while (keyIterator.hasNext()) { String key = keyIterator.next().toString(); + if (key.startsWith(prefix)) { valueMap.put(key, props.getProperty(key)); } 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