Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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