Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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