Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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