Skip to content

Commit c6ae478

Browse files
committed
BCJSSE: Add boolean system property org.bouncycastle.jsse.useNamedGroupsOrder
- If no BCSSLParameters set, the property provides the default value for useNamedGroups. - Property is read per-SSLContext-init
1 parent cc19397 commit c6ae478

5 files changed

Lines changed: 363 additions & 1 deletion

File tree

‎docs/releasenotes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ Date: 2026, TBD
160160

161161
### 2.1.3 Additional Features and Functionality
162162

163+
- BCJSSE: the new org.bouncycastle.jsse.useNamedGroupsOrder boolean system property sets the default behaviour for TLS 1.3 server named group selection, applicable when no BCSSLParameters are set (in which case BCSSLParameters.useNamedGroupsOrder takes precedence). Set to true, connections of an SSLContext default to having a TLS 1.3 server select the key share group by its own named group order rather than the client's. Read per-SSLContext-init rather than once per class load.
163164
- The BCFKS keystore now honours a write-side iteration count property, org.bouncycastle.bcfks.store_it_count (Properties.BCFKS_STORE_IT_COUNT), the counterpart of the PKCS#12 org.bouncycastle.pkcs12.store_it_count added earlier in this cycle: it sets the PBKDF2-HMAC-SHA512 iteration count used for the integrity MAC key, the store encryption and the entry key-encryption keys when a store is written through KeyStore.store(OutputStream, char[]) without a BCFKSLoadStoreParameter naming its own KDF. The default remains 51,200; a value outside 1 .. 5,000,000 is ignored so that a mistyped property cannot produce a file with no PBE work in it, and the upper bound is the default read-side cap, so a file written under the property can always be read back. A BCFKSLoadStoreParameter with an explicit PBKDFConfig is unaffected.
164165
- The LMS / HSS hash-based signature implementation (RFC 8554) has been promoted from org.bouncycastle.pqc.crypto.lms into org.bouncycastle.crypto, following ML-KEM, ML-DSA and SLH-DSA: the key parameter classes are now org.bouncycastle.crypto.params.LMS\* / HSS\* (LMSigParameters, LMOtsParameters, LMSParameters, LMSKeyParameters, LMSPublicKeyParameters, LMSPrivateKeyParameters, LMSKeyGenerationParameters and the four HSS equivalents), the key pair generators are org.bouncycastle.crypto.generators.LMSKeyPairGenerator / HSSKeyPairGenerator, and LMSSigner, HSSSigner and the LMSContextBasedSigner / LMSContextBasedVerifier interfaces are in org.bouncycastle.crypto.signers, with LMSContext and the engine in org.bouncycastle.crypto.signers.lms. org.bouncycastle.crypto.util.PublicKeyFactory / PrivateKeyFactory / SubjectPublicKeyInfoFactory / PrivateKeyInfoFactory now cover id-alg-hss-lms-hashsig, so a caller no longer has to reach for the org.bouncycastle.pqc.crypto.util copies for LMS, and the BC provider's LMS KeyFactory, KeyPairGenerator and Signature services use the promoted classes throughout. Two behavioural differences in the promoted copy: LMSSigner and HSSSigner implement org.bouncycastle.crypto.Signer (they buffer the message through update() and sign or verify it on generateSignature() / verifySignature(byte[])) rather than the org.bouncycastle.pqc.crypto.MessageSigner interface, though the one-shot generateSignature(byte[]) and verifySignature(byte[], byte[]) methods remain. The buffered and one-shot forms must not be mixed: a one-shot call made with a message already absorbed through update() is refused with an IllegalStateException rather than silently discarding it - call reset() first, or use the buffered form - and the refusal precedes the key read, so it spends no one-time key; init() clears any buffered message, as it does on every other buffering Signer in the package. Also, an exhausted key raises the new org.bouncycastle.crypto.ExhaustedPrivateKeyException, which org.bouncycastle.pqc.crypto.ExhaustedPrivateKeyException now extends, so a catch of the new type catches both while a catch of the old one does not see a throw from the promoted code. All encodings are unchanged - the two implementations produce byte-identical X.509, PKCS#8 and signature encodings and each verifies what the other signed, which the new org.bouncycastle.pqc.crypto.test.LMSPromotionCompatibilityTest asserts across the parameter-set matrix. The engine package follows the ML-DSA and SLH-DSA shape: its public classes are LMSEngine, the operations the key classes are built on, LMSContext, and LMSSignature as the opaque form of the chaining signatures an HSS private key carries; the one-time key and signature classes, seed derivation and encoding helpers stay package-private, as do the index-management methods of the key classes, so the stateful index cannot be moved from outside the key.
165166
- org.bouncycastle.pqc.crypto.lms is deprecated in favour of the promoted implementation above and is scheduled for removal in the next release; it is otherwise unchanged and still carries its own test suite for this release. The two implementations hold their signature index in independent objects, so a single stateful private key must be driven through one of them and not both. In the JCE layer, org.bouncycastle.pqc.jcajce.spec.LMSKeyGenParameterSpec and the already-deprecated LMSParameterSpec gain a constructor and accessors taking the promoted types - getLMSigParameters() and getLMOtsParameters() - and their existing constructor, getSigParams() and getOtsParams(), which name the org.bouncycastle.pqc.crypto.lms types, are deprecated alongside the package rather than repointed, so existing callers are unaffected.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class ContextData
4040
private final int handshakeTimeoutMillis;
4141
private final boolean serverEnableStatusRequest;
4242
private final OcspStapleCache ocspStapleCache;
43+
private final boolean defaultUseNamedGroupsOrder;
4344

