Skip to content

Commit ae176fa

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 ae176fa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/java.base/share/classes/java/security/Security.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,27 @@ public Properties getInitialProperties() {
323323
}
324324

325325
private static void initialize() {
326+
/* vvvvvvvvvvvvvvvvvvvvvvvvvvv FIPS PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvv */
327+
/* This 'include'-directives-only magic property is an internal */
328+
/* implementation detail that could (and probably will!) change. */
329+
/* Red Hat customers should NOT rely on this for their own use. */
330+
String fipsKernelFlag = "/proc/sys/crypto/fips_enabled";
331+
boolean fipsModeOn;
332+
try (InputStream is = new java.io.FileInputStream(fipsKernelFlag)) {
333+
fipsModeOn = is.read() == '1';
334+
} catch (IOException ioe) {
335+
fipsModeOn = false;
336+
if (sdebug != null) {
337+
sdebug.println("Failed to read FIPS kernel file: " + ioe);
338+
}
339+
}
340+
String fipsMagicPropName = "__redhat_fips__";
341+
System.setProperty(fipsMagicPropName, "" + fipsModeOn);
342+
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIPS PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
326343
SecPropLoader.loadAll();
344+
/* vvvvvvvvvvvvvvvvvvvvvvvvvvv FIPS PATCH vvvvvvvvvvvvvvvvvvvvvvvvvvv */
345+
System.clearProperty(fipsMagicPropName);
346+
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIPS PATCH ^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
327347
initialSecurityProperties = (Properties) props.clone();
328348
if (sdebug != null) {
329349
for (String key : props.stringPropertyNames()) {

0 commit comments

Comments
 (0)