Я подписал документ. и я хочу добавить DSS в свой документ.
Security.addProvider(new BouncyCastleProvider());
File signedDocument = new File("/signed.pdf");
File out = new File("/signed_plus_dss");
byte[] buffer = new byte[8 * 1024];
FileInputStream fis = new FileInputStream(signedDocument);
FileOutputStream fos = new FileOutputStream(out);
int c;
while ((c = fis.read(buffer)) != -1) {
fos.write(buffer, 0, c);
}
fis.close();
fis = new FileInputStream(out);
// load document
PDDocument doc = PDDocument.load(signedDocument);
PDDocumentCatalog catalog = doc.getDocumentCatalog();
COSDictionary catalogDictionary = catalog.getCOSDictionary();
COSDictionary dssDictionary = new COSDictionary();
/* ... I can add OCSP responses, and CRLS, and Certs here
in order to create document LTV, but now I don't need that.
I have another problem, not this... */
/* if that's false, nothing happens */
catalogDictionary.setNeedToBeUpdate(true);
catalogDictionary.setItem(COSName.getPDFName("DSS"), dssDictionary);
/* ... if we add here Document level time stamp, everything is fine.
signature will not be invalid with TSA. but it's invalid without TSA ... */
doc.saveIncremental(fis, fos);
Это оно. Все отлично. когда я вижу структуру PDF, появляется Document Security Store. но когда я открываю PDF-файл с помощью Adobe Reader, моя подпись недействительна, потому что - «Документ был изменен или поврежден с момента его подписания» и «1 разное изменение (я)» strong >
но здесь происходит кое-что интересное - если я добавлю Pades-LTV (DSS + TSA), все заработает:
например, если мы добавим эти коды:
URL tsaURL = new URL(TSAUrl);
PDSignature signature = new PDSignature();
signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
signature.setSubFilter(COSName.getPDFName("ETSI.RFC3161"));
signature.setSignDate(Calendar.getInstance());
TimestampeInt signatureInt = new TimestampeInt(tsaURL, null, null);
doc.addSignature(signature, signatureInterface);
doc.saveIncremental(fis, fos);
в результате отметка времени уровня документа работает нормально. Но мне тоже нужно добавить только DSS без TSA. как я могу решить эту проблему, что вы думаете?
образцы документов: Первый образец - подпись плюс только DSS. Второй образец - подпись плюс DSS плюс отметка времени на уровне документа