我正在使用 aws cloudHSM 和 itext7 签署 pdf。一切都很好,直到我没有启用 LTV。
但是在启用 LTV 后出现错误“至少一个签名有问题”并显示签名字节范围无效的原因。
下面是代码
private void ltvEnable(PdfSigner signer, OutputStream baos, String name11,
OcspClientBouncyCastle ocspClient, CrlClientOnline crlClient, CustomTSAClient tsc) {
ByteArrayInputStream signedPdfInput = new ByteArrayInputStream(((ByteArrayOutputStream)baos).toByteArray());
try {
PdfReader pdfReader = new PdfReader(signedPdfInput);
PdfDocument document = new PdfDocument(pdfReader.setUnethicalReading(true), new PdfWriter(baos),
new StampingProperties().useAppendMode());
LtvVerification ltvVerification = new LtvVerification(document);
SignatureUtil signatureUtil = new SignatureUtil(document);
List<String> names = signatureUtil.getSignatureNames();
String sigName = names.get(names.size() - 1);
PdfPKCS7 pkcs7 = signatureUtil.readSignatureData(sigName);
if (pkcs7.isTsp()) {
ltvVerification.addVerification(sigName, ocspClient, crlClient, LtvVerification.CertificateOption.WHOLE_CHAIN,
LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES);
} else {
for (String name : names) {
ltvVerification.addVerification(name, ocspClient, crlClient, LtvVerification.CertificateOption.WHOLE_CHAIN,
LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES);
}
}
ltvVerification.merge();
//signer.timestamp(tsc, null);
document.close();
pdfReader.close();
} catch (IOException | GeneralSecurityException e) {
logger.error("Error while making signature ltv enabled");
}
}
在启用 ltv 之前 -:
后 -: