Skip to content

Commit 9c0b4db

Browse files
committed
PKIX: apply the RFC 5280 sec. 6.3.3 (b)(2)(i) distribution point name match and the (d) reasons intersection when either PKIXCertPathReviewer picks a CRL, and report an exception rather than a null one when checkCRL skips every candidate.
1 parent c576fe9 commit 9c0b4db

10 files changed

Lines changed: 623 additions & 0 deletions

File tree

‎ant/jdk14.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
<exclude name="**/cert/ocsp/test/PKIXOcspRevocationCheckerTest.java"/>
253253
<exclude name="**/pkcs/test/PBETest.java"/>
254254
<exclude name="**/pkix/test/PKIXCertPathReviewerCrlReasonTest.java"/>
255+
<exclude name="**/pkix/test/PKIXCertPathReviewerCrlScopeTest.java"/>
255256
<exclude name="**/cert/c509/**/*.java"/>
256257
</fileset>
257258
<fileset dir="mail/src/test/java">

‎docs/releasenotes.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Date: 2026, TBD
3939
- The PKCS#12 key stores wrote the MAC key-derivation parameters of a file they had loaded into every file they wrote afterwards, under whatever password the caller stored with. For PKCS12-PBMAC1 that carried the loaded file's PBKDF2 salt, iteration count, key length and PRF, because the parameters were minted only when the store held none and were then assigned back, so the branch ran once per store object rather than once per write - which also meant one store reused a single PBKDF2 salt across every write, including writes under different passwords, with no file loaded at all. The classic store inherited the MAC salt length and digest algorithm the same way, so a file declaring a zero-length MAC salt was re-stored with one, and a file it had loaded under RFC 9579 handed on that file's PBKDF2 salt too, both stores reading PBMAC1. The values were also latched before the MAC was verified and were not cleared by the load(null, null) a caller must issue to recover, so a file that failed the check left them behind for the caller's own file. The PBKDF2 salt and the MAC salt are now generated for every write, the MAC salt at no fewer than 8 octets, nothing is latched until the file has verified, and an AlgorithmIdentifier supplied through a PKCS12StoreParameter is still written as it was given. A loaded file's PRF, key length, digest algorithm and MacData iteration count are still kept, the last as before; the PBKDF2 count is kept where it is at least the count being written with and raised to it otherwise, since the file being re-stored is not the one that count was chosen for - RFC 9579's own test vectors ask for 2048. That count is now org.bouncycastle.pkcs12.pbkdf2_it_count, default 65,536, the write-side counterpart for a PBMAC1 MAC of what org.bouncycastle.pkcs12.store_it_count is for the PBE. Reading is unaffected: a file's MAC is verified with the parameters it carries, whatever they are (github #2450).
4040
- Cipher.SM9 took its data-encapsulation mode for decryption from the ciphertext rather than from the mode the Cipher was configured with. The GM/T 0080-2020 SM9Cipher structure names the mode in an enType field, but GM/T 0044.4 defines the authenticator as C3 = MAC(K2, C2), over the encapsulated message alone, so enType is not covered by it: re-encoding a ciphertext with the other enType leaves C1, C3 and C2 untouched and steers the recipient into the other mode. GM/T 0044.4 takes K1 and K2 from a single KDF output of klen = mlen + K2_len bits in stream mode and K1_len + K2_len bits in SM4 mode, where K1_len = 128, so when C2 is 16 bytes long the two modes make the identical KDF call and derive the same K1 and K2: a one-block SM4 ciphertext relabelled as stream mode passes the MAC check and the recipient returns K1 xor C2 - from which both the SM4 key K1 and the padded plaintext block follow, wherever that output is observable. CipherSpi now decrypts in the configured mode and rejects a ciphertext whose enType disagrees with it, so the mode is symmetric between encryption and decryption. That check compares two values a relabelling attacker can make agree, and so does not by itself protect a recipient whose Cipher is configured for stream mode - the relabelled one-block ciphertext then matches the configuration - so SM9Engine additionally refuses a 16-byte C2, the one C2 length at which the two modes collide, in both modes and both directions: on decryption, and on encryption a 16-byte message in stream mode and a message of fewer than 16 bytes, which pads to one block, in SM4 mode. Refusing the length on decryption protects the recipient that does so, but the message a relabelled ciphertext gives away is the SM4-mode sender's, who cannot tell whether the recipient's implementation refuses it, which is why the SM4 mode no longer produces one; messages of every other length are unchanged in both modes. A stream-mode ciphertext must accordingly be decrypted through a stream-mode Cipher ("SM9/XOR/NoPadding") rather than the SM4-mode default that Cipher.getInstance("SM9") gives; a message of fewer than 16 bytes has to be sent in stream mode, and one of exactly 16 bytes - a 128-bit key, say - in SM4 mode; and a ciphertext made by an earlier version whose C2 is 16 bytes long is no longer decrypted, whichever mode wrote it - a one-block SM4-mode ciphertext, or a stream-mode one carrying a 16-byte message. The SM9 KEM is unaffected.
4141
- Decrypting an OpenPGP message in two steps - recovering the session key from a SKESK packet and then decrypting the SEIPD v1 body through PGPEncryptedDataList.extractSessionKeyEncryptedData() - stopped detecting a wrong passphrase. 1.86 suppressed the legacy CFB "quick check" on the two repeated prefix bytes for every session-key decryption, to close the Mister-Zuccherato oracle on the path a PKESK session key reaches, but the same class also carries password-derived session keys, where reporting the check is what identifies a wrong passphrase and lets the next passphrase or SKESK packet be tried. A SKESK v4 packet deriving the session key from the S2K output directly (no encrypted session key) yields a well formed session key for any passphrase, so a wrong one no longer failed at all: it surfaced as a parse or integrity failure further down the stream. BouncyCastle's own high-level API decrypts this way, so OpenPGPMessageProcessor took the first wrong passphrase offered for a success and never tried the remaining ones. A new PGPEncryptedDataList.extractSessionKeyEncryptedData(boolean) states whether the session key came from a password: true restores the check and with it the PGPDataValidationException on a wrong passphrase, the existing no-argument method goes on suppressing it, and the high-level API passes true on its passphrase paths alone, so a session key recovered from a public key operation is still never quick checked (github #2459).
42+
- Both copies of PKIXCertPathReviewer (org.bouncycastle.pkix.jcajce and the legacy org.bouncycastle.x509) took the first date-valid CRL issued by the certificate's issuer as an answer about that certificate, applying neither of the RFC 5280 sec. 6.3.3 rules that decide whether a CRL covers it: the (b)(2)(i) match between a name in the CRL's issuing distribution point and a name in the certificate's distribution point, and the (d) intersection of the revocation reasons the two assert. Only the (b)(2)(ii) to (iv) onlyContains booleans were applied. A CA-signed, in-date CRL with no entries, scoped to another distribution point or to a partition of the revocation reasons, was therefore reported as proof of non-revocation - isValidCertPath() true with an empty error list for a certificate its own CA had revoked for key compromise, where CertPathValidator("PKIX") rejects the same chain against the same trust anchor - and it suppressed the distribution point fetch that would otherwise have retrieved the authoritative CRL. Where the reviewer makes the trust decision rather than serving as diagnostics beside a real validation this is a revocation bypass, and SignedMailValidator (bcmail) reaches it with the CRLs carried inside the signed message. Both copies now apply the (b)(2)(i) name match and require a CRL to cover every revocation reason before it can settle the certificate's status, through the public PKIXCRLValidator helpers the validation engine already uses, and keep looking when a candidate does not qualify - falling back, as before, to the distribution point fetch and then to the existing "no valid CRL found" error. A CRL carrying no issuing distribution point, one naming the certificate's own distribution point, and one naming the certificate issuer (the distribution point the engine falls back to) are all still accepted.
43+
- RFC3280CertPathUtilities.checkCRL threw java.lang.NullPointerException rather than a CertPathValidatorException when every candidate CRL for a distribution point was skipped instead of rejected, which is what happens when the reasons a CRL covers add nothing to those already checked - the RFC 5280 sec. 6.3.3 (d) case - since the exception it rethrows is only ever recorded in a catch block. Validation failed closed either way, but outside the declared contract of CertPathValidator.validate(); a run with nothing recorded now reports "No valid CRL found.". All four copies are corrected: pkix, prov, and the prov jdk1.3 and jdk1.4 overlays.
4244

