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 + 4 files changed, 80 insertions(+), 13 deletions(-) (limited to 'pdf-as-lib/src/main/java/at/gv/egiz/pdfas') 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)); } -- cgit v1.2.3