@@ -420,26 +420,13 @@ public PdfPadesSigner setTrustedCertificates(List<Certificate> certificateList)
420
420
return this ;
421
421
}
422
422
423
- private void performTimestamping (PdfDocument document , OutputStream outputStream , ITSAClient tsaClient )
423
+ void performTimestamping (PdfDocument document , OutputStream outputStream , ITSAClient tsaClient )
424
424
throws IOException , GeneralSecurityException {
425
425
PdfSigner timestampSigner = new PdfSigner (document , outputStream , tempOutputStream , tempFile );
426
426
timestampSigner .timestamp (tsaClient , timestampSignatureName );
427
427
}
428
428
429
- private void performSignDetached (SignerProperties signerProperties , boolean isFinal ,
430
- IExternalSignature externalSignature , Certificate [] chain , ITSAClient tsaClient )
431
- throws GeneralSecurityException , IOException {
432
- Certificate [] fullChain = issuingCertificateRetriever .retrieveMissingCertificates (chain );
433
- PdfSigner signer = createPdfSigner (signerProperties , isFinal );
434
- try {
435
- signer .signDetached (externalDigest , externalSignature , fullChain , null , null , tsaClient ,
436
- estimatedSize , CryptoStandard .CADES );
437
- } finally {
438
- signer .originalOS .close ();
439
- }
440
- }
441
-
442
- private PdfSigner createPdfSigner (SignerProperties signerProperties , boolean isFinal ) throws IOException {
429
+ PdfSigner createPdfSigner (SignerProperties signerProperties , boolean isFinal ) throws IOException {
443
430
String tempFilePath = null ;
444
431
if (temporaryDirectoryPath != null ) {
445
432
tempFilePath = getNextTempFile ().getAbsolutePath ();
@@ -464,7 +451,7 @@ private PdfSigner createPdfSigner(SignerProperties signerProperties, boolean isF
464
451
return signer ;
465
452
}
466
453
467
- private void performLtvVerification (PdfDocument pdfDocument , List <String > signatureNames ,
454
+ void performLtvVerification (PdfDocument pdfDocument , List <String > signatureNames ,
468
455
LtvVerification .RevocationDataNecessity revocationDataNecessity )
469
456
throws IOException , GeneralSecurityException {
470
457
LtvVerification ltvVerification = new LtvVerification (pdfDocument )
@@ -478,43 +465,28 @@ private void performLtvVerification(PdfDocument pdfDocument, List<String> signat
478
465
ltvVerification .merge ();
479
466
}
480
467
481
- private void deleteTempFiles () {
468
+ void deleteTempFiles () {
482
469
for (File tempFile : tempFiles ) {
483
470
tempFile .delete ();
484
471
}
485
472
}
486
473
487
- private OutputStream createOutputStream () throws FileNotFoundException {
474
+ OutputStream createOutputStream () throws FileNotFoundException {
488
475
if (temporaryDirectoryPath != null ) {
489
476
return FileUtil .getFileOutputStream (getNextTempFile ());
490
477
}
491
478
tempOutputStream = new ByteArrayOutputStream ();
492
479
return tempOutputStream ;
493
480
}
494
481
495
- private InputStream createInputStream () throws IOException {
482
+ InputStream createInputStream () throws IOException {
496
483
if (temporaryDirectoryPath != null ) {
497
484
return FileUtil .getInputStreamForFile (tempFile );
498
485
}
499
486
return new ByteArrayInputStream (tempOutputStream .toByteArray ());
500
487
}
501
488
502
- private File getNextTempFile () {
503
- if (!FileUtil .directoryExists (temporaryDirectoryPath )) {
504
- throw new PdfException (MessageFormatUtil .format (SignExceptionMessageConstant .PATH_IS_NOT_DIRECTORY ,
505
- temporaryDirectoryPath ));
506
- }
507
- synchronized (LOCK_OBJECT ) {
508
- do {
509
- increment ++;
510
- tempFile = new File (temporaryDirectoryPath + "/" + TEMP_FILE_NAME + increment + ".pdf" );
511
- } while (tempFile .exists ());
512
- tempFiles .add (tempFile );
513
- }
514
- return tempFile ;
515
- }
516
-
517
- private void createRevocationClients (Certificate signingCert , boolean clientsRequired ) {
489
+ void createRevocationClients (Certificate signingCert , boolean clientsRequired ) {
518
490
if (crlClient == null && ocspClient == null && clientsRequired ) {
519
491
X509Certificate signingCertificate = (X509Certificate ) signingCert ;
520
492
if (CertificateUtil .getOCSPURL (signingCertificate ) == null &&
@@ -530,6 +502,34 @@ private void createRevocationClients(Certificate signingCert, boolean clientsReq
530
502
}
531
503
}
532
504
505
+ private void performSignDetached (SignerProperties signerProperties , boolean isFinal ,
506
+ IExternalSignature externalSignature , Certificate [] chain , ITSAClient tsaClient )
507
+ throws GeneralSecurityException , IOException {
508
+ Certificate [] fullChain = issuingCertificateRetriever .retrieveMissingCertificates (chain );
509
+ PdfSigner signer = createPdfSigner (signerProperties , isFinal );
510
+ try {
511
+ signer .signDetached (externalDigest , externalSignature , fullChain , null , null , tsaClient ,
512
+ estimatedSize , CryptoStandard .CADES );
513
+ } finally {
514
+ signer .originalOS .close ();
515
+ }
516
+ }
517
+
518
+ private File getNextTempFile () {
519
+ if (!FileUtil .directoryExists (temporaryDirectoryPath )) {
520
+ throw new PdfException (MessageFormatUtil .format (SignExceptionMessageConstant .PATH_IS_NOT_DIRECTORY ,
521
+ temporaryDirectoryPath ));
522
+ }
523
+ synchronized (LOCK_OBJECT ) {
524
+ do {
525
+ increment ++;
526
+ tempFile = new File (temporaryDirectoryPath + "/" + TEMP_FILE_NAME + increment + ".pdf" );
527
+ } while (tempFile .exists ());
528
+ tempFiles .add (tempFile );
529
+ }
530
+ return tempFile ;
531
+ }
532
+
533
533
private String getDigestAlgorithm (PrivateKey privateKey ) {
534
534
String signatureAlgorithm = SignUtils .getPrivateKeyAlgorithm (privateKey );
535
535
switch (signatureAlgorithm ) {
0 commit comments