Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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