Skip to content

Commit 0b7570d

Browse files
committed
PDFBOX-5936: traverse all chains if there are several issuers + reactivate test code from 5203
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1923235 13f79535-47bb-0310-9956-ffa450edef68
1 parent b10b616 commit 0b7570d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

examples/src/main/java/org/apache/pdfbox/examples/signature/validation/CertInformationCollector.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,18 @@ private void traverseChain(X509Certificate certificate, CertSignatureInformation
243243
return;
244244
}
245245

246+
int count = 0;
246247
for (X509Certificate issuer : certificateSet)
247248
{
248249
try
249250
{
250251
certificate.verify(issuer.getPublicKey(), SecurityProvider.getProvider());
251-
LOG.info("Found the right Issuer Cert! for Cert: {}\n{}",
252+
LOG.info("Found issuer for Cert: {}\n{}",
252253
certificate.getSubjectX500Principal(), issuer.getSubjectX500Principal());
253254
certInfo.issuerCertificate = issuer;
254255
certInfo.certChain = new CertSignatureInformation();
255256
traverseChain(issuer, certInfo.certChain, maxDepth - 1);
256-
break;
257+
++count;
257258
}
258259
catch (GeneralSecurityException ex)
259260
{
@@ -267,6 +268,11 @@ private void traverseChain(X509Certificate certificate, CertSignatureInformation
267268
certificate.getSubjectX500Principal() + "', i.e. Cert '" +
268269
certificate.getIssuerX500Principal() + "' is missing in the chain");
269270
}
271+
if (count > 1)
272+
{
273+
// not a bug, see comment by mkl in PDFBOX-5203
274+
LOG.info("Several issuers for Cert: '{}", certificate.getSubjectX500Principal());
275+
}
270276
}
271277

272278
/**

examples/src/test/java/org/apache/pdfbox/examples/pdmodel/TestCreateSignature.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,11 @@ private void checkLTV(File outFile)
963963
{
964964
continue; // not relevant here
965965
}
966-
// disabled until PDFBOX-5203 is fixed
967-
// assertTrue(sigCertHolderSetFromVRIArray.contains(holder),
968-
// "File '" + outFile + "' Root/DSS/VRI/" + hexSignatureHash +
969-
// "/Cert array doesn't contain a certificate with subject '" +
970-
// holder.getSubject() + "' and serial " + holder.getSerialNumber());
966+
assertTrue(sigCertHolderSetFromVRIArray.contains(holder),
967+
"File '" + outFile + "' Root/DSS/VRI/" + hexSignatureHash +
968+
"/Cert array doesn't contain a certificate with subject '" +
969+
holder.getSubject() +
970+
"' and serial " + holder.getSerialNumber().toString(16).toUpperCase());
971971
}
972972
// Get all certificates. Each one should either be issued (= signed) by a certificate of the set
973973
Set<X509Certificate> certSet = new HashSet<>();
@@ -995,9 +995,8 @@ private void checkLTV(File outFile)
995995
// not the issuer
996996
}
997997
}
998-
// disabled until PDFBOX-5203 is fixed
999-
// assertTrue(verified,
1000-
// "Certificate " + cert.getSubjectX500Principal() + " not issued by any certificate in the Certs array");
998+
assertTrue(verified,
999+
"Certificate " + cert.getSubjectX500Principal() + " not issued by any certificate in the Certs array");
10011000
}
10021001
// Each CRL should be signed by one of the certificates in Certs
10031002
Set<X509CRL> crlSet = new HashSet<>();

0 commit comments

Comments
 (0)