4345
### 2.1.3 Additional Features and Functionality
4446

‎pkix/src/main/java/org/bouncycastle/pkix/jcajce/PKIXCertPathReviewer.java‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@
4848
import org.bouncycastle.asn1.ASN1Primitive;
4949
import org.bouncycastle.asn1.ASN1Sequence;
5050
import org.bouncycastle.asn1.ASN1TaggedObject;
51+
import org.bouncycastle.asn1.x500.X500Name;
5152
import org.bouncycastle.asn1.x509.AccessDescription;
5253
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
5354
import org.bouncycastle.asn1.x509.AuthorityInformationAccess;
5455
import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier;
5556
import org.bouncycastle.asn1.x509.BasicConstraints;
5657
import org.bouncycastle.asn1.x509.CRLDistPoint;
58+
import org.bouncycastle.asn1.x509.CRLValidatorException;
5759
import org.bouncycastle.asn1.x509.DistributionPoint;
5860
import org.bouncycastle.asn1.x509.DistributionPointName;
5961
import org.bouncycastle.asn1.x509.Extension;
@@ -62,6 +64,7 @@
6264
import org.bouncycastle.asn1.x509.GeneralSubtree;
6365
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
6466
import org.bouncycastle.asn1.x509.NameConstraints;
67+
import org.bouncycastle.asn1.x509.PKIXCRLValidator;
6568
import org.bouncycastle.asn1.x509.PolicyInformation;
6669
import org.bouncycastle.jcajce.PKIXPolicyNode;
6770
import org.bouncycastle.asn1.x509.qualified.Iso4217CurrencyCode;
@@ -2140,6 +2143,8 @@ protected void checkCRLs(
21402143
crl_iter = new ArrayList().iterator();
21412144
}
21422145

