Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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