4445
ContextData(boolean fipsMode, JcaTlsCrypto crypto, BCX509ExtendedKeyManager x509KeyManager,
4546
BCX509ExtendedTrustManager x509TrustManager, Map<String, CipherSuiteInfo> supportedCipherSuites,
@@ -73,6 +74,13 @@ final class ContextData
7374
"jdk.tls.server.enableStatusRequestExtension", false);
7475
// nothing reaches the cache unless a server in this context staples, so don't build one
7576
this.ocspStapleCache = serverEnableStatusRequest ? OcspStapleCache.create(crypto.getHelper()) : null;
77+
/*
78+
* NOTE: also read per context (see above), so that an SSLContext initialised after the
79+
* property is set honours it and one initialised before is unaffected. It only seeds the
80+
* default in ProvSSLParameters; a value set on the connection's BCSSLParameters still wins.
81+
*/
82+
this.defaultUseNamedGroupsOrder = PropertyUtils.getBooleanSystemProperty(
83+
"org.bouncycastle.jsse.useNamedGroupsOrder", false);
7684
}
7785

7886
int[] getActiveCipherSuites(JcaTlsCrypto crypto, ProvSSLParameters sslParameters,
@@ -241,6 +249,15 @@ OcspStapleCache getOcspStapleCache()
241249
return ocspStapleCache;
242250
}
243251

252+
/**
253+
* The initial value of {@link ProvSSLParameters#getUseNamedGroupsOrder()} for parameters created
254+
* in this context, from <code>org.bouncycastle.jsse.useNamedGroupsOrder</code> (default false).
255+
*/
256+
boolean getDefaultUseNamedGroupsOrder()
257+
{
258+
return defaultUseNamedGroupsOrder;
259+
}
260+
244261
NamedGroupInfo.PerConnection getNamedGroupsClient(ProvSSLParameters sslParameters,
245262
ProtocolVersion[] activeProtocolVersions)
246263
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static <T> List<T> copyList(Collection<T> list)
4141
private List<BCSNIMatcher> sniMatchers;
4242
// Changed to true in Java 13, then subsequently backported to 8, 11
4343
private boolean useCipherSuitesOrder = true;
44-
private boolean useNamedGroupsOrder = false;
44+
private boolean useNamedGroupsOrder;
4545
private boolean enableRetransmissions = true;
4646
private int maximumPacketSize = 0;
4747
private String[] applicationProtocols = TlsUtils.EMPTY_STRINGS;
@@ -60,6 +60,7 @@ private static <T> List<T> copyList(Collection<T> list)
6060

6161
this.cipherSuites = cipherSuites;
6262
this.protocols = protocols;
63+
this.useNamedGroupsOrder = contextData.getDefaultUseNamedGroupsOrder();
6364
}
6465

6566
ProvSSLParameters copy()

‎tls/src/test/java/org/bouncycastle/jsse/provider/test/AllTests.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static Test suite()
3939
suite.addTestSuite(SSLServerSocketTest.class);
4040
suite.addTestSuite(SSLSocketTest.class);
4141
suite.addTestSuite(TlsFipsTest.class);
42+
suite.addTestSuite(UseNamedGroupsOrderTest.class);
4243

4344

4445
if (hasClass("javax.net.ssl.CertPathTrustManagerParameters"))

0 commit comments

Comments
 (0)