Blame SOURCES/rh1860986-disable_tlsv1.3_in_fips_mode.patch

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