Blame SOURCES/rh2021263-fips_separate_policy_and_fips_init.patch

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