Skip to content

Commit 1fdfb53

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents 516187a + 9af1f99 commit 1fdfb53

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎docs/releasenotes.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ <h3>2.1.2 Defects Fixed</h3>
130130
<li>An OCSP response carrying no nextUpdate could be cached and reused as though it stated a validity interval, so a response could go on answering for a certificate after the responder had newer information about it - after a revocation, in particular. Any such reuse was bounded only by garbage collection rather than by an interval: OcspCache holds each responder's response map through a WeakReference, itself in a WeakHashMap, and nothing else refers to that map once the call returns, so entries last until the next collection. That is unpredictable rather than long - short on a busy JVM, potentially much longer on a large heap that collects rarely - and it is not a window the responder or the caller had any say in. RFC 6960 sec. 4.2.2.1 says the opposite of what that assumes: "if nextUpdate is not set, the responder is indicating that newer revocation information is available all the time", which is a statement that there is no interval to reuse the response over, not that it never expires. OcspCache now separates the two questions it had been asking with one method: a response arriving from the responder is accepted as before, whether or not it states a nextUpdate, while only a response that states one may be served from the cache afterwards. Nothing is rejected that was previously accepted - a responder that omits nextUpdate simply costs another request per validation, which is what "available all the time" asks for. Additionally, both the cached and the caller-supplied (stapled) paths now apply RFC 6960 sec. 4.2.2.1's other freshness rule, "responses whose thisUpdate time is later than the local system time SHOULD be considered unreliable", which neither had checked: a response dated ahead of the time being validated for by more than a 15 minute clock-skew allowance is treated as unreliable, raising "OCSP response not yet valid" on the stapled path.</li>
131131
<li>None of the javax.crypto.KEM encapsulators destroyed the SecretWithEncapsulation the mechanism handed them, so each left the mechanism's own session key live in the heap for as long as the KEM.Encapsulator object was reachable - ML-KEM, HQC, NTRU, NTRU Prime and SM9 were all affected. Clearing the derived key was not enough to cover it: SecretWithEncapsulationImpl.getSecret() and getEncapsulation() hand back clones of their internal arrays, so KdfUtil.makeKeyBytes clearing the secret clone it is passed never reached the session key inside, and only destroy() does. Each encapsulator now takes the encapsulation and the shared secret and then destroys the SecretWithEncapsulation in a finally block, as the sibling Cipher services in the same packages already did, and as the ISO/IEC 18033-2 FrodoKEM and Classic McEliece encapsulators added in this release do. The order matters, since destroy() clears the encapsulation as well as the session key. Nothing observable changes for a caller - the shared secret and encapsulation returned are the same as before, and are the caller's own copies.</li>
132132
<li>The KEM KeyGenerator services had the same missing key-size check as the javax.crypto.KEM ones described under Additional Features below, and are corrected here for the older API too: a KEMGenerateSpec or KEMExtractSpec built withNoKdf() and given a key size larger than the mechanism's session key overran the shared secret and threw ArrayIndexOutOfBoundsException out of KeyGenerator.generateKey(), which has no way to describe such a failure. The conventional 256-bit request failed that way for FrodoKEM's 976 parameter sets, whose session key is 192 bits, as did any request above 256 bits for ML-KEM, Classic McEliece and the composite KEMs, whose session keys are 256 bits. These services take a KEMKDFSpec rather than a KTSParameterSpec and so never pass through KdfUtil.resolveKemSpec, where the KEM services now have their spec validated up front; the check therefore sits in KdfUtil.makeKeyBytes itself, which covers them and any future caller of it. The request is refused with an IllegalArgumentException naming both sizes rather than quietly met at the shorter length, since a caller that asked for a 256-bit AES key and was handed a 192-bit one has no way of telling. A request the session key can satisfy is unaffected and produces exactly the key material it did before, and the Cipher and KTS key-wrapping paths were never affected - there the requested size is only an upper bound on a wrapping key both parties derive the same way from the same secret, so WrapUtil clamps it to the secret it has.</li>
133+
<li>The BCJSSE provider now only computes active early key share groups for clients offering TLS 1.3+. Previously it was computed for all connections, which was mostly harmless, but could generate misleading log messages (at WARNING level) for servers or pre-TLS1.3 clients where the logged condition was irrelevant (github #2392).</li>
133134
</ul>
134135

135136
<h3>2.1.3 Additional Features and Functionality</h3>

‎tls/src/main/java/org/bouncycastle/jsse/provider/NamedGroupInfo.java‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,17 @@ static PerConnection createPerConnectionClient(PerContext perContext, ProvSSLPar
252252
ProtocolVersion latest = ProtocolVersion.getLatestTLS(activeProtocolVersions);
253253
ProtocolVersion earliest = ProtocolVersion.getEarliestTLS(activeProtocolVersions);
254254

255-
return createPerConnection(perContext, sslParameters, earliest, latest);
255+
return createPerConnection(perContext, sslParameters, earliest, latest, true);
256256
}
257257

258258
static PerConnection createPerConnectionServer(PerContext perContext, ProvSSLParameters sslParameters,
259259
ProtocolVersion negotiatedVersion)
260260
{
261-
return createPerConnection(perContext, sslParameters, negotiatedVersion, negotiatedVersion);
261+
return createPerConnection(perContext, sslParameters, negotiatedVersion, negotiatedVersion, false);
262262
}
263263

264264
private static PerConnection createPerConnection(PerContext perContext, ProvSSLParameters sslParameters,
265-
ProtocolVersion earliest, ProtocolVersion latest)
265+
ProtocolVersion earliest, ProtocolVersion latest, boolean isClient)
266266
{
267267
String[] namedGroups = sslParameters.getNamedGroups();
268268

@@ -297,7 +297,9 @@ private static PerConnection createPerConnection(PerContext perContext, ProvSSLP
297297

298298
boolean localECDSA = hasAnyECDSA(local);
299299

300+
// NOTE: Early key shares are only ever used by a client offering TLS 1.3
300301
Vector localEarly = null;
302+
if (isClient && post13Active)
301303
{
302304
String[] earlyKeyShares = sslParameters.getEarlyKeyShares();
303305

@@ -321,9 +323,9 @@ private static PerConnection createPerConnection(PerContext perContext, ProvSSLP
321323
Integer earlyCandidate = Integers.valueOf(earlyCandidates[i]);
322324

323325
NamedGroupInfo earlyNamedGroupInfo = local.get(earlyCandidate);
324-
if (earlyNamedGroupInfo == null || !earlyNamedGroupInfo.isEnabled())
326+
if (earlyNamedGroupInfo == null)
325327
{
326-
LOG.warning("Candidate early key share not an enabled named group: "
328+
LOG.warning("Candidate early key share not an offered named group for this connection: "
327329
+ NamedGroup.getName(earlyCandidates[i]));
328330
continue;
329331
}
@@ -664,6 +666,11 @@ private static int[] createEarlyCandidates(Map<Integer, NamedGroupInfo> index, S
664666
{
665667
result = Arrays.copyOf(result, count);
666668
}
669+
// NOTE: Only complain about an empty result if attempting to configure a non-empty list
670+
if (names.length > 0 && count < 1)
671+
{
672+
LOG.warning("'" + description + "' contained no usable NamedGroup values; no early key_share will be offered");
673+
}
667674
return result;
668675
}
669676

0 commit comments

Comments
 (0)