2146+
DistributionPoint[] distPoints = getDistributionPoints(cert);
2147+
21432148
boolean validCrlFound = false;
21442149
X509CRL crl = null;
21452150
while (crl_iter.hasNext())
@@ -2152,6 +2157,13 @@ protected void checkCRLs(
21522157

21532158
if (nextUpdate == null || validDate.before(nextUpdate))
21542159
{
2160+
// a CRL only says something about this certificate if its scope covers it - keep looking otherwise, rather than taking an out of scope CRL from the issuer as proof of non-revocation.
2161+
if (!isScopedToCertificate(crl, distPoints, cert))
2162+
{
2163+
crl = null;
2164+
continue;
2165+
}
2166+
21552167
validCrlFound = true;
21562168
ErrorBundle msg = createErrorBundle( "CertPathReviewer.localValidCRL", arguments);
21572169
addNotification(msg,index);
@@ -2448,6 +2460,117 @@ protected void checkCRLs(
24482460
}
24492461
}
24502462

2463+
/**
2464+
* The distribution points a CRL may be scoped to for the passed in certificate: the ones in the
2465+
* certificate's CRL distribution points extension, followed by a distribution point naming the
2466+
* certificate issuer, which is what the cert path validation engine falls back to for a CRL the
2467+
* certificate's own distribution points do not name.
2468+
*/
2469+
private DistributionPoint[] getDistributionPoints(X509Certificate cert)
2470+
{
2471+
List dps = new ArrayList();
2472+
2473+
try
2474+
{
2475+
ASN1Primitive ext = getExtensionValue(cert, CRL_DIST_POINTS);
2476+
if (ext != null)
2477+
{
2478+
DistributionPoint[] points = CRLDistPoint.getInstance(ext).getDistributionPoints();
2479+
for (int i = 0; i != points.length; i++)
2480+
{
2481+
dps.add(points[i]);
2482+
}
2483+
}
2484+
}
2485+
catch (Exception e)
2486+
{
2487+
// a distribution points extension which will not decode is reported by the caller
2488+
}
2489+
2490+
try
2491+
{
2492+
X500Name issuer = X500Name.getInstance(getEncodedIssuerPrincipal(cert).getEncoded());
2493+
2494+
dps.add(new DistributionPoint(new DistributionPointName(0,
2495+
new GeneralNames(new GeneralName(GeneralName.directoryName, issuer))), null, null));
2496+
}
2497+
catch (Exception e)
2498+
{
2499+
// an issuer which will not re-encode leaves the certificate's own distribution points
2500+
}
2501+
2502+
return (DistributionPoint[])dps.toArray(new DistributionPoint[dps.size()]);
2503+
}
2504+
2505+
/**
2506+
* Whether the passed in CRL is in scope for the certificate under test, applying the RFC 5280
2507+
* sec. 6.3.3 (b)(2)(i) distribution point name match and the sec. 6.3.3 (d) reasons intersection
2508+
* that {@link PKIXCRLValidator} implements for the cert path validation engine. A CRL carrying no
2509+
* issuing distribution point is in scope for everything its issuer issues; one whose scope cannot
2510+
* be read, or which covers only some revocation reasons, is not evidence about this certificate.
2511+
*/
2512+
private boolean isScopedToCertificate(X509CRL crl, DistributionPoint[] distPoints, X509Certificate cert)
2513+
{
2514+
IssuingDistributionPoint idp;
2515+
try
2516+
{
2517+
ASN1Primitive idpExt = getExtensionValue(crl, ISSUING_DISTRIBUTION_POINT);
2518+
if (idpExt == null)
2519+
{
2520+
return true;
2521+
}
2522+
2523+
idp = IssuingDistributionPoint.getInstance(idpExt);
2524+
}
2525+
catch (Exception e)
2526+
{
2527+
return false;
2528+
}
2529+
2530+
for (int i = 0; i != distPoints.length; i++)
2531+
{
2532+
if (isScopedToDistributionPoint(idp, distPoints[i], crl, cert))
2533+
{
2534+
return true;
2535+
}
2536+
}
2537+
2538+
return false;
2539+
}
2540+
2541+
private boolean isScopedToDistributionPoint(IssuingDistributionPoint idp, DistributionPoint dp, X509CRL crl,
2542+
X509Certificate cert)
2543+
{
2544+
try
2545+
{
2546+
X500Name crlIssuer = null;
2547+
if (PKIXCRLValidator.requiresCRLIssuer(idp))
2548+
{
2549+
crlIssuer = X500Name.getInstance(crl.getIssuerX500Principal().getEncoded());
2550+
}
2551+
2552+
X500Name certIssuer = null;
2553+
if (PKIXCRLValidator.requiresCertificateIssuer(idp, dp))
2554+
{
2555+
certIssuer = X500Name.getInstance(getEncodedIssuerPrincipal(cert).getEncoded());
2556+
}
2557+
2558+
// (b) (2) (i)
2559+
PKIXCRLValidator.checkDistributionPointName(idp, dp, crlIssuer, certIssuer);
2560+
}
2561+
catch (CRLValidatorException e)
2562+
{
2563+
return false;
2564+
}
2565+
catch (Exception e)
2566+
{
2567+
return false;
2568+
}
2569+
2570+
// (d) - the reviewer takes its answer from a single CRL, so one covering only some of the reasons cannot settle the certificate's status on its own.
2571+
return PKIXCRLValidator.intersectReasons(idp, dp) == PKIXCRLValidator.ALL_REASONS;
2572+
}
2573+
24512574
protected Vector getCRLDistUrls(CRLDistPoint crlDistPoints)
24522575
{
24532576
Vector urls = new Vector();

‎pkix/src/main/java/org/bouncycastle/pkix/jcajce/RFC3280CertPathUtilities.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ static void checkCRL(
808808
}
809809
if (!validCrlFound)
810810
{
811+
// every candidate was skipped rather than rejected - the reasons they cover add nothing to the mask - so there is no exception to report.
812+
if (lastException == null)
813+
{
814+
throw new AnnotatedException("No valid CRL found.");
815+
}
816+
811817
throw lastException;
812818
}
813819
}

‎pkix/src/test/java/org/bouncycastle/pkix/test/AllTests.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static Test suite()
2727
suite.addTestSuite(QcStatementReviewerTest.class);
2828
suite.addTestSuite(PKIXCertPathReviewerPolicyTreeTest.class);
2929
suite.addTestSuite(PKIXCertPathReviewerCrlReasonTest.class);
30+
suite.addTestSuite(PKIXCertPathReviewerCrlScopeTest.class);
3031

3132
return new BCTestSetup(suite);
3233
}

0 commit comments

Comments
 (0)