Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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