Skip to content

Commit 8c412cb

Browse files
Allow RestrictedSecurity property extension from default values
1 parent acf059f commit 8c412cb

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

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

+53-22
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ private void init(String profileID) {
10901090
// Load restricted security providers from java.security properties.
10911091
initProviders(profileID, allInfo);
10921092
// Load restricted security properties from java.security properties.
1093-
loadProperties(profileID, allInfo);
1093+
loadProperties(profileID, allInfo, true);
10941094

10951095
String hashProperty = profileID + ".desc.hash";
10961096
String hashValue = securityProps.getProperty(hashProperty);
@@ -1124,7 +1124,7 @@ private void update(String profileExtensionId) {
11241124
// Load restricted security providers from java.security properties.
11251125
updateProviders(profileExtensionId, allInfo);
11261126
// Load restricted security properties from java.security properties.
1127-
loadProperties(profileExtensionId, allInfo);
1127+
loadProperties(profileExtensionId, allInfo, false);
11281128

11291129
String hashProperty = profileExtensionId + ".desc.hash";
11301130
String hashValue = securityProps.getProperty(hashProperty);
@@ -1314,48 +1314,79 @@ private void updateProviders(String profileExtensionId, List<String> allInfo) {
13141314
}
13151315
}
13161316

1317+
private String getExistingValue(String property) {
1318+
// Look for values from profiles that this one extends.
1319+
String existingValue = profileProperties.get(property);
1320+
1321+
// If there is no value, look for non-profile values in java.security file.
1322+
if (existingValue == null) {
1323+
String propertyKey = null;
1324+
switch (property) {
1325+
case "jdkCertpathDisabledAlgorithms":
1326+
propertyKey = "jdk.certpath.disabledAlgorithms";
1327+
break;
1328+
case "jdkSecurityLegacyAlgorithms":
1329+
propertyKey = "jdk.security.legacyAlgorithms";
1330+
break;
1331+
case "jdkTlsDisabledAlgorithms":
1332+
propertyKey = "jdk.tls.disabledAlgorithms";
1333+
break;
1334+
case "jdkTlsDisabledNamedCurves":
1335+
propertyKey = "jdk.tls.disabledNamedCurves";
1336+
break;
1337+
case "jdkTlsLegacyAlgorithms":
1338+
propertyKey = "jdk.tls.legacyAlgorithms";
1339+
break;
1340+
default:
1341+
propertyKey = "";
1342+
}
1343+
existingValue = securityProps.getProperty(propertyKey);
1344+
}
1345+
return existingValue;
1346+
}
1347+
13171348
/**
13181349
* Load restricted security properties.
13191350
*/
1320-
private void loadProperties(String profileID, List<String> allInfo) {
1351+
private void loadProperties(String profileID, List<String> allInfo, boolean isBaseProfile) {
13211352
if (debug != null) {
13221353
debug.println("\tLoading properties of restricted security profile.");
13231354
}
13241355

1325-
setProperty("descName", profileID + ".desc.name", allInfo);
1326-
if (setProperty("descIsDefaultString", profileID + ".desc.default", allInfo)) {
1356+
setProperty("descName", profileID + ".desc.name", allInfo, isBaseProfile);
1357+
if (setProperty("descIsDefaultString", profileID + ".desc.default", allInfo, isBaseProfile)) {
13271358
descIsDefault = Boolean.parseBoolean(profileProperties.get("descIsDefaultString"));
13281359
}
1329-
if (setProperty("descIsFIPSString", profileID + ".desc.fips", allInfo)) {
1360+
if (setProperty("descIsFIPSString", profileID + ".desc.fips", allInfo, isBaseProfile)) {
13301361
descIsFIPS = Boolean.parseBoolean(profileProperties.get("descIsFIPSString"));
13311362
}
1332-
setProperty("descNumber", profileID + ".desc.number", allInfo);
1333-
setProperty("descPolicy", profileID + ".desc.policy", allInfo);
1334-
setProperty("descSunsetDate", profileID + ".desc.sunsetDate", allInfo);
1363+
setProperty("descNumber", profileID + ".desc.number", allInfo, isBaseProfile);
1364+
setProperty("descPolicy", profileID + ".desc.policy", allInfo, isBaseProfile);
1365+
setProperty("descSunsetDate", profileID + ".desc.sunsetDate", allInfo, isBaseProfile);
13351366

13361367
setProperty("jdkTlsDisabledNamedCurves",
1337-
profileID + ".tls.disabledNamedCurves", allInfo);
1368+
profileID + ".tls.disabledNamedCurves", allInfo, isBaseProfile);
13381369
setProperty("jdkTlsDisabledAlgorithms",
1339-
profileID + ".tls.disabledAlgorithms", allInfo);
1370+
profileID + ".tls.disabledAlgorithms", allInfo, isBaseProfile);
13401371
setProperty("jdkTlsEphemeralDHKeySize",
1341-
profileID + ".tls.ephemeralDHKeySize", allInfo);
1372+
profileID + ".tls.ephemeralDHKeySize", allInfo, isBaseProfile);
13421373
setProperty("jdkTlsLegacyAlgorithms",
1343-
profileID + ".tls.legacyAlgorithms", allInfo);
1374+
profileID + ".tls.legacyAlgorithms", allInfo, isBaseProfile);
13441375
setProperty("jdkCertpathDisabledAlgorithms",
1345-
profileID + ".jce.certpath.disabledAlgorithms", allInfo);
1376+
profileID + ".jce.certpath.disabledAlgorithms", allInfo, isBaseProfile);
13461377
setProperty("jdkSecurityLegacyAlgorithms",
1347-
profileID + ".jce.legacyAlgorithms", allInfo);
1378+
profileID + ".jce.legacyAlgorithms", allInfo, isBaseProfile);
13481379
setProperty("keyStoreType",
1349-
profileID + ".keystore.type", allInfo);
1380+
profileID + ".keystore.type", allInfo, isBaseProfile);
13501381
setProperty("keyStore",
1351-
profileID + ".javax.net.ssl.keyStore", allInfo);
1382+
profileID + ".javax.net.ssl.keyStore", allInfo, isBaseProfile);
13521383

