@@ -104,18 +104,12 @@ public class LtvVerifier extends RootStoreVerifier {
104
104
*/
105
105
public LtvVerifier (PdfDocument document ) throws GeneralSecurityException {
106
106
super (null );
107
- this .document = document ;
108
- this .acroForm = PdfAcroForm .getAcroForm (document , true );
109
- this .sgnUtil = new SignatureUtil (document );
110
- List <String > names = sgnUtil .getSignatureNames ();
111
- signatureName = names .get (names .size () - 1 );
112
- this .signDate = DateTimeUtil .getCurrentTimeDate ();
113
- pkcs7 = coversWholeDocument ();
114
- LOGGER .info (MessageFormat .format ("Checking {0}signature {1}" , pkcs7 .isTsp () ? "document-level timestamp " : "" , signatureName ));
107
+ initLtvVerifier (document );
115
108
}
116
109
public LtvVerifier (PdfDocument document , String securityProviderCode ) throws GeneralSecurityException {
117
- this ( document );
110
+ super ( null );
118
111
this .securityProviderCode = securityProviderCode ;
112
+ initLtvVerifier (document );
119
113
}
120
114
121
115
/**
@@ -141,29 +135,6 @@ public void setVerifyRootCertificate(boolean verifyRootCertificate) {
141
135
this .verifyRootCertificate = verifyRootCertificate ;
142
136
}
143
137
144
- /**
145
- * Checks if the signature covers the whole document
146
- * and throws an exception if the document was altered
147
- * @return a PdfPKCS7 object
148
- * @throws GeneralSecurityException
149
- */
150
- protected PdfPKCS7 coversWholeDocument () throws GeneralSecurityException {
151
- PdfPKCS7 pkcs7 = sgnUtil .verifySignature (signatureName , securityProviderCode );
152
- if (sgnUtil .signatureCoversWholeDocument (signatureName )) {
153
- LOGGER .info ("The timestamp covers whole document." );
154
- }
155
- else {
156
- throw new VerificationException ((Certificate ) null , "Signature doesn't cover whole document." );
157
- }
158
- if (pkcs7 .verify ()) {
159
- LOGGER .info ("The signed document has not been modified." );
160
- return pkcs7 ;
161
- }
162
- else {
163
- throw new VerificationException ((Certificate ) null , "The document was altered after the final signature was applied." );
164
- }
165
- }
166
-
167
138
/**
168
139
* Verifies all the document-level timestamps and all the signatures in the document.
169
140
* @throws IOException
@@ -352,4 +323,38 @@ public List<BasicOCSPResp> getOCSPResponsesFromDSS() throws IOException, General
352
323
}
353
324
return ocsps ;
354
325
}
326
+
327
+ protected void initLtvVerifier (PdfDocument document ) throws GeneralSecurityException {
328
+ this .document = document ;
329
+ this .acroForm = PdfAcroForm .getAcroForm (document , true );
330
+ this .sgnUtil = new SignatureUtil (document );
331
+ List <String > names = sgnUtil .getSignatureNames ();
332
+ signatureName = names .get (names .size () - 1 );
333
+ this .signDate = DateTimeUtil .getCurrentTimeDate ();
334
+ pkcs7 = coversWholeDocument ();
335
+ LOGGER .info (MessageFormat .format ("Checking {0}signature {1}" , pkcs7 .isTsp () ? "document-level timestamp " : "" , signatureName ));
336
+ }
337
+
338
+ /**
339
+ * Checks if the signature covers the whole document
340
+ * and throws an exception if the document was altered
341
+ * @return a PdfPKCS7 object
342
+ * @throws GeneralSecurityException
343
+ */
344
+ protected PdfPKCS7 coversWholeDocument () throws GeneralSecurityException {
345
+ PdfPKCS7 pkcs7 = sgnUtil .verifySignature (signatureName , securityProviderCode );
346
+ if (sgnUtil .signatureCoversWholeDocument (signatureName )) {
347
+ LOGGER .info ("The timestamp covers whole document." );
348
+ }
349
+ else {
350
+ throw new VerificationException ((Certificate ) null , "Signature doesn't cover whole document." );
351
+ }
352
+ if (pkcs7 .verify ()) {
353
+ LOGGER .info ("The signed document has not been modified." );
354
+ return pkcs7 ;
355
+ }
356
+ else {
357
+ throw new VerificationException ((Certificate ) null , "The document was altered after the final signature was applied." );
358
+ }
359
+ }
355
360
}
0 commit comments