Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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