Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

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