aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-04-16 21:31:36 +0200
committerAlexander Marsalek <amarsalek@iaik.tugraz.at>2021-04-16 21:31:36 +0200
commit649b3cd196987eac24a519d987676a0ba09e2432 (patch)
tree2b23429059a42e47ae79918f3742a94d31630f2a
parent0ee66ba66a9ea84cd6f31589ce0b0192f24a6258 (diff)
downloadpdf-as-4-649b3cd196987eac24a519d987676a0ba09e2432.tar.gz
pdf-as-4-649b3cd196987eac24a519d987676a0ba09e2432.tar.bz2
pdf-as-4-649b3cd196987eac24a519d987676a0ba09e2432.zip
added test & error message
-rw-r--r--pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java33
-rw-r--r--pdf-as-common/src/main/resources/resources/messages/common.properties1
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java2
-rw-r--r--pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java8
-rw-r--r--pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java90
5 files changed, 129 insertions, 5 deletions
diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java
index 9c53c80e..7b29b535 100644
--- a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java
+++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturBlockParameterTest.java
@@ -45,6 +45,7 @@ import org.junit.Test;
import javax.activation.DataSource;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
@@ -67,6 +68,38 @@ public class SignaturBlockParameterTest {
return absolutePath;
}
+ @Test(expected = PdfAsException.class)
+ public void invalid() throws IOException, PdfAsException, PDFASError {
+
+ PdfAs pdfas = PdfAsFactory.createPdfAs(new File(getPath("pdfas-config")));
+ Configuration config = pdfas.getConfiguration();
+
+ byte[] input = IOUtils.toByteArray(new FileInputStream(getPath("simple_rotated_0.pdf")));
+
+ IPlainSigner signer = new PAdESSignerKeystore(getPath("test.p12"), KS_ALIAS, KS_PASS, KS_KEY_PASS, KS_TYPE);
+
+ String profile = "SIGNATURBLOCK_DE_NOTE_DYNAMIC";
+ System.out.println("Testing " + profile);
+
+ DataSource source = new ByteArrayDataSource(input);
+ String outFile = getPath("out") + "/" + profile + ".pdf";
+ FileOutputStream fos = new FileOutputStream(outFile);
+ SignParameter signParameter = PdfAsFactory.createSignParameter(
+ config, source, fos);
+
+ Map<String, String> map = new HashMap<>();
+ map.put("subject", "TEST123");
+ map.put("WAY_TOOOOOOOOOOOOOOOOOOOOO_LONG_KEY", "bar");
+ signParameter.setDynamicSignatureBlockArguments(map);
+// signParameter.setPlainSigner(signer);
+// signParameter.setSignatureProfileId(profile);
+//
+// SignResult result = pdfas.sign(signParameter);
+
+ fos.close();
+
+ }
+
@Test
public void test() throws IOException, PDFASError, PdfAsException {
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
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
index 19111342..5c3e548f 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsParameterImpl.java
@@ -90,7 +90,7 @@ protected Configuration configuration;
if( CheckSignatureBlockParameters.checkSignatureBlockParameterMapIsValid(tmpMap, keyRegex, valueRegex) == true) {
this.dynamicSignatureBlockArgumentsMap = tmpMap;
}else{
- throw new PdfAsException("Invalid signature block parameters");
+ throw new PdfAsException("error.invalid.signature.parameter.01");
}
}
diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java
index 4089377b..d8066ffc 100644
--- a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java
+++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAP.java
@@ -86,10 +86,10 @@ public class SimpleTestSOAP {
System.out.println("Sign Error: " + response.getError());
System.out.println("redirect url: " + response.getRedirectUrl());
- File outputFile = new File(file+"_signedSOAP.pdf");
- try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
- outputStream.write(response.getSignedPDF());
- }
+// File outputFile = new File(file+"_signedSOAP.pdf");
+// try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
+// outputStream.write(response.getSignedPDF());
+// }
System.out.println("Done!");
} catch (Throwable e) {
diff --git a/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java
new file mode 100644
index 00000000..17278303
--- /dev/null
+++ b/pdf-as-web-client/src/test/java/at/gv/egiz/pdfas/web/client/test/SimpleTestSOAPInvalidParameter.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * <copyright> Copyright 2014 by E-Government Innovation Center EGIZ, Graz, Austria </copyright>
+ * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a
+ * joint initiative of the Federal Chancellery Austria and Graz University of
+ * Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ ******************************************************************************/
+package at.gv.egiz.pdfas.web.client.test;
+
+import at.gv.egiz.pdfas.api.ws.PDFASSignParameters;
+import at.gv.egiz.pdfas.api.ws.PDFASSignParameters.Connector;
+import at.gv.egiz.pdfas.api.ws.PDFASSignRequest;
+import at.gv.egiz.pdfas.api.ws.PDFASSignResponse;
+import at.gv.egiz.pdfas.web.client.RemotePDFSigner;
+import org.apache.commons.io.IOUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.net.URL;
+
+public class SimpleTestSOAPInvalidParameter {
+
+ public static void main(String[] args) {
+ try {
+ String file = "/Users/amarsalek/Documents/pdf-as-4/unsigned.pdf";
+ FileInputStream fis = new FileInputStream(file);
+ byte[] inputData = IOUtils.toByteArray(fis);
+
+ PDFASSignParameters signParameters = new PDFASSignParameters();
+// signParameters.setConnector(Connector.JKS);
+ signParameters.setConnector(Connector.BKU);
+ signParameters.setPosition(null);
+ signParameters.setProfile("SIGNATURBLOCK_SMALL_DE1");
+ signParameters.setQRCodeContent("TEST CONTENT");
+ //signParameters.setKeyIdentifier("test");
+
+ PDFASSignRequest request = new PDFASSignRequest();
+ request.setInputData(inputData);
+ request.setParameters(signParameters);
+ request.setRequestID("SOME TEST ID");
+ request.getSignatureBlockParameters().put("abc","SOAP Test");
+ //URL endpoint = new
+ //URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl");
+ //URL endpoint = new
+ // URL("http://www.buergerkarte.at/pdf-as-extern-4/wssign?wsdl");
+// String baseUrl = "http://demo.egiz.gv.at/demoportal-pdf_as/services/";
+ String baseUrl = "http://localhost:8080/pdf-as-web/services/";
+ //URL endpoint = new URL(
+ // "http://192.168.56.10/pdf-as-web/wssign?wsdl");
+
+ URL signEndpoint = new URL(baseUrl + "wssign?wsdl");
+
+ RemotePDFSigner signer = new RemotePDFSigner(signEndpoint, true);
+
+ PDFASSignRequest signrequest = new PDFASSignRequest();
+ signrequest.setInputData(inputData);
+ signrequest.setParameters(signParameters);
+ signParameters.setTransactionId("MYID ....");
+ signrequest.getSignatureBlockParameters().put("abc","SOAP Test 5555");
+ signrequest.getSignatureBlockParameters().put("way toooooooooooooo long","SOAP Test 5555");
+ System.out.println("Simple Request:");
+ PDFASSignResponse response = signer.signPDFDokument(signrequest);
+
+ System.out.println("Sign Error: " + response.getError());
+ System.out.println("redirect url: " + response.getRedirectUrl());
+
+ System.out.println("Should see an error page...");
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+}