Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

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