From 8ed8e4e931c1cb3d3c814a53a07f73b566c3b719 Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Fri, 2 Jul 2021 14:06:44 +0200 Subject: v4.2.0 --- pdf-as-common/build.gradle | 19 +++++----- .../at/gv/egiz/pdfas/api/ws/PDFASSignRequest.java | 16 +++++++++ .../settings/DefaultSignatureProfileSettings.java | 4 +++ .../pdfas/common/settings/IProfileConstants.java | 1 + .../utils/CheckSignatureBlockParameters.java | 42 ++++++++++++++++++++++ .../resources/resources/messages/common.properties | 1 + 6 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java (limited to 'pdf-as-common') diff --git a/pdf-as-common/build.gradle b/pdf-as-common/build.gradle index e1a5fdfc..a607fcfe 100644 --- a/pdf-as-common/build.gradle +++ b/pdf-as-common/build.gradle @@ -1,4 +1,4 @@ -apply plugin: 'java' +apply plugin: 'java-library' apply plugin: 'eclipse' jar { @@ -20,14 +20,15 @@ releases.dependsOn jar releases.dependsOn sourcesJar dependencies { - compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion - compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2' - compile group: 'commons-io', name: 'commons-io', version: '2.4' - compile group: 'ognl', name: 'ognl', version: '3.0.6' - compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' - compile 'commons-codec:commons-codec:1.10' - compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3' - testCompile group: 'junit', name: 'junit', version: '4.+' + api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion + api group: 'commons-collections', name: 'commons-collections', version: '3.2.2' + api group: 'commons-io', name: 'commons-io', version: '2.8.0' + api group: 'ognl', name: 'ognl', version: '3.2.19' + api group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' + api 'commons-codec:commons-codec:1.10' + api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3' + api group: 'javax.jws', name: 'javax.jws-api', version: '1.1' + testImplementation group: 'junit', name: 'junit', version: '4.+' } test { diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignRequest.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignRequest.java index 3e714ea9..39a384b2 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignRequest.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/api/ws/PDFASSignRequest.java @@ -24,6 +24,8 @@ package at.gv.egiz.pdfas.api.ws; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @@ -40,6 +42,9 @@ public class PDFASSignRequest implements Serializable { byte[] inputData; PDFASSignParameters parameters; VerificationLevel verificationLevel; + + //map of user provided parameters, these values can be used in the signature block + Map signatureBlockParameters; @XmlElement(required = true, nillable = false, name="requestID") public String getRequestID() { @@ -76,4 +81,15 @@ public class PDFASSignRequest implements Serializable { public void setParameters(PDFASSignParameters parameters) { this.parameters = parameters; } + + @XmlElement(required = false, nillable = true, name="signatureBlockParameter") + public Map getSignatureBlockParameters() { + if(signatureBlockParameters == null) + signatureBlockParameters = new HashMap<>(); + return signatureBlockParameters; + } + + public void setSignatureBlockParameters(Map signatureBlockParameters) { + this.signatureBlockParameters = signatureBlockParameters; + } } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java index 6f1519a4..6e288a27 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/DefaultSignatureProfileSettings.java @@ -65,6 +65,10 @@ public class DefaultSignatureProfileSettings { public static final String VALUE_SIG_DATE_DEFAULT = "yyyy-MM-dd'T'HH:mm:ssXXX"; + public static final String SIG_BLOCK_PARAMETER_DEFAULT_KEY_REGEX = "^([A-za-z]){1,20}$"; +// public static final String SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX = "^([\\p{Print}-ß_'\\+\\!\u00e4\u00f6\u00fc" + +// "\u00c4\u00d6\u00dc]){1,100}$"; +public static final String SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX = "^([\\p{Print}\u00df\u00A7\u20AC\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc]){1,100}$"; static { profileSettings.put(KEY_SIG_SUBJECT, new SignatureProfileEntry(KEY_SIG_SUBJECT, KEY_SIG_SUBJECT_DEFAULT, VALUE_SIG_SUBJECT_DEFAULT) ); diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java index e1fcb9d0..3f07f774 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/IProfileConstants.java @@ -96,4 +96,5 @@ public interface IProfileConstants { public final static String SIG_PDFUA_FORCE = "SIG_PDFUA_FORCE"; public final static String LATIN1_ENCODING = "latin1_encoding"; + public final static String SIGNATURE_BLOCK_PARAMETER = "sbp"; } diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java new file mode 100644 index 00000000..756a240c --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/CheckSignatureBlockParameters.java @@ -0,0 +1,42 @@ +package at.gv.egiz.pdfas.common.utils; + +import at.gv.egiz.pdfas.common.settings.DefaultSignatureProfileSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +public class CheckSignatureBlockParameters { + + private static final Logger logger = LoggerFactory + .getLogger(CheckSignatureBlockParameters.class); + public static boolean checkSignatureBlockParameterMapIsValid(Map map, String keyRegex, + String valueRegex) { + + logger.trace("regex1:"+keyRegex+", regex1:"+valueRegex); + if(keyRegex == null || keyRegex.length() == 0) { + keyRegex = DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_KEY_REGEX; + } + if(valueRegex == null || valueRegex.length() == 0) { + valueRegex = DefaultSignatureProfileSettings.SIG_BLOCK_PARAMETER_DEFAULT_VALUE_REGEX; + } + logger.trace("regex2:"+keyRegex+", regex2:"+valueRegex); + for(String key : map.keySet()){ + if(isValid(key, keyRegex) == false) { + logger.error("Invalid key:"+key+", regex:"+keyRegex); + return false; + } + if(isValid(map.get(key), valueRegex) == false) { + logger.error("Invalid value:"+map.get(key)+", regex:"+valueRegex); + return false; + } + } + + return true; + } + + public static boolean isValid(String s, String regex) { + return s.matches(regex); + } + +} diff --git a/pdf-as-common/src/main/resources/resources/messages/common.properties b/pdf-as-common/src/main/resources/resources/messages/common.properties index 8ddfe312..0a7f1787 100644 --- a/pdf-as-common/src/main/resources/resources/messages/common.properties +++ b/pdf-as-common/src/main/resources/resources/messages/common.properties @@ -25,6 +25,7 @@ error.pdf.stamp.09=no suitable placeholder found and STRICT matching mode reques error.pdf.stamp.10=no stamper available error.pdf.stamp.11=Failed to calculate page length +error.invalid.signature.parameter.01=Signature block parameter is invalid #Signature errors error.pdf.sig.01=Failed to create signature error.pdf.sig.02=Failed to open keystore -- cgit v1.2.3