Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

673b76
diff -r bbc65dfa59d1 src/java.base/share/classes/java/security/SystemConfigurator.java
673b76
--- openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java	Thu Jan 23 18:22:31 2020 -0300
673b76
+++ openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java	Sat Aug 01 23:16:51 2020 -0300
673b76
@@ -1,11 +1,13 @@
673b76
 /*
673b76
- * Copyright (c) 2019, Red Hat, Inc.
673b76
+ * Copyright (c) 2019, 2020, Red Hat, Inc.
673b76
  *
673b76
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
673b76
  *
673b76
  * This code is free software; you can redistribute it and/or modify it
673b76
  * under the terms of the GNU General Public License version 2 only, as
673b76
- * published by the Free Software Foundation.
673b76
+ * published by the Free Software Foundation.  Oracle designates this
673b76
+ * particular file as subject to the "Classpath" exception as provided
673b76
+ * by Oracle in the LICENSE file that accompanied this code.
673b76
  *
673b76
  * This code is distributed in the hope that it will be useful, but WITHOUT
673b76
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
673b76
@@ -34,10 +36,10 @@
673b76
 import java.util.Iterator;
673b76
 import java.util.Map.Entry;
673b76
 import java.util.Properties;
673b76
-import java.util.function.Consumer;
673b76
-import java.util.regex.Matcher;
673b76
 import java.util.regex.Pattern;
673b76
 
673b76
+import jdk.internal.misc.SharedSecrets;
673b76
+import jdk.internal.misc.JavaSecuritySystemConfiguratorAccess;
673b76
 import sun.security.util.Debug;
673b76
 
673b76
 /**
673b76
@@ -47,7 +49,7 @@
673b76
  *
673b76
  */
673b76
 
