for (Object object : root) {
rootCertificates.add((X509Certificate) object);
}
// Open the document for reading.
PdfReader reader = new PdfReader(documentFileName);
// Get the signatures in the document.
AcroFields fields = reader.getAcroFields();
ArrayList<String> signatures = fields.getSignatureNames();
if (signatures.size() == 0) {
throw new NoSignatureException(messages.getString(
"Document_has_no_signature."));
}
// Check if the last signature is a timestamp.
String lastSignature = signatures.get(signatures.size() - 1);
PdfPKCS7 pkcs7 = fields.verifySignature(lastSignature);
if (!pkcs7.isTsp()) {
throw new NoTimestampException(messages.getString(
"Document_has_no_document_level_timestamp."));
}
// Get the expiration date of the last timestamp.
Calendar expiration = Calendar.getInstance();
expiration.setTime(pkcs7.getSigningCertificate().getNotAfter());
// Validate last timestamp on the current date.
SignatureValidator.validate(lastSignature, reader, rootCertificates);
// Get OCSP responses and CRLs from DSS to validate old signatures.
PdfDictionary dictionary = reader.getCatalog().getAsDict(PdfName.DSS);
if (dictionary == null) {
throw new NoDSSException(messages.getString(
"Document_has_no_DSS_(Document_Security_Store)."));
}
PdfArray ocspArray = dictionary.getAsArray(PdfName.OCSPS);