Skip to content

Commit c229747

Browse files
committed
RH2021263: Improve Security initialisation, now FIPS support no longer relies on crypto policy support
1 parent fc0e5c3 commit c229747

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/java.base/share/classes/java/security/Security.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ public final class Security {
6161
private static final Debug sdebug =
6262
Debug.getInstance("properties");
6363

64-
/* System property file*/
65-
private static final String SYSTEM_PROPERTIES =
66-
"/etc/crypto-policies/back-ends/java.config";
67-
6864
/* The java.security properties */
6965
private static Properties props;
7066

@@ -206,22 +202,36 @@ private static void initialize() {
206202
}
207203
}
208204

205+
if (!loadedProps) {
206+
initializeStatic();
207+
if (sdebug != null) {
208+
sdebug.println("unable to load security properties " +
209+
"-- using defaults");
210+
}
211+
}
212+
209213
String disableSystemProps = System.getProperty("java.security.disableSystemPropertiesFile");
210214
if ((disableSystemProps == null || "false".equalsIgnoreCase(disableSystemProps)) &&
211215
"true".equalsIgnoreCase(props.getProperty("security.useSystemPropertiesFile"))) {
212-
if (SystemConfigurator.configure(props)) {
213-
loadedProps = true;
216+
if (!SystemConfigurator.configureSysProps(props)) {
217+
if (sdebug != null) {
218+
sdebug.println("WARNING: System properties could not be loaded.");
219+
}
214220
}
215221
}
216222

217-
if (!loadedProps) {
218-
initializeStatic();
223+
// FIPS support depends on the contents of java.security so
224+
// ensure it has loaded first
225+
if (loadedProps) {
226+
boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
219227
if (sdebug != null) {
220-
sdebug.println("unable to load security properties " +
221-
"-- using defaults");
228+
if (fipsEnabled) {
229+
sdebug.println("FIPS support enabled.");
230+
} else {
231+
sdebug.println("FIPS support disabled.");
232+
}
222233
}
223234
}
224-
225235
}
226236

227237
/*

src/java.base/share/classes/java/security/SystemConfigurator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Void run() {
7676
* java.security.disableSystemPropertiesFile property is not set and
7777
* security.useSystemPropertiesFile is true.
7878
*/
79-
static boolean configure(Properties props) {
79+
static boolean configureSysProps(Properties props) {
8080
boolean loadedProps = false;
8181

8282
try (BufferedInputStream bis =
@@ -96,11 +96,19 @@ static boolean configure(Properties props) {
9696
e.printStackTrace();
9797
}
9898
}
99+
return loadedProps;
100+
}
101+
102+
/*
103+
* Invoked at the end of java.security.Security initialisation
104+
* if java.security properties have been loaded
105+
*/
106+
static boolean configureFIPS(Properties props) {
107+
boolean loadedProps = false;
99108

100109
try {
101110
if (enableFips()) {
102111
if (sdebug != null) { sdebug.println("FIPS mode detected"); }
103-
loadedProps = false;
104112
// Remove all security providers
105113
Iterator<Entry<Object, Object>> i = props.entrySet().iterator();
106114
while (i.hasNext()) {

0 commit comments

Comments
 (0)