Skip to content

Commit a5e172b

Browse files
committed
The three java.security.cert.X509CRL accessors no longer let an unchecked exception escape when an indirect CRL carries an entry whose certificateIssuer does not decode to a directoryName, getRevokedCertificates(), getRevokedCertificate(BigInteger) and isRevoked(Certificate) having re-parsed it as GeneralNames.getInstance(...).getNames()[0] in both X509CRLImpl and the deprecated jce.provider.X509CRLObject the registered X509StreamParser.CRL service returns, which also refused the well-formed encoding that names the directoryName after another GeneralName although X509CRLEntryObject read the same CRL correctly, so all six sites now share that sibling's logic, promoted to a package-private static in each of the two packages, and an entry naming no directoryName is treated as having no certificate issuer of its own, which java.security.cert.X509CRLEntry defines as the CRL issuer's, relates to github #2425.
1 parent 76020c6 commit a5e172b

11 files changed

Lines changed: 164 additions & 138 deletions

File tree

‎docs/releasenotes.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Date: 2026, TBD
172172
- The GOST R 34.10-2001 / 2012 signer (org.bouncycastle.crypto.signers.ECGOST3410Signer, and ECGOST3410_2012Signer which extends it) drew its per-signature nonce uniformly over the bit length of the group order and rejected only a draw of zero, where the GOST R 34.10-94 signer beside it already redraws anything at or past the order. A draw that landed at or past n was therefore not discarded but folded to k mod n by the reductions that followed, which makes the bottom of the range likelier than the top. On most of the named curves that costs nothing - the order is either just below the next power of two, so such a draw essentially never happens, or close to half of it, so the fold covers the range exactly twice and the result stays uniform - but on the three whose order is about 0.61 of 2^256 (GostR3410-2001-CryptoPro-C, GostR3410-2001-CryptoPro-XchB and Tc26-Gost-3410-12-256-paramSetD) the bottom 64.5% of the range takes 78.4% of the draws, so a nonce fell below n/2 about 61% of the time rather than 50%. A nonce that is not uniform over [1, n-1] is the input a lattice attack on the signing key consumes, and while no key recovery is demonstrated here, the scheme's security argument assumes a uniform one. The nonce is now redrawn until it is below the order, as the GOST R 34.10-94 signer does. That signer had the mirror of the same gap and is corrected with it: it redrew a nonce at or past q but accepted one of zero, which is the single value that gives the signing key away outright - the blinded exponent becomes a multiple of q, so r is 1 and s = k * m + x * r collapses to x. It is a 2^-256 draw, but free to close, and it is now redrawn like any other unusable value. A caller supplying a deterministic stream of test randomness will see further bytes requested where a draw is out of range and previously was not redrawn; the GOST R 34.10 vectors all draw in range and are unaffected. Note the redraw is also what the constant-time assembly above depends on, since that rejects rather than reduces an operand at or past the modulus.
173173
- org.bouncycastle.openpgp.api.DoubleBufferedInputStream has been removed. The class has been present since 1.81, to withhold a trailing window of decrypted data so that unauthenticated plaintext is not emitted, but it was never referenced by anything in the library - no class in any source tree constructed one, and no policy or setting connected it to the decryption pipeline - and it did not work. Its read() returned the buffered byte unmasked, so every byte from 0x80 upwards came back negative and 0xFF came back as -1, which a caller reads as end of stream: data was silently corrupted and then silently truncated. Reading an OpenPGP message through one failed on the first packet, the new-format tag octet 0xCB being read as -53. Its read(byte[], int, int) also returned 0 where the underlying stream returned 0, which the InputStream contract does not allow. Beyond that it never filled its buffers, taking whatever a single read of the underlying stream returned, so the amount withheld was one read rather than the configured buffer size - for a tampered five megabyte message a corrected version of the class still released all but about 1.7 kilobytes of the plaintext with a one megabyte buffer. It is removed rather than repaired: it was unusable as shipped, nothing in the library depended on it, and the withholding it offered was not the guarantee its documentation described. This is a removal from the exported org.bouncycastle.openpgp.api package, so it is a public API change, but no caller can have been reading data through one successfully. Note that the high-level decryption API still hands version 1 (MDC) integrity-protected plaintext to a streaming caller before the integrity check runs at end of stream, so callers must not act on data read from an OpenPGPMessageInputStream until close() has returned without error; version 2 (AEAD) messages are unaffected, each chunk being authenticated before it is released (github #2424).
174174

175+
- The three X509CRL accessors let an unchecked exception escape when an indirect CRL carried an entry whose certificateIssuer extension did not decode to a directoryName. getRevokedCertificates(), getRevokedCertificate(BigInteger) and isRevoked(Certificate) each re-parsed the extension with GeneralNames.getInstance(...).getNames()[0], which raises ArrayIndexOutOfBoundsException for an empty GeneralNames and IllegalArgumentException for a first GeneralName that is not a directoryName, neither of them declared by java.security.cert.X509CRL, so a caller guarding only the CRLException the API names did not catch them; a CRL is routinely fetched and parsed before its signature is checked, so the bytes reaching these methods are not necessarily trusted. The same three sites appear again in the deprecated org.bouncycastle.jce.provider.X509CRLObject, which the registered X509StreamParser.CRL service returns, and in the jdk1.1 and jdk1.3 overlays of both classes. This was not only a robustness problem: because the parse assumed the directoryName was first, a CRL naming its entry issuer as a directoryName after some other GeneralName - a well-formed encoding, GeneralNames being a SEQUENCE OF with no ordering requirement - was refused as well, while X509CRLEntryObject, which iterates for the directoryName inside a try/catch, read the same CRL correctly. All six call sites now use that sibling's logic, which has been promoted to a package-private static in each of the two packages rather than left as a fourth hand-written copy, so the accessors and the entry objects can no longer disagree about the same CRL. An entry whose certificateIssuer names no directoryName is treated as having no certificate issuer of its own, which java.security.cert.X509CRLEntry.getCertificateIssuer() defines as the CRL issuer's, so isRevoked reports such an entry against the CRL issuer rather than throwing (github #2425).
176+
175177

176178
### 2.1.3 Additional Features and Functionality
177179

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/x509/X509CRLEntryObject.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected X509CRLEntryObject(
7070
X500Name previousCertificateIssuer)
7171
{
7272
this.c = c;
73-
this.certificateIssuer = loadCertificateIssuer(isIndirect, previousCertificateIssuer);
73+
this.certificateIssuer = loadCertificateIssuer(c, isIndirect, previousCertificateIssuer);
7474
}
7575

7676
/**
@@ -84,7 +84,7 @@ public boolean hasUnsupportedCriticalExtension()
8484
return extensions != null && extensions.hasAnyCriticalExtensions();
8585
}
8686

87-
private X500Name loadCertificateIssuer(boolean isIndirect, X500Name previousCertificateIssuer)
87+
static X500Name loadCertificateIssuer(TBSCertList.CRLEntry c, boolean isIndirect, X500Name previousCertificateIssuer)
8888
{
8989
if (!isIndirect)
9090
{

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/x509/X509CRLImpl.java‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.bouncycastle.asn1.x509.CertificateList;
4646
import org.bouncycastle.asn1.x509.Extension;
4747
import org.bouncycastle.asn1.x509.Extensions;
48-
import org.bouncycastle.asn1.x509.GeneralNames;
4948
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
5049
import org.bouncycastle.asn1.x509.TBSCertList;
5150
import org.bouncycastle.asn1.x509.Time;
@@ -431,15 +430,7 @@ private Set loadCRLEntries()
431430
TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement();
432431
X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
433432
entrySet.add(crlEntry);
434-
if (isIndirect && entry.hasExtensions())
435-
{
436-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
437-
438-
if (currentCaName != null)
439-
{
440-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
441-
}
442-
}
433+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
443434
}
444435

445436
return entrySet;
@@ -459,15 +450,7 @@ public X509CRLEntry getRevokedCertificate(BigInteger serialNumber)
459450
return new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
460451
}
461452

462-
if (isIndirect && entry.hasExtensions())
463-
{
464-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
465-
466-
if (currentCaName != null)
467-
{
468-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
469-
}
470-
}
453+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
471454
}
472455

473456
return null;
@@ -656,14 +639,10 @@ public boolean isRevoked(Certificate cert)
656639
{
657640
TBSCertList.CRLEntry entry = TBSCertList.CRLEntry.getInstance(certs.nextElement());
658641

659-
if (isIndirect && entry.hasExtensions())
642+
caName = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, caName);
643+
if (caName == null)
660644
{
661-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
662-
663-
if (currentCaName != null)
664-
{
665-
caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
666-
}
645+
caName = c.getIssuer(); // an entry with no certificate issuer of its own is the CRL issuer's
667646
}
668647

669648
if (entry.getUserCertificate().hasValue(serial))

‎prov/src/main/java/org/bouncycastle/jce/provider/X509CRLEntryObject.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public X509CRLEntryObject(
6969
X500Name previousCertificateIssuer)
7070
{
7171
this.c = c;
72-
this.certificateIssuer = loadCertificateIssuer(isIndirect, previousCertificateIssuer);
72+
this.certificateIssuer = loadCertificateIssuer(c, isIndirect, previousCertificateIssuer);
7373
}
7474

7575
/**
@@ -83,7 +83,7 @@ public boolean hasUnsupportedCriticalExtension()
8383
return extensions != null && extensions.hasAnyCriticalExtensions();
8484
}
8585

86-
private X500Name loadCertificateIssuer(boolean isIndirect, X500Name previousCertificateIssuer)
86+
static X500Name loadCertificateIssuer(TBSCertList.CRLEntry c, boolean isIndirect, X500Name previousCertificateIssuer)
8787
{
8888
if (!isIndirect)
8989
{

‎prov/src/main/java/org/bouncycastle/jce/provider/X509CRLObject.java‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.bouncycastle.asn1.x509.CertificateList;
3939
import org.bouncycastle.asn1.x509.Extension;
4040
import org.bouncycastle.asn1.x509.Extensions;
41-
import org.bouncycastle.asn1.x509.GeneralNames;
4241
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
4342
import org.bouncycastle.asn1.x509.TBSCertList;
4443
import org.bouncycastle.asn1.x509.Time;
@@ -315,15 +314,7 @@ private Set loadCRLEntries()
315314
TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement();
316315
X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
317316
entrySet.add(crlEntry);
318-
if (isIndirect && entry.hasExtensions())
319-
{
320-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
321-
322-
if (currentCaName != null)
323-
{
324-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
325-
}
326-
}
317+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
327318
}
328319

329320
return entrySet;
@@ -343,15 +334,7 @@ public X509CRLEntry getRevokedCertificate(BigInteger serialNumber)
343334
return new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
344335
}
345336

346-
if (isIndirect && entry.hasExtensions())
347-
{
348-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
349-
350-
if (currentCaName != null)
351-
{
352-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
353-
}
354-
}
337+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
355338
}
356339

357340
return null;
@@ -556,14 +539,10 @@ public boolean isRevoked(Certificate cert)
556539
{
557540
TBSCertList.CRLEntry entry = TBSCertList.CRLEntry.getInstance(certs.nextElement());
558541

559-
if (isIndirect && entry.hasExtensions())
542+
caName = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, caName);
543+
if (caName == null)
560544
{
561-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
562-
563-
if (currentCaName != null)
564-
{
565-
caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
566-
}
545+
caName = c.getIssuer(); // an entry with no certificate issuer of its own is the CRL issuer's
567546
}
568547

569548
if (entry.getUserCertificate().hasValue(serial))

‎prov/src/main/jdk1.1/org/bouncycastle/jce/provider/X509CRLObject.java‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.bouncycastle.asn1.x509.CertificateList;
3535
import org.bouncycastle.asn1.x509.Extension;
3636
import org.bouncycastle.asn1.x509.Extensions;
37-
import org.bouncycastle.asn1.x509.GeneralNames;
3837
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
3938
import org.bouncycastle.asn1.x509.TBSCertList;
4039
import org.bouncycastle.asn1.x509.Time;
@@ -260,15 +259,7 @@ private Set loadCRLEntries()
260259
TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement();
261260
X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
262261
entrySet.add(crlEntry);
263-
if (isIndirect && entry.hasExtensions())
264-
{
265-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
266-
267-
if (currentCaName != null)
268-
{
269-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
270-
}
271-
}
262+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
272263
}
273264

274265
return entrySet;
@@ -288,15 +279,7 @@ public X509CRLEntry getRevokedCertificate(BigInteger serialNumber)
288279
return new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
289280
}
290281

291-
if (isIndirect && entry.hasExtensions())
292-
{
293-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
294-
295-
if (currentCaName != null)
296-
{
297-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
298-
}
299-
}
282+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
300283
}
301284

302285
return null;
@@ -499,14 +482,10 @@ public boolean isRevoked(Certificate cert)
499482

500483
for (int i = 0; i < certs.length; i++)
501484
{
502-
if (isIndirect && certs[i].hasExtensions())
485+
caName = X509CRLEntryObject.loadCertificateIssuer(certs[i], isIndirect, caName);
486+
if (caName == null)
503487
{
504-
Extension currentCaName = certs[i].getExtensions().getExtension(Extension.certificateIssuer);
505-
506-
if (currentCaName != null)
507-
{
508-
caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
509-
}
488+
caName = c.getIssuer(); // an entry with no certificate issuer of its own is the CRL issuer's
510489
}
511490

512491
if (certs[i].getUserCertificate().getValue().equals(serial))

‎prov/src/main/jdk1.3/org/bouncycastle/jcajce/provider/asymmetric/x509/X509CRLEntryObject.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public X509CRLEntryObject(
7070
X500Name previousCertificateIssuer)
7171
{
7272
this.c = c;
73-
this.certificateIssuer = loadCertificateIssuer(isIndirect, previousCertificateIssuer);
73+
this.certificateIssuer = loadCertificateIssuer(c, isIndirect, previousCertificateIssuer);
7474
}
7575

7676
/**
@@ -84,7 +84,7 @@ public boolean hasUnsupportedCriticalExtension()
8484
return extensions != null && extensions.hasAnyCriticalExtensions();
8585
}
8686

87-
private X500Name loadCertificateIssuer(boolean isIndirect, X500Name previousCertificateIssuer)
87+
static X500Name loadCertificateIssuer(TBSCertList.CRLEntry c, boolean isIndirect, X500Name previousCertificateIssuer)
8888
{
8989
if (!isIndirect)
9090
{

‎prov/src/main/jdk1.3/org/bouncycastle/jcajce/provider/asymmetric/x509/X509CRLImpl.java‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.bouncycastle.asn1.x509.CertificateList;
3939
import org.bouncycastle.asn1.x509.Extension;
4040
import org.bouncycastle.asn1.x509.Extensions;
41-
import org.bouncycastle.asn1.x509.GeneralNames;
4241
import org.bouncycastle.asn1.x509.IssuingDistributionPoint;
4342
import org.bouncycastle.asn1.x509.TBSCertList;
4443
import org.bouncycastle.asn1.x509.Time;
@@ -301,15 +300,7 @@ private Set loadCRLEntries()
301300
TBSCertList.CRLEntry entry = (TBSCertList.CRLEntry)certs.nextElement();
302301
X509CRLEntryObject crlEntry = new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
303302
entrySet.add(crlEntry);
304-
if (isIndirect && entry.hasExtensions())
305-
{
306-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
307-
308-
if (currentCaName != null)
309-
{
310-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
311-
}
312-
}
303+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
313304
}
314305

315306
return entrySet;
@@ -329,15 +320,7 @@ public X509CRLEntry getRevokedCertificate(BigInteger serialNumber)
329320
return new X509CRLEntryObject(entry, isIndirect, previousCertificateIssuer);
330321
}
331322

332-
if (isIndirect && entry.hasExtensions())
333-
{
334-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
335-
336-
if (currentCaName != null)
337-
{
338-
previousCertificateIssuer = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
339-
}
340-
}
323+
previousCertificateIssuer = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, previousCertificateIssuer);
341324
}
342325

343326
return null;
@@ -542,14 +525,10 @@ public boolean isRevoked(Certificate cert)
542525
{
543526
TBSCertList.CRLEntry entry = TBSCertList.CRLEntry.getInstance(certs.nextElement());
544527

545-
if (isIndirect && entry.hasExtensions())
528+
caName = X509CRLEntryObject.loadCertificateIssuer(entry, isIndirect, caName);
529+
if (caName == null)
546530
{
547-
Extension currentCaName = entry.getExtensions().getExtension(Extension.certificateIssuer);
548-
549-
if (currentCaName != null)
550-
{
551-
caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
552-
}
531+
caName = c.getIssuer(); // an entry with no certificate issuer of its own is the CRL issuer's
553532
}
554533

555534
if (entry.getUserCertificate().hasValue(serial))

0 commit comments

Comments
 (0)