}
}
}
// Send a OCSP request.
BasicOCSPResp response = OCSPClient.getOCSPResponse(
certificate, issuerCertificate);
if (response == null) {
throw new NoOCSPResponseException(String.format(messages.getString(
"Could_not_get_a_OCSP_response_for_the_certificate__%s"),
CertificateValidator.getCertificateName(certificate)));
}
ocspResponses.add(response);
// Download CRL.
} else if (useCRL) {
// Check if the CRL has already been downloaded.
boolean downloaded = false;
Collection<String> urls = CRLDownloader.getCRLDistributionPoints(certificate);
for (String url : urls) {
if (allCRLDistributionPoints.contains(url)) {
downloaded = true;
} else {
allCRLDistributionPoints.add(url);
}
}
if (downloaded) {
continue;
}
// Download CRL.
X509CRL crl = CRLDownloader.getCRL(certificate);
if (crl == null) {
throw new NoCRLException(String.format(messages.getString(
"Could_not_get_CRL_for_the_certificate__%s"),
CertificateValidator.getCertificateName(certificate)));
}
crls.add(crl);
}
}
// Add signature certificates, OCSP responses and CRLs to global stores.
certMap.put(signature, certificates);
ocspMap.put(signature, ocspResponses);
crlMap.put(signature, crls);
}
// Open output file for writing.
FileOutputStream output = new FileOutputStream(outputFileName);
File temp = File.createTempFile("tmp", ".tmp");
PdfStamper stamper = PdfStamper.createSignature(
reader, output, '\0', temp, true);
// Create a DSS (Document Security Store).
LtvVerification verification = stamper.getLtvVerification();
// Add certificates, OCSP responses and CRLs to DSS.
for (String signature : certMap.keySet()) {
ArrayList<byte[]> certificates = new ArrayList<byte[]>();
for (X509Certificate certificate : certMap.get(signature)) {
certificates.add(certificate.getEncoded());
}
ArrayList<byte[]> ocsps = new ArrayList<byte[]>();
for (BasicOCSPResp response : ocspMap.get(signature)) {
ocsps.add(response.getEncoded());
}
ArrayList<byte[]> crls = new ArrayList<byte[]>();
for (X509CRL crl : crlMap.get(signature)) {
crls.add(crl.getEncoded());
}