Skip to content

Commit 4890f99

Browse files
Fix wrong initialization order introduced in the refactoring commit
DEVSIX-1286
1 parent cab59ed commit 4890f99

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

sign/src/main/java/com/itextpdf/signatures/LtvVerifier.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,12 @@ public class LtvVerifier extends RootStoreVerifier {
104104
*/
105105
public LtvVerifier(PdfDocument document) throws GeneralSecurityException {
106106
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);
115108
}
116109
public LtvVerifier(PdfDocument document, String securityProviderCode) throws GeneralSecurityException {
117-
this(document);
110+
super(null);
118111
this.securityProviderCode = securityProviderCode;
112+
initLtvVerifier(document);
119113
}
120114

121115
/**
@@ -141,29 +135,6 @@ public void setVerifyRootCertificate(boolean verifyRootCertificate) {
141135
this.verifyRootCertificate = verifyRootCertificate;
142136
}
143137

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-
167138
/**
168139
* Verifies all the document-level timestamps and all the signatures in the document.
169140
* @throws IOException
@@ -352,4 +323,38 @@ public List<BasicOCSPResp> getOCSPResponsesFromDSS() throws IOException, General
352323
}
353324
return ocsps;
354325
}
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+
}
355360
}

0 commit comments

Comments
 (0)