Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

f78b6c
commit aaf92165ad1cbb1c9818eb60178c91293e13b053
f78b6c
Author: Andrew John Hughes <andrew@openjdk.org>
f78b6c
Date:   Mon Jan 24 15:13:14 2022 +0000
f78b6c
f78b6c
    RH2021263: Improve Security initialisation, now FIPS support no longer relies on crypto policy support
f78b6c
f78b6c
diff --git openjdk.orig/jdk/src/share/classes/java/security/Security.java openjdk/jdk/src/share/classes/java/security/Security.java
f78b6c
index fa494b680f..b5aa5c749d 100644
f78b6c
--- openjdk.orig/jdk/src/share/classes/java/security/Security.java
f78b6c
+++ openjdk/jdk/src/share/classes/java/security/Security.java
f78b6c
@@ -57,10 +57,6 @@ public final class Security {
f78b6c
     private static final Debug sdebug =
f78b6c
                         Debug.getInstance("properties");
f78b6c
 
f78b6c
-    /* System property file*/
f78b6c
-    private static final String SYSTEM_PROPERTIES =
f78b6c
-        "/etc/crypto-policies/back-ends/java.config";
f78b6c
-
f78b6c
     /* The java.security properties */
f78b6c
     private static Properties props;
f78b6c
 
f78b6c
@@ -202,13 +198,6 @@ public final class Security {
f78b6c
             }
f78b6c
         }
f78b6c
 
f78b6c
-        String disableSystemProps = System.getProperty("java.security.disableSystemPropertiesFile");
f78b6c
-        if (disableSystemProps == null &&
f78b6c
-            "true".equalsIgnoreCase(props.getProperty
f78b6c
-                ("security.useSystemPropertiesFile"))) {
f78b6c
-            loadedProps = loadedProps && SystemConfigurator.configure(props);
f78b6c
-        }
f78b6c
-
f78b6c
         if (!loadedProps) {
f78b6c
             initializeStatic();
f78b6c
             if (sdebug != null) {
f78b6c
@@ -217,6 +206,28 @@ public final class Security {
f78b6c
             }
f78b6c
         }
f78b6c
 
f78b6c
+        String disableSystemProps = System.getProperty("java.security.disableSystemPropertiesFile");
f78b6c
+        if ((disableSystemProps == null || "false".equalsIgnoreCase(disableSystemProps)) &&
f78b6c
+            "true".equalsIgnoreCase(props.getProperty("security.useSystemPropertiesFile"))) {
f78b6c
+            if (!SystemConfigurator.configureSysProps(props)) {
f78b6c
+                if (sdebug != null) {
f78b6c
+                    sdebug.println("WARNING: System properties could not be loaded.");
f78b6c
+                }
f78b6c
+            }
f78b6c
+        }
f78b6c
+
f78b6c
+        // FIPS support depends on the contents of java.security so
f78b6c
+        // ensure it has loaded first
f78b6c
+        if (loadedProps) {
f78b6c
+            boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
f78b6c
+             if (sdebug != null) {
f78b6c
+                if (fipsEnabled) {
f78b6c
+                    sdebug.println("FIPS support enabled.");
f78b6c
+                } else {
f78b6c
+                    sdebug.println("FIPS support disabled.");
f78b6c
+                }
f78b6c
+             }
f78b6c
+        }
f78b6c
     }
f78b6c
 
f78b6c
     /*
f78b6c
diff --git openjdk.orig/jdk/src/share/classes/java/security/SystemConfigurator.java openjdk/jdk/src/share/classes/java/security/SystemConfigurator.java
f78b6c
index d1f677597d..7da65b1d2c 100644
f78b6c
--- openjdk.orig/jdk/src/share/classes/java/security/SystemConfigurator.java
f78b6c
+++ openjdk/jdk/src/share/classes/java/security/SystemConfigurator.java
f78b6c
@@ -76,7 +76,7 @@ final class SystemConfigurator {
f78b6c
      * java.security.disableSystemPropertiesFile property is not set and
f78b6c
      * security.useSystemPropertiesFile is true.
f78b6c
      */
f78b6c
-    static boolean configure(Properties props) {
f78b6c
+    static boolean configureSysProps(Properties props) {
f78b6c
         boolean loadedProps = false;
f78b6c
 
f78b6c
         try (BufferedInputStream bis =
f78b6c
@@ -96,11 +96,19 @@ final class SystemConfigurator {
f78b6c
                 e.printStackTrace();
f78b6c
             }
f78b6c
         }
f78b6c
+        return loadedProps;
f78b6c
+    }
f78b6c
+
f78b6c
+    /*
f78b6c
+     * Invoked at the end of java.security.Security initialisation
f78b6c
+     * if java.security properties have been loaded
f78b6c
+     */
f78b6c
+    static boolean configureFIPS(Properties props) {
f78b6c
+        boolean loadedProps = false;
f78b6c
 
f78b6c
         try {
f78b6c
             if (enableFips()) {
f78b6c
                 if (sdebug != null) { sdebug.println("FIPS mode detected"); }
f78b6c
-                loadedProps = false;
f78b6c
                 // Remove all security providers
f78b6c
                 Iterator<Entry<Object, Object>> i = props.entrySet().iterator();
f78b6c
                 while (i.hasNext()) {