Skip to content

Commit c5d619a

Browse files
Allow RestrictedSecurity property extension from default values
The default values existing in the java.security file are now considered the baseline and all profiles can inherit them and add or remove to them, if they are in list form. This does not include the providers, though. Signed-off-by: Kostas Tsiounis<[email protected]>
1 parent 8e2f053 commit c5d619a

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,48 @@ private void updateProviders(String profileExtensionId, List<String> allInfo) {
13321332
}
13331333
}
13341334

1335+
private String getExistingValue(String property) {
1336+
if (debug != null) {
1337+
debug.println("\tGetting previous value of property: " + property);
1338+
}
1339+
1340+
// Look for values from profiles that this one extends.
1341+
String existingValue = profileProperties.get(property);
1342+
String debugMessage = "\t\tPrevious value from extended profile: ";
1343+
1344+
// If there is no value, look for non-profile values in java.security file.
1345+
if (existingValue == null) {
1346+
debugMessage = "\t\tPrevious value from java.security file: ";
1347+
String propertyKey;
1348+
switch (property) {
1349+
case "jdkCertpathDisabledAlgorithms":
1350+
propertyKey = "jdk.certpath.disabledAlgorithms";
1351+
break;
1352+
case "jdkSecurityLegacyAlgorithms":
1353+
propertyKey = "jdk.security.legacyAlgorithms";
1354+
break;
1355+
case "jdkTlsDisabledAlgorithms":
1356+
propertyKey = "jdk.tls.disabledAlgorithms";
1357+
break;
1358+
case "jdkTlsDisabledNamedCurves":
1359+
propertyKey = "jdk.tls.disabledNamedCurves";
1360+
break;
1361+
case "jdkTlsLegacyAlgorithms":
1362+
propertyKey = "jdk.tls.legacyAlgorithms";
1363+
break;
1364+
default:
1365+
return null;
1366+
}
1367+
existingValue = securityProps.getProperty(propertyKey);
1368+
}
1369+
1370+
if ((debug != null) && (existingValue != null)) {
1371+
debug.println(debugMessage + existingValue);
1372+
}
1373+
1374+
return existingValue;
1375+
}
1376+
13351377
/**
13361378
* Load restricted security properties.
13371379
*/
@@ -1603,7 +1645,7 @@ private boolean setProperty(String property, String propertyKey, List<String> al
16031645
allInfo.add(propertyKey + "=" + value);
16041646

16051647
// Check if property overrides, adds to or removes from previous value.
1606-
String existingValue = profileProperties.get(property);
1648+
String existingValue = getExistingValue(property);
16071649
if (value.startsWith("+")) {
16081650
if (!isPropertyAppendable(property)) {
16091651
printStackTraceAndExit("Property '" + property + "' is not appendable.");
@@ -1613,7 +1655,8 @@ private boolean setProperty(String property, String propertyKey, List<String> al
16131655

16141656
// Take existing value of property into account, if applicable.
16151657
if (existingValue == null) {
1616-
printStackTraceAndExit("Property '" + property + "' does not exist in parent profile. Cannot append.");
1658+
printStackTraceAndExit("Property '" + property + "' does not exist in"
1659+
+ " parent profile or java.security file. Cannot append.");
16171660
} else if (existingValue.isBlank()) {
16181661
newValue = value;
16191662
} else {
@@ -1627,6 +1670,10 @@ private boolean setProperty(String property, String propertyKey, List<String> al
16271670
// Remove values from property.
16281671
value = value.substring(1).trim();
16291672
if (!value.isBlank()) {
1673+
if (existingValue == null) {
1674+
printStackTraceAndExit("Property '" + property + "' does not exist in"
1675+
+ " parent profile or java.security file. Cannot remove.");
1676+
}
16301677
List<String> existingValues = Stream.of(existingValue.split(","))
16311678
.map(v -> v.trim())
16321679
.collect(Collectors.toList());
@@ -1640,7 +1687,8 @@ private boolean setProperty(String property, String propertyKey, List<String> al
16401687
} else {
16411688
// Nothing to do. Use existing value of property into account, if available.
16421689
if (existingValue == null) {
1643-
printStackTraceAndExit("Property '" + property + "' does not exist in parent profile. Cannot remove.");
1690+
printStackTraceAndExit("Property '" + property + "' does not exist in"
1691+
+ " parent profile or java.security file. Cannot remove.");
16441692
} else if (existingValue.isBlank()) {
16451693
newValue = value;
16461694
} else {

src/java.base/share/conf/security/java.security

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,14 @@ RestrictedSecurity.NSS.140-2.securerandom.algorithm = PKCS11
182182
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.name = OpenJCEPlusFIPS Cryptographic Module FIPS 140-3
183183
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.default = false
184184
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.fips = true
185-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.hash = SHA256:4a85dc0db2f257388155b3ada7378773884edc89c80c8d715f4bdde84cc3d8bd
185+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.hash = SHA256:bea1b7da967ac27720b7bc439ccd2d4250ebe783a6919a8e7047e6a6b862a116
186186
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.number = Certificate #XXX
187187
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.policy = https://csrc.nist.gov/projects/cryptographic-module-validation-program/certificate/
188188
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.desc.sunsetDate = 2026-09-21
189189
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.fips.mode = 140-3
190190

191-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.disabledNamedCurves =
192-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.disabledAlgorithms = \
193-
3DES_EDE_CBC, \
194-
anon, \
195-
DES, \
191+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.disabledAlgorithms = + \
196192
DH keySize < 2048, \
197-
DTLSv1.0, \
198-
EC keySize < 224, \
199-
ECDH, \
200-
MD5withRSA, \
201-
NULL, \
202-
RC4, \
203-
SSLv3, \
204193
TLS_DHE_DSS_WITH_AES_128_CBC_SHA, \
205194
TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, \
206195
TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, \
@@ -224,15 +213,9 @@ RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.disabledAlgorithms = \
224213
TLS_RSA_WITH_AES_256_CBC_SHA, \
225214
TLS_RSA_WITH_AES_256_CBC_SHA256, \
226215
TLS_RSA_WITH_AES_256_GCM_SHA384, \
227-
TLSv1, \
228-
TLSv1.1, \
229216
X25519, \
230217
X448
231-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.ephemeralDHKeySize =
232-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.tls.legacyAlgorithms =
233218

234-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.jce.certpath.disabledAlgorithms =
235-
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.jce.legacyAlgorithms =
236219
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3.jce.provider.1 = com.ibm.crypto.plus.provider.OpenJCEPlusFIPS [ \
237220
{AlgorithmParameterGenerator, AESGCM, *}, \
238221
{AlgorithmParameterGenerator, CCM, *}, \

0 commit comments

Comments
 (0)