13531384
setProperty("jdkSecureRandomProvider",
1354-
profileID + ".securerandom.provider", allInfo);
1385+
profileID + ".securerandom.provider", allInfo, isBaseProfile);
13551386
setProperty("jdkSecureRandomAlgorithm",
1356-
profileID + ".securerandom.algorithm", allInfo);
1387+
profileID + ".securerandom.algorithm", allInfo, isBaseProfile);
13571388
setProperty("jdkFipsMode",
1358-
profileID + ".fips.mode", allInfo);
1389+
profileID + ".fips.mode", allInfo, isBaseProfile);
13591390

13601391
if (debug != null) {
13611392
debug.println("\tProperties of restricted security profile successfully loaded.");
@@ -1573,7 +1604,7 @@ private void printProfile(String profileToPrint) {
15731604
* @param propertyKey the property key in the java.security file
15741605
* @return whether the property was set
15751606
*/
1576-
private boolean setProperty(String property, String propertyKey, List<String> allInfo) {
1607+
private boolean setProperty(String property, String propertyKey, List<String> allInfo, boolean isBaseProfile) {
15771608
if (debug != null) {
15781609
debug.println("Setting property: " + property);
15791610
}
@@ -1585,7 +1616,7 @@ private boolean setProperty(String property, String propertyKey, List<String> al
15851616
allInfo.add(propertyKey + "=" + value);
15861617

15871618
// Check if property overrides, adds to or removes from previous value.
1588-
String existingValue = profileProperties.get(property);
1619+
String existingValue = getExistingValue(property);
15891620
if (value.startsWith("+")) {
15901621
if (!isPropertyAppendable(property)) {
15911622
printStackTraceAndExit("Property '" + property + "' is not appendable.");

0 commit comments

Comments
 (0)