Skip to content

Commit 0395df6

Browse files
committed
OPENJDK-2108: Internal __redhat_fips__ property
Introduce an 'include'-directives-only __redhat_fips__ magic property that expands as either true or false depending on the System FIPS status, reported by the /proc/sys/crypto/fips_enabled kernel file.
1 parent 78770bf commit 0395df6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/java.base/share/classes/sun/security/util/PropertyExpander.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,35 @@ public static String expand(String value, boolean encodeURL)
6161
return expand(value, encodeURL, System::getProperty);
6262
}
6363

64+
/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvv FIPS PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
65+
private static final class RedHatFIPS {
66+
// This 'include'-directives-only magic property is an internal
67+
// implementation detail that could (and probably will!) change.
68+
// Red Hat customers should NOT rely on this for their own use.
69+
private static final String MAGIC_PROP = "__redhat_fips__";
70+
private static final String IS_ON = "" + isOn();
71+
72+
private static boolean isOn() {
73+
String path = "/proc/sys/crypto/fips_enabled";
74+
try (java.io.InputStream is = new java.io.FileInputStream(path)) {
75+
return is.read() == '1';
76+
} catch (java.io.IOException ignore) {
77+
return false;
78+
}
79+
}
80+
81+
static String getProperty(String key) {
82+
return MAGIC_PROP.equals(key) ? IS_ON : System.getProperty(key, "");
83+
}
84+
}
85+
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIPS PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
86+
6487
/*
6588
* In non-strict mode an undefined property is replaced by an empty string.
6689
*/
6790
public static String expandNonStrict(String value) {
6891
try {
69-
return expand(value, false, key -> System.getProperty(key, ""));
92+
return expand(value, false, RedHatFIPS::getProperty); //< FIPS PATCH
7093
} catch (ExpandException e) {
7194
// should not happen
7295
throw new AssertionError("unexpected expansion error: when " +

0 commit comments

Comments
 (0)