Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

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