Blame SOURCES/pr2888-rh2055274-support_system_cacerts.patch

87b62d
diff --git a/jdk/src/share/classes/sun/security/ssl/TrustStoreManager.java b/jdk/src/share/classes/sun/security/ssl/TrustStoreManager.java
87b62d
index e7b4763db53..e8ec8467e6a 100644
87b62d
--- a/jdk/src/share/classes/sun/security/ssl/TrustStoreManager.java
87b62d
+++ b/jdk/src/share/classes/sun/security/ssl/TrustStoreManager.java
87b62d
@@ -31,6 +31,7 @@ import java.security.*;
87b62d
 import java.security.cert.*;
87b62d
 import java.util.*;
87b62d
 import sun.security.action.*;
87b62d
+import sun.security.tools.KeyStoreUtil;
87b62d
 import sun.security.validator.TrustStoreUtil;
87b62d
 
87b62d
 /**
87b62d
@@ -68,7 +69,7 @@ final class TrustStoreManager {
87b62d
      * The preference of the default trusted KeyStore is:
87b62d
      *    javax.net.ssl.trustStore
87b62d
      *    jssecacerts
87b62d
-     *    cacerts
87b62d
+     *    cacerts (system and local)
87b62d
      */
87b62d
     private static final class TrustStoreDescriptor {
87b62d
         private static final String fileSep = File.separator;
87b62d
@@ -76,7 +77,7 @@ final class TrustStoreManager {
87b62d
                 GetPropertyAction.privilegedGetProperty("java.home") +
87b62d
                 fileSep + "lib" + fileSep + "security";
87b62d
         private static final String defaultStore =
87b62d
-                defaultStorePath + fileSep + "cacerts";
87b62d
+            KeyStoreUtil.getCacertsKeyStoreFile().getPath();
87b62d
         private static final String jsseDefaultStore =
87b62d
                 defaultStorePath + fileSep + "jssecacerts";
87b62d
 
87b62d
@@ -139,6 +140,10 @@ final class TrustStoreManager {
87b62d
                     String storePropPassword = System.getProperty(
87b62d
                             "javax.net.ssl.trustStorePassword", "");
87b62d
 
87b62d
+                    if (SSLLogger.isOn && SSLLogger.isOn("trustmanager")) {
87b62d
+                        SSLLogger.fine("Default store: " + defaultStore);
87b62d
+                    }
87b62d
+
87b62d
                     String temporaryName = "";
87b62d
                     File temporaryFile = null;
87b62d
                     long temporaryTime = 0L;
87b62d
@@ -146,21 +151,22 @@ final class TrustStoreManager {
87b62d
                         String[] fileNames =
87b62d
                                 new String[] {storePropName, defaultStore};
87b62d
                         for (String fileName : fileNames) {
87b62d
-                            File f = new File(fileName);
87b62d
-                            if (f.isFile() && f.canRead()) {
87b62d
-                                temporaryName = fileName;;
87b62d
-                                temporaryFile = f;
87b62d
-                                temporaryTime = f.lastModified();
87b62d
-
87b62d
-                                break;
87b62d
-                            }
87b62d
-
87b62d
-                            // Not break, the file is inaccessible.
87b62d
-                            if (SSLLogger.isOn &&
87b62d
+                            if (fileName != null && !"".equals(fileName)) {
87b62d
+                                File f = new File(fileName);
87b62d
+                                if (f.isFile() && f.canRead()) {
87b62d
+                                    temporaryName = fileName;;
87b62d
+                                    temporaryFile = f;
87b62d
+                                    temporaryTime = f.lastModified();
87b62d
+
87b62d
+                                    break;
87b62d
+                                }
87b62d
+                                // Not break, the file is inaccessible.
87b62d
+                                if (SSLLogger.isOn &&
87b62d
                                     SSLLogger.isOn("trustmanager")) {
87b62d
-                                SSLLogger.fine(
87b62d
-                                        "Inaccessible trust store: " +
87b62d
-                                        storePropName);
87b62d
+                                    SSLLogger.fine(
87b62d
+                                            "Inaccessible trust store: " +
87b62d
+                                            fileName);
87b62d
+                                }
87b62d
                             }
87b62d
                         }
87b62d
                     } else {
87b62d
diff --git a/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java b/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java
87b62d
index fcc77786da1..f554f83a8b4 100644
87b62d
--- a/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java
87b62d
+++ b/jdk/src/share/classes/sun/security/tools/KeyStoreUtil.java
87b62d
@@ -33,7 +33,10 @@ import java.io.InputStreamReader;
87b62d
 
87b62d
 import java.net.URL;
87b62d
 
87b62d
+import java.security.AccessController;
87b62d
 import java.security.KeyStore;
87b62d
+import java.security.PrivilegedAction;
87b62d
+import java.security.Security;
87b62d
 
87b62d
 import java.security.cert.X509Certificate;
87b62d
 import java.text.Collator;
87b62d
@@ -54,6 +57,33 @@ public class KeyStoreUtil {
87b62d
 
87b62d
     private static final String JKS = "jks";
87b62d
 
87b62d
+    private static final String PROP_NAME = "security.systemCACerts";
87b62d
+
87b62d
+    /**
87b62d
+     * Returns the value of the security property propName, which can be overridden
87b62d
+     * by a system property of the same name
87b62d
+     *
87b62d
+     * @param  propName the name of the system or security property
87b62d
+     * @return the value of the system or security property
87b62d
+     */
87b62d
+    @SuppressWarnings("removal")
87b62d
+    public static String privilegedGetOverridable(String propName) {
87b62d
+        if (System.getSecurityManager() == null) {
87b62d
+            return getOverridableProperty(propName);
87b62d
+        } else {
87b62d
+            return AccessController.doPrivileged((PrivilegedAction<String>) () -> getOverridableProperty(propName));
87b62d
+        }
87b62d
+    }
87b62d
+
87b62d
+    private static String getOverridableProperty(String propName) {
87b62d
+        String val = System.getProperty(propName);
87b62d
+        if (val == null) {
87b62d
+            return Security.getProperty(propName);
87b62d
+        } else {
87b62d
+            return val;
87b62d
+        }
87b62d
+    }
87b62d
+
87b62d
     /**
87b62d
      * Returns true if the certificate is self-signed, false otherwise.
87b62d
      */
87b62d
@@ -96,20 +126,38 @@ public class KeyStoreUtil {
87b62d
         }
87b62d
     }
87b62d
 
87b62d
+    /**
87b62d
+     * Returns the path to the cacerts DB
87b62d
+     */
87b62d
+    public static File getCacertsKeyStoreFile()
87b62d
+    {
87b62d
+        String sep = File.separator;
87b62d
+        File file = null;
87b62d
+        /* Check system cacerts DB first, preferring system property over security property */
87b62d
+        String systemDB = privilegedGetOverridable(PROP_NAME);
87b62d
+        if (systemDB != null && !"".equals(systemDB)) {
87b62d
+            file = new File(systemDB);
87b62d
+        }
87b62d
+        if (file == null || !file.exists()) {
87b62d
+            file = new File(System.getProperty("java.home") + sep
87b62d
+                            + "lib" + sep + "security" + sep
87b62d
+                            + "cacerts");
87b62d
+        }
87b62d
+        if (file.exists()) {
87b62d
+            return file;
87b62d
+        }
87b62d
+        return null;
87b62d
+    }
87b62d
+
87b62d
     /**
87b62d
      * Returns the keystore with the configured CA certificates.
87b62d
      */
87b62d
     public static KeyStore getCacertsKeyStore()
87b62d
         throws Exception
87b62d
     {
87b62d
-        String sep = File.separator;
87b62d
-        File file = new File(System.getProperty("java.home") + sep
87b62d
-                             + "lib" + sep + "security" + sep
87b62d
-                             + "cacerts");
87b62d
-        if (!file.exists()) {
87b62d
-            return null;
87b62d
-        }
87b62d
         KeyStore caks = null;
87b62d
+        File file = getCacertsKeyStoreFile();
87b62d
+        if (file == null) { return null; }
87b62d
         try (FileInputStream fis = new FileInputStream(file)) {
87b62d
             caks = KeyStore.getInstance(JKS);
87b62d
             caks.load(fis, null);
87b62d
diff --git a/jdk/src/share/lib/security/java.security-aix b/jdk/src/share/lib/security/java.security-aix
87b62d
index bfe0c593adb..093bc09bf95 100644
87b62d
--- a/jdk/src/share/lib/security/java.security-aix
87b62d
+++ b/jdk/src/share/lib/security/java.security-aix
87b62d
@@ -294,6 +294,13 @@ security.overridePropertiesFile=true
87b62d
 #
87b62d
 security.useSystemPropertiesFile=false
87b62d
 
87b62d
+#
87b62d
+# Specifies the system certificate store
87b62d
+# This property may be disabled using
87b62d
+# -Djava.security.disableSystemCACerts=true
87b62d
+#
87b62d
+security.systemCACerts=${java.home}/lib/security/cacerts
87b62d
+
87b62d
 #
87b62d
 # Determines the default key and trust manager factory algorithms for
87b62d
 # the javax.net.ssl package.
87b62d
diff --git a/jdk/src/share/lib/security/java.security-linux b/jdk/src/share/lib/security/java.security-linux
87b62d
index 9d1c8fe8a8e..16c9281cc1f 100644
87b62d
--- a/jdk/src/share/lib/security/java.security-linux
87b62d
+++ b/jdk/src/share/lib/security/java.security-linux
87b62d
@@ -307,6 +307,13 @@ security.overridePropertiesFile=true
87b62d
 #
87b62d
 security.useSystemPropertiesFile=false
87b62d
 
87b62d
+#
87b62d
+# Specifies the system certificate store
87b62d
+# This property may be disabled using
87b62d
+# -Djava.security.disableSystemCACerts=true
87b62d
+#
87b62d
+security.systemCACerts=${java.home}/lib/security/cacerts
87b62d
+
87b62d
 #
87b62d
 # Determines the default key and trust manager factory algorithms for
87b62d
 # the javax.net.ssl package.
87b62d
diff --git a/jdk/src/share/lib/security/java.security-macosx b/jdk/src/share/lib/security/java.security-macosx
87b62d
index 19047c61097..43e034cdeaf 100644
87b62d
--- a/jdk/src/share/lib/security/java.security-macosx
87b62d
+++ b/jdk/src/share/lib/security/java.security-macosx
87b62d
@@ -297,6 +297,13 @@ security.overridePropertiesFile=true
87b62d
 #
87b62d
 security.useSystemPropertiesFile=false
87b62d
 
87b62d
+#
87b62d
+# Specifies the system certificate store
87b62d
+# This property may be disabled using
87b62d
+# -Djava.security.disableSystemCACerts=true
87b62d
+#
87b62d
+security.systemCACerts=${java.home}/lib/security/cacerts
87b62d
+
87b62d
 #
87b62d
 # Determines the default key and trust manager factory algorithms for
87b62d
 # the javax.net.ssl package.
87b62d
diff --git a/jdk/src/share/lib/security/java.security-solaris b/jdk/src/share/lib/security/java.security-solaris
87b62d
index 7eda556ae13..325937e97fb 100644
87b62d
--- a/jdk/src/share/lib/security/java.security-solaris
87b62d
+++ b/jdk/src/share/lib/security/java.security-solaris
87b62d
@@ -295,6 +295,13 @@ security.overridePropertiesFile=true
87b62d
 #
87b62d
 security.useSystemPropertiesFile=false
87b62d
 
87b62d
+#
87b62d
+# Specifies the system certificate store
87b62d
+# This property may be disabled using
87b62d
+# -Djava.security.disableSystemCACerts=true
87b62d
+#
87b62d
+security.systemCACerts=${java.home}/lib/security/cacerts
87b62d
+
87b62d
 #
87b62d
 # Determines the default key and trust manager factory algorithms for
87b62d
 # the javax.net.ssl package.
87b62d
diff --git a/jdk/src/share/lib/security/java.security-windows b/jdk/src/share/lib/security/java.security-windows
87b62d
index dfa1a669aa9..92ef777e065 100644
87b62d
--- a/jdk/src/share/lib/security/java.security-windows
87b62d
+++ b/jdk/src/share/lib/security/java.security-windows
87b62d
@@ -297,6 +297,13 @@ security.overridePropertiesFile=true
87b62d
 #
87b62d
 security.useSystemPropertiesFile=false
87b62d
 
87b62d
+#
87b62d
+# Specifies the system certificate store
87b62d
+# This property may be disabled using
87b62d
+# -Djava.security.disableSystemCACerts=true
87b62d
+#
87b62d
+security.systemCACerts=${java.home}/lib/security/cacerts
87b62d
+
87b62d
 #
87b62d
 # Determines the default key and trust manager factory algorithms for
87b62d
 # the javax.net.ssl package.