Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

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