I have read many of the questions/answers about how to make a pdf ltv enabled using iText. Neither of them worked for me. I have a steam of pdf and I set a signature field which I then use in order to call signDetached method and sign the pdf. I use:
signer.signDetached(new BouncyCastleDigest(), pks, chain,
Collections.singleton(crlClient), ocspClient, tsc,0, subfilter);
But nothing happened. I have read that you have to include all the certificates except from root. I add the chain of my private certificat (which I use so as to sign pdf), but I have not found a possible way include TSA's certificate.
I use iText version 7.X.
KeyStore ks = getKeyStore();
Certificate[] chain = null;
Enumeration<String> al = ks.aliases();
for (Enumeration<String> l = al; l.hasMoreElements();) {
String alias = (String) l.nextElement();
chain = ks.getCertificateChain(alias);
}
PrivateKey pk = (PrivateKey) ks.getKey(ks.aliases().nextElement(), "******".toCharArray());
IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, BouncyCastleProvider.PROVIDER_NAME);
OCSPVerifier ocspVerifier = new OCSPVerifier(null, null);
OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle(ocspVerifier);
String url = CertificateUtil.getCRLURL((X509Certificate) chain[0]);
CrlClientOnline crlClient = new CrlClientOnline(url);
try {
signer.signDetached(new BouncyCastleDigest(), pks, chain, Collections.singleton(crlClient), ocspClient, tsc,
0, subfilter);
} catch (Exception ex) {
System.out.println("Tzizzzzzzzzzzzzzzz" + ex.getCause());
}
private KeyStore getKeyStore()
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("tsaPath"), "****".toCharArray());
ks.load(new FileInputStream("p12Path"), "*******".toCharArray());
return ks;
}
AdobeLtvEnabling
. Some limitations of that class are listed at the bottom of that answer. If one of those limitations is the issue, that class might be improved to lift that limitation. – mkl