Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

95617d
commit 0cd8cee94fe0f867b0b39890e00be620af1d9b07
95617d
Author: Andrew Hughes <gnu.andrew@redhat.com>
95617d
Date:   Tue Jan 18 02:09:27 2022 +0000
95617d
95617d
    RH2021263: Improve Security initialisation, now FIPS support no longer relies on crypto policy support
95617d
95617d
diff --git openjdk.orig/src/java.base/share/classes/java/security/Security.java openjdk/src/java.base/share/classes/java/security/Security.java
95617d
index 28ab1846173..f9726741afd 100644
95617d
--- openjdk.orig/src/java.base/share/classes/java/security/Security.java
95617d
+++ openjdk/src/java.base/share/classes/java/security/Security.java
95617d
@@ -61,10 +61,6 @@ public final class Security {
95617d
     private static final Debug sdebug =
95617d
                         Debug.getInstance("properties");
95617d
 
95617d
-    /* System property file*/
95617d
-    private static final String SYSTEM_PROPERTIES =
95617d
-        "/etc/crypto-policies/back-ends/java.config";
95617d
-
95617d
     /* The java.security properties */
95617d
     private static Properties props;
95617d
 
95617d
@@ -206,22 +202,36 @@ public final class Security {
95617d
             }
95617d
         }
95617d
 
95617d
+        if (!loadedProps) {
95617d
+            initializeStatic();
95617d
+            if (sdebug != null) {
95617d
+                sdebug.println("unable to load security properties " +
95617d
+                        "-- using defaults");
95617d
+            }
95617d
+        }
95617d
+
95617d
         String disableSystemProps = System.getProperty("java.security.disableSystemPropertiesFile");
95617d
         if ((disableSystemProps == null || "false".equalsIgnoreCase(disableSystemProps)) &&
95617d
             "true".equalsIgnoreCase(props.getProperty("security.useSystemPropertiesFile"))) {
95617d
-            if (SystemConfigurator.configure(props)) {
95617d
-                loadedProps = true;
95617d
+            if (!SystemConfigurator.configureSysProps(props)) {
95617d
+                if (sdebug != null) {
95617d
+                    sdebug.println("WARNING: System properties could not be loaded.");
95617d
+                }
95617d
             }
95617d
         }
95617d
 
95617d
-        if (!loadedProps) {
95617d
-            initializeStatic();
95617d
+        // FIPS support depends on the contents of java.security so
95617d
+        // ensure it has loaded first
95617d
+        if (loadedProps) {
95617d
+            boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
95617d
             if (sdebug != null) {
95617d
-                sdebug.println("unable to load security properties " +
95617d
-                        "-- using defaults");
95617d
+                if (fipsEnabled) {
95617d
+                    sdebug.println("FIPS support enabled.");
95617d
+                } else {
95617d
+                    sdebug.println("FIPS support disabled.");
95617d
+                }
95617d
             }
95617d
         }
95617d
-
95617d
     }
95617d
 
95617d
     /*
95617d
diff --git openjdk.orig/src/java.base/share/classes/java/security/SystemConfigurator.java openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
95617d
index 874c6221ebe..b7ed41acf0f 100644
95617d
--- openjdk.orig/src/java.base/share/classes/java/security/SystemConfigurator.java
95617d
+++ openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
95617d
@@ -76,7 +76,7 @@ final class SystemConfigurator {
95617d
      * java.security.disableSystemPropertiesFile property is not set and
95617d
      * security.useSystemPropertiesFile is true.
95617d
      */
95617d
-    static boolean configure(Properties props) {
95617d
+    static boolean configureSysProps(Properties props) {
95617d
         boolean loadedProps = false;
95617d
 
95617d
         try (BufferedInputStream bis =
95617d
@@ -96,11 +96,19 @@ final class SystemConfigurator {
95617d
                 e.printStackTrace();
95617d
             }
95617d
         }
95617d
+        return loadedProps;
95617d
+    }
95617d
+
95617d
+    /*
95617d
+     * Invoked at the end of java.security.Security initialisation
95617d
+     * if java.security properties have been loaded
95617d
+     */
95617d
+    static boolean configureFIPS(Properties props) {
95617d
+        boolean loadedProps = false;
95617d
 
95617d
         try {
95617d
             if (enableFips()) {
95617d
                 if (sdebug != null) { sdebug.println("FIPS mode detected"); }
95617d
-                loadedProps = false;
95617d
                 // Remove all security providers
95617d
                 Iterator<Entry<Object, Object>> i = props.entrySet().iterator();
95617d
                 while (i.hasNext()) {