|
|
9d60fa |
diff --git a/src/java.base/share/classes/javopenjdk.orig///security/Security.java openjdk///src/java.base/share/classes/java/security/Security.java
|
|
|
0f3be5 |
--- openjdk.orig/src/java.base/share/classes/java/security/Security.java
|
|
|
0f3be5 |
+++ openjdk/src/java.base/share/classes/java/security/Security.java
|
|
|
9d60fa |
@@ -196,26 +196,8 @@
|
|
|
9d60fa |
if (disableSystemProps == null &&
|
|
|
9d60fa |
"true".equalsIgnoreCase(props.getProperty
|
|
|
9d60fa |
("security.useSystemPropertiesFile"))) {
|
|
|
9d60fa |
-
|
|
|
9d60fa |
- // now load the system file, if it exists, so its values
|
|
|
9d60fa |
- // will win if they conflict with the earlier values
|
|
|
9d60fa |
- try (BufferedInputStream bis =
|
|
|
9d60fa |
- new BufferedInputStream(new FileInputStream(SYSTEM_PROPERTIES))) {
|
|
|
9d60fa |
- props.load(bis);
|
|
|
9d60fa |
+ if (SystemConfigurator.configure(props)) {
|
|
|
9d60fa |
loadedProps = true;
|
|
|
9d60fa |
-
|
|
|
9d60fa |
- if (sdebug != null) {
|
|
|
9d60fa |
- sdebug.println("reading system security properties file " +
|
|
|
9d60fa |
- SYSTEM_PROPERTIES);
|
|
|
9d60fa |
- sdebug.println(props.toString());
|
|
|
9d60fa |
- }
|
|
|
9d60fa |
- } catch (IOException e) {
|
|
|
9d60fa |
- if (sdebug != null) {
|
|
|
9d60fa |
- sdebug.println
|
|
|
9d60fa |
- ("unable to load security properties from " +
|
|
|
9d60fa |
- SYSTEM_PROPERTIES);
|
|
|
9d60fa |
- e.printStackTrace();
|
|
|
9d60fa |
- }
|
|
|
9d60fa |
}
|
|
|
9d60fa |
}
|
|
|
9d60fa |
|
|
|
9d60fa |
diff --git a/src/java.base/share/classes/javopenjdk.orig///security/SystemConfigurator.java openjdk///src/java.base/share/classes/java/security/SystemConfigurator.java
|
|
|
9d60fa |
new file mode 100644
|
|
|
9d60fa |
--- /dev/null
|
|
|
0f3be5 |
+++ openjdk/src/java.base/share/classes/java/security/SystemConfigurator.java
|
|
|
9d60fa |
@@ -0,0 +1,151 @@
|
|
|
9d60fa |
+/*
|
|
|
9d60fa |
+ * Copyright (c) 2019, Red Hat, Inc.
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ * This code is free software; you can redistribute it and/or modify it
|
|
|
9d60fa |
+ * under the terms of the GNU General Public License version 2 only, as
|
|
|
9d60fa |
+ * published by the Free Software Foundation.
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
9d60fa |
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
9d60fa |
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
9d60fa |
+ * version 2 for more details (a copy is included in the LICENSE file that
|
|
|
9d60fa |
+ * accompanied this code).
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ * You should have received a copy of the GNU General Public License version
|
|
|
9d60fa |
+ * 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
9d60fa |
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
9d60fa |
+ * or visit www.oracle.com if you need additional information or have any
|
|
|
9d60fa |
+ * questions.
|
|
|
9d60fa |
+ */
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+package java.security;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+import java.io.BufferedInputStream;
|
|
|
9d60fa |
+import java.io.FileInputStream;
|
|
|
9d60fa |
+import java.io.IOException;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+import java.nio.file.Files;
|
|
|
9d60fa |
+import java.nio.file.Path;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+import java.util.Iterator;
|
|
|
9d60fa |
+import java.util.Map.Entry;
|
|
|
9d60fa |
+import java.util.Properties;
|
|
|
9d60fa |
+import java.util.function.Consumer;
|
|
|
9d60fa |
+import java.util.regex.Matcher;
|
|
|
9d60fa |
+import java.util.regex.Pattern;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+import sun.security.util.Debug;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+/**
|
|
|
9d60fa |
+ * Internal class to align OpenJDK with global crypto-policies.
|
|
|
9d60fa |
+ * Called from java.security.Security class initialization,
|
|
|
9d60fa |
+ * during startup.
|
|
|
9d60fa |
+ *
|
|
|
9d60fa |
+ */
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+class SystemConfigurator {
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ private static final Debug sdebug =
|
|
|
9d60fa |
+ Debug.getInstance("properties");
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ private static final String CRYPTO_POLICIES_BASE_DIR =
|
|
|
9d60fa |
+ "/etc/crypto-policies";
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ private static final String CRYPTO_POLICIES_JAVA_CONFIG =
|
|
|
9d60fa |
+ CRYPTO_POLICIES_BASE_DIR + "/back-ends/java.config";
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ private static final String CRYPTO_POLICIES_CONFIG =
|
|
|
9d60fa |
+ CRYPTO_POLICIES_BASE_DIR + "/config";
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ private static final class SecurityProviderInfo {
|
|
|
9d60fa |
+ int number;
|
|
|
9d60fa |
+ String key;
|
|
|
9d60fa |
+ String value;
|
|
|
9d60fa |
+ SecurityProviderInfo(int number, String key, String value) {
|
|
|
9d60fa |
+ this.number = number;
|
|
|
9d60fa |
+ this.key = key;
|
|
|
9d60fa |
+ this.value = value;
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ /*
|
|
|
9d60fa |
+ * Invoked when java.security.Security class is initialized, if
|
|
|
9d60fa |
+ * java.security.disableSystemPropertiesFile property is not set and
|
|
|
9d60fa |
+ * security.useSystemPropertiesFile is true.
|
|
|
9d60fa |
+ */
|
|
|
9d60fa |
+ static boolean configure(Properties props) {
|
|
|
9d60fa |
+ boolean loadedProps = false;
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ try (BufferedInputStream bis =
|
|
|
9d60fa |
+ new BufferedInputStream(
|
|
|
9d60fa |
+ new FileInputStream(CRYPTO_POLICIES_JAVA_CONFIG))) {
|
|
|
9d60fa |
+ props.load(bis);
|
|
|
9d60fa |
+ loadedProps = true;
|
|
|
9d60fa |
+ if (sdebug != null) {
|
|
|
9d60fa |
+ sdebug.println("reading system security properties file " +
|
|
|
9d60fa |
+ CRYPTO_POLICIES_JAVA_CONFIG);
|
|
|
9d60fa |
+ sdebug.println(props.toString());
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ } catch (IOException e) {
|
|
|
9d60fa |
+ if (sdebug != null) {
|
|
|
9d60fa |
+ sdebug.println("unable to load security properties from " +
|
|
|
9d60fa |
+ CRYPTO_POLICIES_JAVA_CONFIG);
|
|
|
9d60fa |
+ e.printStackTrace();
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ try {
|
|
|
9d60fa |
+ if (enableFips()) {
|
|
|
9d60fa |
+ if (sdebug != null) { sdebug.println("FIPS mode detected"); }
|
|
|
9d60fa |
+ loadedProps = false;
|
|
|
9d60fa |
+ // Remove all security providers
|
|
|
9d60fa |
+ Iterator<Entry<Object, Object>> i = props.entrySet().iterator();
|
|
|
9d60fa |
+ while (i.hasNext()) {
|
|
|
9d60fa |
+ Entry<Object, Object> e = i.next();
|
|
|
9d60fa |
+ if (((String) e.getKey()).startsWith("security.provider")) {
|
|
|
9d60fa |
+ if (sdebug != null) { sdebug.println("Removing provider: " + e); }
|
|
|
9d60fa |
+ i.remove();
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ // Add FIPS security providers
|
|
|
9d60fa |
+ String fipsProviderValue = null;
|
|
|
9d60fa |
+ for (int n = 1;
|
|
|
9d60fa |
+ (fipsProviderValue = (String) props.get("fips.provider." + n)) != null; n++) {
|
|
|
9d60fa |
+ String fipsProviderKey = "security.provider." + n;
|
|
|
9d60fa |
+ if (sdebug != null) {
|
|
|
9d60fa |
+ sdebug.println("Adding provider " + n + ": " +
|
|
|
9d60fa |
+ fipsProviderKey + "=" + fipsProviderValue);
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ props.put(fipsProviderKey, fipsProviderValue);
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ loadedProps = true;
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ } catch (Exception e) {
|
|
|
9d60fa |
+ if (sdebug != null) {
|
|
|
9d60fa |
+ sdebug.println("unable to load FIPS configuration");
|
|
|
9d60fa |
+ e.printStackTrace();
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ return loadedProps;
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+ /*
|
|
|
9d60fa |
+ * FIPS is enabled only if crypto-policies are set to "FIPS"
|
|
|
9d60fa |
+ * and the com.redhat.fips property is true.
|
|
|
9d60fa |
+ */
|
|
|
9d60fa |
+ private static boolean enableFips() throws Exception {
|
|
|
0f3be5 |
+ boolean fipsEnabled = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
|
|
|
9d60fa |
+ if (fipsEnabled) {
|
|
|
9d60fa |
+ String cryptoPoliciesConfig = new String(Files.readAllBytes(Path.of(CRYPTO_POLICIES_CONFIG)));
|
|
|
9d60fa |
+ if (sdebug != null) { sdebug.println("Crypto config:\n" + cryptoPoliciesConfig); }
|
|
|
9d60fa |
+ Pattern pattern = Pattern.compile("^FIPS$", Pattern.MULTILINE);
|
|
|
9d60fa |
+ return pattern.matcher(cryptoPoliciesConfig).find();
|
|
|
9d60fa |
+ } else {
|
|
|
9d60fa |
+ return false;
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+ }
|
|
|
9d60fa |
+}
|
|
|
9d60fa |
diff --git openjdk.orig///src/java.base/share/conf/security/java.security openjdk///src/java.base/share/conf/security/java.security
|
|
|
0f3be5 |
--- openjdk.orig/src/java.base/share/conf/security/java.security
|
|
|
0f3be5 |
+++ openjdk/src/java.base/share/conf/security/java.security
|
|
|
9d60fa |
@@ -87,6 +87,14 @@
|
|
|
9d60fa |
#security.provider.tbd=SunPKCS11 ${java.home}/lib/security/nss.cfg
|
|
|
9d60fa |
|
|
|
9d60fa |
#
|
|
|
9d60fa |
+# Security providers used when global crypto-policies are set to FIPS.
|
|
|
9d60fa |
+#
|
|
|
9d60fa |
+fips.provider.1=SunPKCS11 ${java.home}/conf/security/nss.fips.cfg
|
|
|
9d60fa |
+fips.provider.2=SUN
|
|
|
9d60fa |
+fips.provider.3=SunEC
|
|
|
9d60fa |
+fips.provider.4=com.sun.net.ssl.internal.ssl.Provider SunPKCS11-NSS-FIPS
|
|
|
9d60fa |
+
|
|
|
9d60fa |
+#
|
|
|
9d60fa |
# A list of preferred providers for specific algorithms. These providers will
|
|
|
9d60fa |
# be searched for matching algorithms before the list of registered providers.
|
|
|
9d60fa |
# Entries containing errors (parsing, etc) will be ignored. Use the
|