Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

f8e459
diff --git openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
f8e459
index f9baf8c9742..60fa75cab45 100644
f8e459
--- openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
f8e459
+++ openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
f8e459
@@ -1,11 +1,13 @@
f8e459
 /*
f8e459
- * Copyright (c) 2019, Red Hat, Inc.
f8e459
+ * Copyright (c) 2019, 2020, Red Hat, Inc.
f8e459
  *
f8e459
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8e459
  *
f8e459
  * This code is free software; you can redistribute it and/or modify it
f8e459
  * under the terms of the GNU General Public License version 2 only, as
f8e459
- * published by the Free Software Foundation.
f8e459
+ * published by the Free Software Foundation.  Oracle designates this
f8e459
+ * particular file as subject to the "Classpath" exception as provided
f8e459
+ * by Oracle in the LICENSE file that accompanied this code.
f8e459
  *
f8e459
  * This code is distributed in the hope that it will be useful, but WITHOUT
f8e459
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8e459
@@ -34,10 +36,10 @@ import java.nio.file.Path;
f8e459
 import java.util.Iterator;
f8e459
 import java.util.Map.Entry;
f8e459
 import java.util.Properties;
f8e459
-import java.util.function.Consumer;
f8e459
-import java.util.regex.Matcher;
f8e459
 import java.util.regex.Pattern;
f8e459
 
f8e459
+import jdk.internal.access.JavaSecuritySystemConfiguratorAccess;
f8e459
+import jdk.internal.access.SharedSecrets;
f8e459
 import sun.security.util.Debug;
f8e459
 
f8e459
 /**
f8e459
@@ -47,7 +49,7 @@ import sun.security.util.Debug;
f8e459
  *
f8e459
  */
f8e459
 