673b76
-class SystemConfigurator {
673b76
+final class SystemConfigurator {
673b76
 
673b76
     private static final Debug sdebug =
673b76
             Debug.getInstance("properties");
673b76
@@ -61,15 +63,16 @@
673b76
     private static final String CRYPTO_POLICIES_CONFIG =
673b76
             CRYPTO_POLICIES_BASE_DIR + "/config";
673b76
 
673b76
-    private static final class SecurityProviderInfo {
673b76
-        int number;
673b76
-        String key;
673b76
-        String value;
673b76
-        SecurityProviderInfo(int number, String key, String value) {
673b76
-            this.number = number;
673b76
-            this.key = key;
673b76
-            this.value = value;
673b76
-        }
673b76
+    private static boolean systemFipsEnabled = false;
673b76
+
673b76
+    static {
673b76
+        SharedSecrets.setJavaSecuritySystemConfiguratorAccess(
673b76
+            new JavaSecuritySystemConfiguratorAccess() {
673b76
+                @Override
673b76
+                public boolean isSystemFipsEnabled() {
673b76
+                    return SystemConfigurator.isSystemFipsEnabled();
673b76
+                }
673b76
+            });
673b76
     }
673b76
 
673b76
     /*
673b76
@@ -128,9 +131,9 @@
673b76
                     String nonFipsKeystoreType = props.getProperty("keystore.type");
673b76
                     props.put("keystore.type", keystoreTypeValue);
673b76
                     if (keystoreTypeValue.equals("PKCS11")) {
673b76
-                    	// If keystore.type is PKCS11, javax.net.ssl.keyStore
673b76
-                    	// must be "NONE". See JDK-8238264.
673b76
-                    	System.setProperty("javax.net.ssl.keyStore", "NONE");
673b76
+                        // If keystore.type is PKCS11, javax.net.ssl.keyStore
673b76
+                        // must be "NONE". See JDK-8238264.
673b76
+                        System.setProperty("javax.net.ssl.keyStore", "NONE");
673b76
                     }
673b76
                     if (System.getProperty("javax.net.ssl.trustStoreType") == null) {
673b76
                         // If no trustStoreType has been set, use the
673b76
@@ -144,12 +147,13 @@
673b76
                         sdebug.println("FIPS mode default keystore.type = " +
673b76
                                 keystoreTypeValue);
673b76
                         sdebug.println("FIPS mode javax.net.ssl.keyStore = " +
673b76
-                        		System.getProperty("javax.net.ssl.keyStore", ""));
673b76
+                                System.getProperty("javax.net.ssl.keyStore", ""));
673b76
                         sdebug.println("FIPS mode javax.net.ssl.trustStoreType = " +
673b76
                                 System.getProperty("javax.net.ssl.trustStoreType", ""));
673b76
                     }
673b76
                 }
673b76
                 loadedProps = true;
673b76
+                systemFipsEnabled = true;
673b76
             }
673b76
         } catch (Exception e) {
673b76
             if (sdebug != null) {
673b76
@@ -160,13 +164,30 @@
673b76
         return loadedProps;
673b76
     }
673b76
 
673b76
+    /**
673b76
+     * Returns whether or not global system FIPS alignment is enabled.
673b76
+     *
673b76
+     * Value is always 'false' before java.security.Security class is
673b76
+     * initialized.
673b76
+     *
673b76
+     * Call from out of this package through SharedSecrets:
673b76
+     *   SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
673b76
+     *           .isSystemFipsEnabled();
673b76
+     *
673b76
+     * @return  a boolean value indicating whether or not global
673b76
+     *          system FIPS alignment is enabled.
673b76
+     */
673b76
+    static boolean isSystemFipsEnabled() {
673b76
+        return systemFipsEnabled;
673b76
+    }
673b76
+
673b76
     /*
673b76
      * FIPS is enabled only if crypto-policies are set to "FIPS"
673b76
      * and the com.redhat.fips property is true.
673b76
      */
673b76
     private static boolean enableFips() throws Exception {
673b76
-        boolean fipsEnabled = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
673b76
-        if (fipsEnabled) {
673b76
+        boolean shouldEnable = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
673b76
+        if (shouldEnable) {
673b76
             String cryptoPoliciesConfig = new String(Files.readAllBytes(Path.of(CRYPTO_POLICIES_CONFIG)));
673b76
             if (sdebug != null) { sdebug.println("Crypto config:\n" + cryptoPoliciesConfig); }
673b76
             Pattern pattern = Pattern.compile("^FIPS$", Pattern.MULTILINE);
673b76
diff -r bbc65dfa59d1 src/java.base/share/classes/jdk/internal/misc/JavaSecuritySystemConfiguratorAccess.java
673b76
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
673b76
+++ openjdk/src/java.base/share/classes/jdk/internal/misc/JavaSecuritySystemConfiguratorAccess.java	Sat Aug 01 23:16:51 2020 -0300
673b76
@@ -0,0 +1,30 @@
673b76
+/*
673b76
+ * Copyright (c) 2020, Red Hat, Inc.
673b76
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
673b76
+ *
673b76
+ * This code is free software; you can redistribute it and/or modify it
673b76
+ * under the terms of the GNU General Public License version 2 only, as
673b76
+ * published by the Free Software Foundation.  Oracle designates this
673b76
+ * particular file as subject to the "Classpath" exception as provided
673b76
+ * by Oracle in the LICENSE file that accompanied this code.
673b76
+ *
673b76
+ * This code is distributed in the hope that it will be useful, but WITHOUT
673b76
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
673b76
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
673b76
+ * version 2 for more details (a copy is included in the LICENSE file that
673b76
+ * accompanied this code).
673b76
+ *
673b76
+ * You should have received a copy of the GNU General Public License version
673b76
+ * 2 along with this work; if not, write to the Free Software Foundation,
673b76
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
673b76
+ *
673b76
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
673b76
+ * or visit www.oracle.com if you need additional information or have any
673b76
+ * questions.
673b76
+ */
673b76
+
673b76
+package jdk.internal.misc;
673b76
+
673b76
+public interface JavaSecuritySystemConfiguratorAccess {
673b76
+    boolean isSystemFipsEnabled();
673b76
+}
673b76
diff -r bbc65dfa59d1 src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java
673b76
--- openjdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java	Thu Jan 23 18:22:31 2020 -0300
673b76
+++ openjdk/src/java.base/share/classes/jdk/internal/misc/SharedSecrets.java	Sat Aug 01 23:16:51 2020 -0300
673b76
@@ -76,6 +76,7 @@
673b76
     private static JavaIORandomAccessFileAccess javaIORandomAccessFileAccess;
673b76
     private static JavaSecuritySignatureAccess javaSecuritySignatureAccess;
673b76
     private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
673b76
+    private static JavaSecuritySystemConfiguratorAccess javaSecuritySystemConfiguratorAccess;
673b76
 
673b76
     public static JavaUtilJarAccess javaUtilJarAccess() {
673b76
         if (javaUtilJarAccess == null) {
673b76
@@ -361,4 +362,12 @@
673b76
         }
673b76
         return javaxCryptoSealedObjectAccess;
673b76
     }
673b76
+
673b76
+    public static void setJavaSecuritySystemConfiguratorAccess(JavaSecuritySystemConfiguratorAccess jssca) {
673b76
+        javaSecuritySystemConfiguratorAccess = jssca;
673b76
+    }
673b76
+
673b76
+    public static JavaSecuritySystemConfiguratorAccess getJavaSecuritySystemConfiguratorAccess() {
673b76
+        return javaSecuritySystemConfiguratorAccess;
673b76
+    }
673b76
 }
673b76
diff -r bbc65dfa59d1 src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
673b76
--- openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java	Thu Jan 23 18:22:31 2020 -0300
673b76
+++ openjdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java	Sat Aug 01 23:16:51 2020 -0300
673b76
@@ -31,6 +31,7 @@
673b76
 import java.security.cert.*;
673b76
 import java.util.*;
673b76
 import javax.net.ssl.*;
673b76
+import jdk.internal.misc.SharedSecrets;
673b76
 import sun.security.action.GetPropertyAction;
673b76
 import sun.security.provider.certpath.AlgorithmChecker;
673b76
 import sun.security.validator.Validator;
673b76
@@ -542,20 +543,38 @@
673b76
 
673b76
         static {
673b76
             if (SunJSSE.isFIPS()) {
673b76
-                supportedProtocols = Arrays.asList(
673b76
-                    ProtocolVersion.TLS13,
673b76
-                    ProtocolVersion.TLS12,
673b76
-                    ProtocolVersion.TLS11,
673b76
-                    ProtocolVersion.TLS10
673b76
-                );
673b76
+                if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
673b76
+                        .isSystemFipsEnabled()) {
673b76
+                    // RH1860986: TLSv1.3 key derivation not supported with
673b76
+                    // the Security Providers available in system FIPS mode.
673b76
+                    supportedProtocols = Arrays.asList(
673b76
+                        ProtocolVersion.TLS12,
673b76
+                        ProtocolVersion.TLS11,
673b76
+                        ProtocolVersion.TLS10
673b76
+                    );
673b76
 
673b76
-                serverDefaultProtocols = getAvailableProtocols(
673b76
-                        new ProtocolVersion[] {
673b76
-                    ProtocolVersion.TLS13,
673b76
-                    ProtocolVersion.TLS12,
673b76
-                    ProtocolVersion.TLS11,
673b76
-                    ProtocolVersion.TLS10
673b76
-                });
673b76
+                    serverDefaultProtocols = getAvailableProtocols(
673b76
+                            new ProtocolVersion[] {
673b76
+                        ProtocolVersion.TLS12,
673b76
+                        ProtocolVersion.TLS11,
673b76
+                        ProtocolVersion.TLS10
673b76
+                    });
673b76
+                } else {
673b76
+                    supportedProtocols = Arrays.asList(
673b76
+                        ProtocolVersion.TLS13,
673b76
+                        ProtocolVersion.TLS12,
673b76
+                        ProtocolVersion.TLS11,
673b76
+                        ProtocolVersion.TLS10
673b76
+                    );
673b76
+
673b76
+                    serverDefaultProtocols = getAvailableProtocols(
673b76
+                            new ProtocolVersion[] {
673b76
+                        ProtocolVersion.TLS13,
673b76
+                        ProtocolVersion.TLS12,
673b76
+                        ProtocolVersion.TLS11,
673b76
+                        ProtocolVersion.TLS10
673b76
+                    });
673b76
+                }
673b76
             } else {
673b76
                 supportedProtocols = Arrays.asList(
673b76
                     ProtocolVersion.TLS13,
673b76
@@ -620,6 +639,16 @@
673b76
 
673b76
         static ProtocolVersion[] getSupportedProtocols() {
673b76
             if (SunJSSE.isFIPS()) {
673b76
+                if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
673b76
+                        .isSystemFipsEnabled()) {
673b76
+                    // RH1860986: TLSv1.3 key derivation not supported with
673b76
+                    // the Security Providers available in system FIPS mode.
673b76
+                    return new ProtocolVersion[] {
673b76
+                            ProtocolVersion.TLS12,
673b76
+                            ProtocolVersion.TLS11,
673b76
+                            ProtocolVersion.TLS10
673b76
+                    };
673b76
+                }
673b76
                 return new ProtocolVersion[] {
673b76
                         ProtocolVersion.TLS13,
673b76
                         ProtocolVersion.TLS12,
673b76
@@ -949,6 +978,16 @@
673b76
 
673b76
         static ProtocolVersion[] getProtocols() {
673b76
             if (SunJSSE.isFIPS()) {
673b76
+                if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
673b76
+                        .isSystemFipsEnabled()) {
673b76
+                    // RH1860986: TLSv1.3 key derivation not supported with
673b76
+                    // the Security Providers available in system FIPS mode.
673b76
+                    return new ProtocolVersion[] {
673b76
+                            ProtocolVersion.TLS12,
673b76
+                            ProtocolVersion.TLS11,
673b76
+                            ProtocolVersion.TLS10
673b76
+                    };
673b76
+                }
673b76
                 return new ProtocolVersion[]{
673b76
                         ProtocolVersion.TLS13,
673b76
                         ProtocolVersion.TLS12,
673b76
diff -r bbc65dfa59d1 src/java.base/share/classes/sun/security/ssl/SunJSSE.java
673b76
--- openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java	Thu Jan 23 18:22:31 2020 -0300
673b76
+++ openjdk/src/java.base/share/classes/sun/security/ssl/SunJSSE.java	Sat Aug 01 23:16:51 2020 -0300
673b76
@@ -27,6 +27,8 @@
673b76
 
673b76
 import java.security.*;
673b76
 import java.util.*;
673b76
+
673b76
+import jdk.internal.misc.SharedSecrets;
673b76
 import sun.security.rsa.SunRsaSignEntries;
673b76
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
673b76
 import static sun.security.provider.SunEntries.createAliases;
673b76
@@ -195,8 +197,13 @@
673b76
             "sun.security.ssl.SSLContextImpl$TLS11Context", null, null);
673b76
         ps("SSLContext", "TLSv1.2",
673b76
             "sun.security.ssl.SSLContextImpl$TLS12Context", null, null);
673b76
-        ps("SSLContext", "TLSv1.3",
673b76
-            "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
673b76
+        if (!SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
673b76
+                .isSystemFipsEnabled()) {
673b76
+            // RH1860986: TLSv1.3 key derivation not supported with
673b76
+            // the Security Providers available in system FIPS mode.
673b76
+            ps("SSLContext", "TLSv1.3",
673b76
+                "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
673b76
+        }
673b76
         ps("SSLContext", "TLS",
673b76
             "sun.security.ssl.SSLContextImpl$TLSContext",
673b76
             (isfips? null : createAliases("SSL")), null);