Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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