f8e459
-class SystemConfigurator {
f8e459
+final class SystemConfigurator {
f8e459
 
f8e459
     private static final Debug sdebug =
f8e459
             Debug.getInstance("properties");
f8e459
@@ -61,15 +63,16 @@ class SystemConfigurator {
f8e459
     private static final String CRYPTO_POLICIES_CONFIG =
f8e459
             CRYPTO_POLICIES_BASE_DIR + "/config";
f8e459
 
f8e459
-    private static final class SecurityProviderInfo {
f8e459
-        int number;
f8e459
-        String key;
f8e459
-        String value;
f8e459
-        SecurityProviderInfo(int number, String key, String value) {
f8e459
-            this.number = number;
f8e459
-            this.key = key;
f8e459
-            this.value = value;
f8e459
-        }
f8e459
+    private static boolean systemFipsEnabled = false;
f8e459
+
f8e459
+    static {
f8e459
+        SharedSecrets.setJavaSecuritySystemConfiguratorAccess(
f8e459
+            new JavaSecuritySystemConfiguratorAccess() {
f8e459
+                @Override
f8e459
+                public boolean isSystemFipsEnabled() {
f8e459
+                    return SystemConfigurator.isSystemFipsEnabled();
f8e459
+                }
f8e459
+            });
f8e459
     }
f8e459
 
f8e459
     /*
f8e459
@@ -128,9 +131,9 @@ class SystemConfigurator {
f8e459
                     String nonFipsKeystoreType = props.getProperty("keystore.type");
f8e459
                     props.put("keystore.type", keystoreTypeValue);
f8e459
                     if (keystoreTypeValue.equals("PKCS11")) {
f8e459
-                    	// If keystore.type is PKCS11, javax.net.ssl.keyStore
f8e459
-                    	// must be "NONE". See JDK-8238264.
f8e459
-                    	System.setProperty("javax.net.ssl.keyStore", "NONE");
f8e459
+                        // If keystore.type is PKCS11, javax.net.ssl.keyStore
f8e459
+                        // must be "NONE". See JDK-8238264.
f8e459
+                        System.setProperty("javax.net.ssl.keyStore", "NONE");
f8e459
                     }
f8e459
                     if (System.getProperty("javax.net.ssl.trustStoreType") == null) {
f8e459
                         // If no trustStoreType has been set, use the
f8e459
@@ -144,12 +147,13 @@ class SystemConfigurator {
f8e459
                         sdebug.println("FIPS mode default keystore.type = " +
f8e459
                                 keystoreTypeValue);
f8e459
                         sdebug.println("FIPS mode javax.net.ssl.keyStore = " +
f8e459
-                        		System.getProperty("javax.net.ssl.keyStore", ""));
f8e459
+                                System.getProperty("javax.net.ssl.keyStore", ""));
f8e459
                         sdebug.println("FIPS mode javax.net.ssl.trustStoreType = " +
f8e459
                                 System.getProperty("javax.net.ssl.trustStoreType", ""));
f8e459
                     }
f8e459
                 }
f8e459
                 loadedProps = true;
f8e459
+                systemFipsEnabled = true;
f8e459
             }
f8e459
         } catch (Exception e) {
f8e459
             if (sdebug != null) {
f8e459
@@ -160,13 +164,30 @@ class SystemConfigurator {
f8e459
         return loadedProps;
f8e459
     }
f8e459
 
f8e459
+    /**
f8e459
+     * Returns whether or not global system FIPS alignment is enabled.
f8e459
+     *
f8e459
+     * Value is always 'false' before java.security.Security class is
f8e459
+     * initialized.
f8e459
+     *
f8e459
+     * Call from out of this package through SharedSecrets:
f8e459
+     *   SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
f8e459
+     *           .isSystemFipsEnabled();
f8e459
+     *
f8e459
+     * @return  a boolean value indicating whether or not global
f8e459
+     *          system FIPS alignment is enabled.
f8e459
+     */
f8e459
+    static boolean isSystemFipsEnabled() {
f8e459
+        return systemFipsEnabled;
f8e459
+    }
f8e459
+
f8e459
     /*
f8e459
      * FIPS is enabled only if crypto-policies are set to "FIPS"
f8e459
      * and the com.redhat.fips property is true.
f8e459
      */
f8e459
     private static boolean enableFips() throws Exception {
f8e459
-        boolean fipsEnabled = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
f8e459
-        if (fipsEnabled) {
f8e459
+        boolean shouldEnable = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
f8e459
+        if (shouldEnable) {
f8e459
             String cryptoPoliciesConfig = new String(Files.readAllBytes(Path.of(CRYPTO_POLICIES_CONFIG)));
f8e459
             if (sdebug != null) { sdebug.println("Crypto config:\n" + cryptoPoliciesConfig); }
f8e459
             Pattern pattern = Pattern.compile("^FIPS$", Pattern.MULTILINE);
f8e459
diff --git openjdk/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java openjdk/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java
f8e459
new file mode 100644
f8e459
index 00000000000..a31e93ec02e
f8e459
--- /dev/null
f8e459
+++ openjdk/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java
f8e459
@@ -0,0 +1,30 @@
f8e459
+/*
f8e459
+ * Copyright (c) 2020, Red Hat, Inc.
f8e459
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8e459
+ *
f8e459
+ * This code is free software; you can redistribute it and/or modify it
f8e459
+ * under the terms of the GNU General Public License version 2 only, as
f8e459
+ * published by the Free Software Foundation.  Oracle designates this
f8e459
+ * particular file as subject to the "Classpath" exception as provided
f8e459
+ * by Oracle in the LICENSE file that accompanied this code.
f8e459
+ *
f8e459
+ * This code is distributed in the hope that it will be useful, but WITHOUT
f8e459
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8e459
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8e459
+ * version 2 for more details (a copy is included in the LICENSE file that
f8e459
+ * accompanied this code).
f8e459
+ *
f8e459
+ * You should have received a copy of the GNU General Public License version
f8e459
+ * 2 along with this work; if not, write to the Free Software Foundation,
f8e459
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8e459
+ *
f8e459
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8e459
+ * or visit www.oracle.com if you need additional information or have any
f8e459
+ * questions.
f8e459
+ */
f8e459
+
f8e459
+package jdk.internal.access;
f8e459
+
f8e459
+public interface JavaSecuritySystemConfiguratorAccess {
f8e459
+    boolean isSystemFipsEnabled();
f8e459
+}
f8e459
diff --git openjdk/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java openjdk/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
f8e459
index f6d3638c3dd..5a2c9eb0c46 100644
f8e459
--- openjdk/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
f8e459
+++ openjdk/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
f8e459
@@ -81,6 +81,7 @@ public class SharedSecrets {
f8e459
     private static JavaSecuritySpecAccess javaSecuritySpecAccess;
f8e459
     private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
f8e459
     private static JavaxCryptoSpecAccess javaxCryptoSpecAccess;
f8e459
+    private static JavaSecuritySystemConfiguratorAccess javaSecuritySystemConfiguratorAccess;
f8e459
 
f8e459
     public static void setJavaUtilCollectionAccess(JavaUtilCollectionAccess juca) {
f8e459
         javaUtilCollectionAccess = juca;
f8e459
@@ -442,4 +443,12 @@ public class SharedSecrets {
f8e459
             MethodHandles.lookup().ensureInitialized(c);
f8e459
         } catch (IllegalAccessException e) {}
f8e459
     }
f8e459
+
f8e459
+    public static void setJavaSecuritySystemConfiguratorAccess(JavaSecuritySystemConfiguratorAccess jssca) {
f8e459
+        javaSecuritySystemConfiguratorAccess = jssca;
f8e459
+    }
f8e459
+
f8e459
+    public static JavaSecuritySystemConfiguratorAccess getJavaSecuritySystemConfiguratorAccess() {
f8e459
+        return javaSecuritySystemConfiguratorAccess;
f8e459
+    }
f8e459
 }
f8e459
diff --git openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
f8e459
index 6ffdfeda18d..775b185fb06 100644
f8e459
--- openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
f8e459
+++ openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
f8e459
@@ -32,6 +32,7 @@ import java.security.cert.*;
f8e459
 import java.util.*;
f8e459
 import java.util.concurrent.locks.ReentrantLock;
f8e459
 import javax.net.ssl.*;
f8e459
+import jdk.internal.access.SharedSecrets;
f8e459
 import sun.security.action.GetPropertyAction;
f8e459
 import sun.security.provider.certpath.AlgorithmChecker;
f8e459
 import sun.security.validator.Validator;
f8e459
@@ -536,22 +537,40 @@ public abstract class SSLContextImpl extends SSLContextSpi {
f8e459
         private static final List<CipherSuite> serverDefaultCipherSuites;
f8e459
 
f8e459
         static {
f8e459
-            supportedProtocols = Arrays.asList(
f8e459
-                ProtocolVersion.TLS13,
f8e459
-                ProtocolVersion.TLS12,
f8e459
-                ProtocolVersion.TLS11,
f8e459
-                ProtocolVersion.TLS10,
f8e459
-                ProtocolVersion.SSL30,
f8e459
-                ProtocolVersion.SSL20Hello
f8e459
-            );
f8e459
-
f8e459
-            serverDefaultProtocols = getAvailableProtocols(
f8e459
-                    new ProtocolVersion[] {
f8e459
-                ProtocolVersion.TLS13,
f8e459
-                ProtocolVersion.TLS12,
f8e459
-                ProtocolVersion.TLS11,
f8e459
-                ProtocolVersion.TLS10
f8e459
-            });
f8e459
+            if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
f8e459
+                    .isSystemFipsEnabled()) {
f8e459
+                // RH1860986: TLSv1.3 key derivation not supported with
f8e459
+                // the Security Providers available in system FIPS mode.
f8e459
+                supportedProtocols = Arrays.asList(
f8e459
+                    ProtocolVersion.TLS12,
f8e459
+                    ProtocolVersion.TLS11,
f8e459
+                    ProtocolVersion.TLS10
f8e459
+                );
f8e459
+
f8e459
+                serverDefaultProtocols = getAvailableProtocols(
f8e459
+                        new ProtocolVersion[] {
f8e459
+                    ProtocolVersion.TLS12,
f8e459
+                    ProtocolVersion.TLS11,
f8e459
+                    ProtocolVersion.TLS10
f8e459
+                });
f8e459
+            } else {
f8e459
+                supportedProtocols = Arrays.asList(
f8e459
+                    ProtocolVersion.TLS13,
f8e459
+                    ProtocolVersion.TLS12,
f8e459
+                    ProtocolVersion.TLS11,
f8e459
+                    ProtocolVersion.TLS10,
f8e459
+                    ProtocolVersion.SSL30,
f8e459
+                    ProtocolVersion.SSL20Hello
f8e459
+                );
f8e459
+
f8e459
+                serverDefaultProtocols = getAvailableProtocols(
f8e459
+                        new ProtocolVersion[] {
f8e459
+                    ProtocolVersion.TLS13,
f8e459
+                    ProtocolVersion.TLS12,
f8e459
+                    ProtocolVersion.TLS11,
f8e459
+                    ProtocolVersion.TLS10
f8e459
+                });
f8e459
+            }
f8e459
 
f8e459
             supportedCipherSuites = getApplicableSupportedCipherSuites(
f8e459
                     supportedProtocols);
f8e459
@@ -842,12 +861,23 @@ public abstract class SSLContextImpl extends SSLContextSpi {
f8e459
             ProtocolVersion[] candidates;
f8e459
             if (refactored.isEmpty()) {
f8e459
                 // Client and server use the same default protocols.
f8e459
-                candidates = new ProtocolVersion[] {
f8e459
-                        ProtocolVersion.TLS13,
f8e459
-                        ProtocolVersion.TLS12,
f8e459
-                        ProtocolVersion.TLS11,
f8e459
-                        ProtocolVersion.TLS10
f8e459
-                    };
f8e459
+                if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
f8e459
+                        .isSystemFipsEnabled()) {
f8e459
+                    // RH1860986: TLSv1.3 key derivation not supported with
f8e459
+                    // the Security Providers available in system FIPS mode.
f8e459
+                    candidates = new ProtocolVersion[] {
f8e459
+                            ProtocolVersion.TLS12,
f8e459
+                            ProtocolVersion.TLS11,
f8e459
+                            ProtocolVersion.TLS10
f8e459
+                        };
f8e459
+                } else {
f8e459
+                    candidates = new ProtocolVersion[] {
f8e459
+                            ProtocolVersion.TLS13,
f8e459
+                            ProtocolVersion.TLS12,
f8e459
+                            ProtocolVersion.TLS11,
f8e459
+                            ProtocolVersion.TLS10
f8e459
+                        };
f8e459
+                }
f8e459
             } else {
f8e459
                 // Use the customized TLS protocols.
f8e459
                 candidates =
f8e459
diff --git openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
f8e459
index 894e26dfad8..8b16378b96b 100644
f8e459
--- openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
f8e459
+++ openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
f8e459
@@ -27,6 +27,8 @@ package sun.security.ssl;
f8e459
 
f8e459
 import java.security.*;
f8e459
 import java.util.*;
f8e459
+
f8e459
+import jdk.internal.access.SharedSecrets;
f8e459
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
f8e459
 
f8e459
 /**
f8e459
@@ -102,8 +104,13 @@ public class SunJSSE extends java.security.Provider {
f8e459
             "sun.security.ssl.SSLContextImpl$TLS11Context", null, null);
f8e459
         ps("SSLContext", "TLSv1.2",
f8e459
             "sun.security.ssl.SSLContextImpl$TLS12Context", null, null);
f8e459
-        ps("SSLContext", "TLSv1.3",
f8e459
-            "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
f8e459
+        if (!SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
f8e459
+                .isSystemFipsEnabled()) {
f8e459
+            // RH1860986: TLSv1.3 key derivation not supported with
f8e459
+            // the Security Providers available in system FIPS mode.
f8e459
+            ps("SSLContext", "TLSv1.3",
f8e459
+                "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
f8e459
+        }
f8e459
         ps("SSLContext", "TLS",
f8e459
             "sun.security.ssl.SSLContextImpl$TLSContext",
f8e459
             List.of("SSL"), null);