Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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