diff options
Diffstat (limited to 'pdf-as-lib/src/main/java/demo')
-rw-r--r-- | pdf-as-lib/src/main/java/demo/SignatureVerificationDemo.java | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/pdf-as-lib/src/main/java/demo/SignatureVerificationDemo.java b/pdf-as-lib/src/main/java/demo/SignatureVerificationDemo.java index 0ba95ff..204339a 100644 --- a/pdf-as-lib/src/main/java/demo/SignatureVerificationDemo.java +++ b/pdf-as-lib/src/main/java/demo/SignatureVerificationDemo.java @@ -57,7 +57,7 @@ public class SignatureVerificationDemo { /**
* Starts a demo that verifies a document.
- *
+ *
* @param args
* The parameter(s).
*/
@@ -67,7 +67,7 @@ public class SignatureVerificationDemo { System.err.println("Please provide path of file to be verified.");
System.exit(1);
}
-
+
File configdir = new File("./work");
// look for work folder in current directory
if (!configdir.exists()) {
@@ -75,7 +75,7 @@ public class SignatureVerificationDemo { configdir = new File("../work");
}
File signedFile = new File(args[0]);
-
+
AnalyzeResult analyzeResult = null;
try {
@@ -108,7 +108,7 @@ public class SignatureVerificationDemo { System.out.println("Analyzing...");
analyzeResult = pdfasAPI.analyze(analyzeParameters);
System.out.println("Successfully analyzed.");
-
+
// information on non-textual objects can be used after analysis step and/or after verification
List signatures = analyzeResult.getSignatures();
if (signatures != null && !signatures.isEmpty()) {
@@ -126,7 +126,7 @@ public class SignatureVerificationDemo { System.out.println(" -> " + info.toString());
}
System.out.println();
-
+
} else {
System.out.println("\nNo non-textual objects detected for this signature.");
}
@@ -139,7 +139,7 @@ public class SignatureVerificationDemo { }
System.exit(1);
}
-
+
// retrieve reconstructed signature
ReconstructXMLDsigAfterAnalysisParameters recstrParams = new ReconstructXMLDsigAfterAnalysisParameters();
recstrParams.setAnalyzeResult(analyzeResult);
@@ -166,9 +166,9 @@ public class SignatureVerificationDemo { */
// setup verification
-
+
// verification without intermediate step of reconstruction
- /*
+ /*
VerifyAfterAnalysisParameters vaap = new VerifyAfterAnalysisParameters();
vaap.setAnalyzeResult(analyzeResult);
vaap.setReturnHashInputData(true);
@@ -178,7 +178,7 @@ public class SignatureVerificationDemo { // use result.isVerificationDone() in order to find out if a signatures was successfully verified
vaap.setSuppressVerifyExceptions(true);
*/
-
+
// verification with intermediate step of reconstruction
VerifyAfterReconstructXMLDsigParameters varp = new VerifyAfterReconstructXMLDsigParameters();
varp.setReconstructXMLDsigResult(recstrResult);
@@ -192,15 +192,15 @@ public class SignatureVerificationDemo { // invoke verification
System.out.println("Verifying...");
-
+
// without intermediate step of reconstruction
/*
VerifyResults verifyResults = pdfasAPI.verify(vaap);
*/
-
+
// with intermediate step of reconstruction
VerifyResults verifyResults = pdfasAPI.verify(varp);
-
+
// retrieve results
List verifyResultList = verifyResults.getResults();
System.out.println("Verification complete.\n");
@@ -213,14 +213,14 @@ public class SignatureVerificationDemo { counter++;
VerifyResult result = (VerifyResult) it.next();
out.println("\n------------------------ SIGNATURE #" + counter + " ------------------------\n");
-
+
// check if signature verification of the current signature was successfully completed (independent from result)
if (!result.isVerificationDone()) {
PdfAsException ex = result.getVerificationException();
out.println(ErrorCodeHelper.formErrorMessage(ex));
continue;
}
-
+
Main.formatVerifyResult(result, out);
XMLDsigData xmlDSigData = result.getReconstructedXMLDsig();
if (xmlDSigData != null) {
@@ -233,12 +233,12 @@ public class SignatureVerificationDemo { byte[] data = result.getSignedData().getAsByteArray();
out.println("\n Signed Data: " + data.length + " bytes (" + result.getSignatureType() + ")");
}
-
+
// check if there are timestamps
if (result.getTimeStampValue() != null) {
out.println("\n TimeStamp value available for this signature");
}
-
+
// check if non textual elements have been detected for this signature
if (result.hasNonTextualObjects()) {
out.println("\n WARNING: " + result.getNonTextualObjects().size() + " non textual object(s) detected for this signature");
@@ -248,13 +248,13 @@ public class SignatureVerificationDemo { out.println(" -> " + info.toString());
}
out.println();
-
+
} else {
out.println("\n No non-textual objects detected for this signature.");
}
}
- out.flush();
-
+ out.flush();
+
} catch (PdfAsException e) {
if (ErrorCode.DOCUMENT_NOT_SIGNED == e.getErrorCode() && analyzeResult != null && analyzeResult.hasBeenCorrected()) {
System.err.println("\nThe document could not been processed, maybe due to modification by third party tools. An attempt to correct the document was successful but no verifiable signatures could be found. This/these signature(s) - if any - might got lost.");
|