Skip to content

Commit 4f1b233

Browse files
authored
Merge pull request #1055 from KostasTsiounis/named_group_property_j11
Set jdk.tls.namedGroups property through RestrictedSecurity profiles
2 parents 20917e4 + ee8c94a commit 4f1b233

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,17 @@ private static void setProperties(Properties props) {
655655
// SSL property "javax.net.ssl.keyStore" set at the JVM level via system properties.
656656
System.setProperty("javax.net.ssl.keyStore", keyStore);
657657
}
658+
String jdkTlsNamedGroups = restricts.jdkTlsNamedGroups;
659+
if (!isNullOrBlank(jdkTlsNamedGroups)) {
660+
String namedGroups = System.getProperty("jdk.tls.namedGroups");
661+
if (namedGroups == null) {
662+
// TLS property "jdk.tls.namedGroups" set at the JVM level via system properties.
663+
System.setProperty("jdk.tls.namedGroups", jdkTlsNamedGroups);
664+
} else {
665+
printStackTraceAndExit("System property jdk.tls.namedGroups cannot be set"
666+
+ " when defined in a RestrictedSecurity profile");
667+
}
668+
}
658669
}
659670

660671
/**
@@ -800,6 +811,7 @@ private static final class RestrictedSecurityProperties {
800811
private final String jdkTlsDisabledAlgorithms;
801812
private final String jdkTlsEphemeralDHKeySize;
802813
private final String jdkTlsLegacyAlgorithms;
814+
private final String jdkTlsNamedGroups;
803815
private final String jdkCertpathDisabledAlgorithms;
804816
private final String jdkSecurityLegacyAlgorithms;
805817
private final String keyStoreType;
@@ -834,6 +846,7 @@ private RestrictedSecurityProperties(String profileID, ProfileParser parser) {
834846
this.jdkTlsDisabledAlgorithms = parser.getProperty("jdkTlsDisabledAlgorithms");
835847
this.jdkTlsEphemeralDHKeySize = parser.getProperty("jdkTlsEphemeralDHKeySize");
836848
this.jdkTlsLegacyAlgorithms = parser.getProperty("jdkTlsLegacyAlgorithms");
849+
this.jdkTlsNamedGroups = parser.getProperty("jdkTlsNamedGroups");
837850
this.jdkCertpathDisabledAlgorithms = parser.getProperty("jdkCertpathDisabledAlgorithms");
838851
this.jdkSecurityLegacyAlgorithms = parser.getProperty("jdkSecurityLegacyAlgorithms");
839852
this.keyStoreType = parser.getProperty("keyStoreType");
@@ -1128,6 +1141,7 @@ private void listUsedProfile() {
11281141
printProperty(profileID + ".tls.disabledAlgorithms: ", jdkTlsDisabledAlgorithms);
11291142
printProperty(profileID + ".tls.ephemeralDHKeySize: ", jdkTlsEphemeralDHKeySize);
11301143
printProperty(profileID + ".tls.legacyAlgorithms: ", jdkTlsLegacyAlgorithms);
1144+
printProperty(profileID + ".tls.namedGroups: ", jdkTlsNamedGroups);
11311145
printProperty(profileID + ".jce.certpath.disabledAlgorithms: ", jdkCertpathDisabledAlgorithms);
11321146
printProperty(profileID + ".jce.legacyAlgorithms: ", jdkSecurityLegacyAlgorithms);
11331147
System.out.println();
@@ -1582,6 +1596,8 @@ private void loadProperties(String profileID, List<String> allInfo) {
15821596
profileID + ".tls.ephemeralDHKeySize", allInfo);
15831597
setProperty("jdkTlsLegacyAlgorithms",
15841598
profileID + ".tls.legacyAlgorithms", allInfo);
1599+
setProperty("jdkTlsNamedGroups",
1600+
profileID + ".tls.namedGroups", allInfo);
15851601
setProperty("jdkCertpathDisabledAlgorithms",
15861602
profileID + ".jce.certpath.disabledAlgorithms", allInfo);
15871603
setProperty("jdkSecurityLegacyAlgorithms",

closed/test/jdk/openj9/internal/security/TestProperties.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ===========================================================================
3-
* (c) Copyright IBM Corp. 2024, 2025 All Rights Reserved
3+
* (c) Copyright IBM Corp. 2024, 2026 All Rights Reserved
44
* ===========================================================================
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -202,6 +202,21 @@ private static Stream<Arguments> patternMatches_propertiesList() {
202202
return tests.build();
203203
}
204204

205+
private static Stream<Arguments> patternMatches_systemProperties() {
206+
return Stream.of(
207+
// 1 - Test property - base profile with javax.net.ssl.keyStore loads successfully.
208+
Arguments.of("TestBase.Version",
209+
System.getProperty("test.src") + "/property-java.security",
210+
"javax\\.net\\.ssl\\.keyStore: NONE",
211+
0),
212+
// 2 - Test property - base profile with jdk.tls.namedGroups loads successfully.
213+
Arguments.of("TestBase.Version",
214+
System.getProperty("test.src") + "/property-java.security",
215+
"jdk\\.tls\\.namedGroups: secp256r1",
216+
0)
217+
);
218+
}
219+
205220
@ParameterizedTest
206221
@MethodSource("patternMatches_expectedExitValue0")
207222
public void shouldContain_expectedExitValue0(String customprofile, String securityPropertyFile, String expected) throws Exception {
@@ -241,6 +256,19 @@ public void shouldContain_propertiesList(String customprofile, String securityPr
241256
outputAnalyzer.shouldHaveExitValue(exitValue).shouldMatch(expected);
242257
}
243258

259+
@ParameterizedTest
260+
@MethodSource("patternMatches_systemProperties")
261+
public void shouldContain_systemProperties(String customprofile, String securityPropertyFile, String expected, int exitValue) throws Exception {
262+
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJava(
263+
"-Dsemeru.fips=true",
264+
"-Dsemeru.customprofile=" + customprofile,
265+
"-Djava.security.properties=" + securityPropertyFile,
266+
"TestProperties"
267+
);
268+
outputAnalyzer.reportDiagnosticSummary();
269+
outputAnalyzer.shouldHaveExitValue(exitValue).shouldMatch(expected);
270+
}
271+
244272
private static boolean isProviderPresent(String providerName) {
245273
for (Provider provider : Security.getProviders()) {
246274
if (provider.getName().equalsIgnoreCase(providerName)) {
@@ -250,13 +278,28 @@ private static boolean isProviderPresent(String providerName) {
250278
return false;
251279
}
252280

281+
private static void testSystemProperties() {
282+
// Test javax.net.ssl.keyStore system property.
283+
String keyStore = System.getProperty("javax.net.ssl.keyStore");
284+
if (keyStore != null) {
285+
System.out.println("javax.net.ssl.keyStore: " + keyStore);
286+
}
287+
288+
// Test jdk.tls.namedGroups system property.
289+
String namedGroups = System.getProperty("jdk.tls.namedGroups");
290+
if (namedGroups != null) {
291+
System.out.println("jdk.tls.namedGroups: " + namedGroups);
292+
}
293+
}
294+
253295
public static void main(String[] args) {
254296
// Something to trigger "properties" debug output.
255297
try {
256298
for (Provider provider : Security.getProviders()) {
257299
System.out.println("Provider Name: " + provider.getName());
258300
System.out.println("Provider Version: " + provider.getVersionStr());
259301
}
302+
testSystemProperties();
260303
} catch (Exception e) {
261304
System.out.println(e);
262305
}

closed/test/jdk/openj9/internal/security/property-java.security

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
RestrictedSecurity.TestBase.Version.desc.name = Test Base Profile
2222
RestrictedSecurity.TestBase.Version.desc.default = false
2323
RestrictedSecurity.TestBase.Version.desc.fips = true
24-
RestrictedSecurity.TestBase.Version.desc.hash = SHA256:5694e96a9990cae706ea0c712e19924dcab88ebf8aa303e1aac99c1b07f6c8ab
24+
RestrictedSecurity.TestBase.Version.desc.hash = SHA256:156d6520b0ed1eab55ad55d3e2a4fd4c3a335cf98e5e7fdaa21b1ca5d63e46d3
2525
RestrictedSecurity.TestBase.Version.fips.mode = 140-3
2626

2727
RestrictedSecurity.TestBase.Version.tls.disabledNamedCurves =
2828
RestrictedSecurity.TestBase.Version.tls.disabledAlgorithms =
2929
RestrictedSecurity.TestBase.Version.tls.ephemeralDHKeySize =
3030
RestrictedSecurity.TestBase.Version.tls.legacyAlgorithms =
31+
RestrictedSecurity.TestBase.Version.tls.namedGroups = secp256r1
3132

3233
RestrictedSecurity.TestBase.Version.jce.certpath.disabledAlgorithms =
3334
RestrictedSecurity.TestBase.Version.jce.legacyAlgorithms =

src/java.base/share/classes/sun/security/ssl/SupportedGroupsExtension.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2026, 2026 All Rights Reserved
29+
* ===========================================================================
30+
*/
2631
package sun.security.ssl;
2732

2833
import java.io.IOException;
@@ -160,6 +165,10 @@ static class SupportedGroups {
160165
static {
161166
boolean requireFips = SunJSSE.isFIPS();
162167

168+
// RestrictedSecurity must be given an opportunity to set
169+
// jdk.tls.namedGroups based on the selected profile, if applicable.
170+
NamedGroup.SECP256_R1.ordinal();
171+
163172
// The value of the System Property defines a list of enabled named
164173
// groups in preference order, separated with comma. For example:
165174
//

0 commit comments

Comments
 (0)