Blame SOURCES/pr2888-rh2055274-support_system_cacerts.patch

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