Skip to content

Commit dd544f8

Browse files
committed
RH2090378: Revert to disabling system security properties and FIPS mode support together (openjdk#4)
- Improve debug output of all properties for FIPS mode and system security property support. - Run JDK tests in GHA with system security properties both disabled and enabled in java.security - General code cleanup Reviewed-by: @martinuy Reviewed-by: @franferrax
1 parent 1e55dec commit dd544f8

File tree

4 files changed

+243
-38
lines changed

4 files changed

+243
-38
lines changed

.github/workflows/submit.yml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,167 @@ jobs:
402402
path: ~/linux-x64${{ matrix.artifact }}_testsupport_${{ env.logsuffix }}.zip
403403
continue-on-error: true
404404

405+
linux_x64_test_fips:
406+
name: Linux x64 + FIPS
407+
runs-on: "ubuntu-20.04"
408+
needs:
409+
- prerequisites
410+
- linux_x64_build
411+
412+
strategy:
413+
fail-fast: false
414+
matrix:
415+
test:
416+
- jdk/tier1 part 1
417+
- jdk/tier1 part 2
418+
- jdk/tier1 part 3
419+
include:
420+
- test: jdk/tier1 part 1
421+
suites: test/jdk/:tier1_part1
422+
- test: jdk/tier1 part 2
423+
suites: test/jdk/:tier1_part2
424+
- test: jdk/tier1 part 3
425+
suites: test/jdk/:tier1_part3
426+
427+
env:
428+
JDK_VERSION: "${{ needs.prerequisites.outputs.jdk_version }}"
429+
BOOT_JDK_VERSION: "${{ fromJson(needs.prerequisites.outputs.dependencies).BOOT_JDK_VERSION }}"
430+
BOOT_JDK_FILENAME: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_FILENAME }}"
431+
BOOT_JDK_URL: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_URL }}"
432+
BOOT_JDK_SHA256: "${{ fromJson(needs.prerequisites.outputs.dependencies).LINUX_X64_BOOT_JDK_SHA256 }}"
433+
434+
steps:
435+
- name: Checkout the source
436+
uses: actions/checkout@v2
437+
438+
- name: Restore boot JDK from cache
439+
id: bootjdk
440+
uses: actions/cache@v2
441+
with:
442+
path: ~/bootjdk/${{ env.BOOT_JDK_VERSION }}
443+
key: bootjdk-${{ runner.os }}-${{ env.BOOT_JDK_VERSION }}-${{ env.BOOT_JDK_SHA256 }}-v1
444+
445+
- name: Download boot JDK
446+
run: |
447+
mkdir -p "${HOME}/bootjdk/${BOOT_JDK_VERSION}"
448+
wget -O "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" "${BOOT_JDK_URL}"
449+
echo "${BOOT_JDK_SHA256} ${HOME}/bootjdk/${BOOT_JDK_FILENAME}" | sha256sum -c >/dev/null -
450+
tar -xf "${HOME}/bootjdk/${BOOT_JDK_FILENAME}" -C "${HOME}/bootjdk/${BOOT_JDK_VERSION}"
451+
mv "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"*/* "${HOME}/bootjdk/${BOOT_JDK_VERSION}/"
452+
if: steps.bootjdk.outputs.cache-hit != 'true'
453+
454+
- name: Restore jtreg artifact
455+
id: jtreg_restore
456+
uses: actions/download-artifact@v2
457+
with:
458+
name: transient_jtreg_${{ needs.prerequisites.outputs.bundle_id }}
459+
path: ~/jtreg/
460+
continue-on-error: true
461+
462+
- name: Restore jtreg artifact (retry)
463+
uses: actions/download-artifact@v2
464+
with:
465+
name: transient_jtreg_${{ needs.prerequisites.outputs.bundle_id }}
466+
path: ~/jtreg/
467+
if: steps.jtreg_restore.outcome == 'failure'
468+
469+
- name: Restore build artifacts
470+
id: build_restore
471+
uses: actions/download-artifact@v2
472+
with:
473+
name: transient_jdk-linux-x64${{ matrix.artifact }}_${{ needs.prerequisites.outputs.bundle_id }}
474+
path: ~/jdk-linux-x64${{ matrix.artifact }}
475+
continue-on-error: true
476+
477+
- name: Restore build artifacts (retry)
478+
uses: actions/download-artifact@v2
479+
with:
480+
name: transient_jdk-linux-x64${{ matrix.artifact }}_${{ needs.prerequisites.outputs.bundle_id }}
481+
path: ~/jdk-linux-x64${{ matrix.artifact }}
482+
if: steps.build_restore.outcome == 'failure'
483+
484+
- name: Unpack jdk
485+
run: |
486+
mkdir -p "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}"
487+
tar -xf "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }}"
488+
489+
- name: Unpack tests
490+
run: |
491+
mkdir -p "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}"
492+
tar -xf "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}.tar.gz" -C "${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}"
493+
494+
- name: Find root of jdk image dir
495+
run: |
496+
imageroot=`find ${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin${{ matrix.artifact }} -name release -type f`
497+
echo "imageroot=`dirname ${imageroot}`" >> $GITHUB_ENV
498+
499+
- name: Turn on system security properties and FIPS mode support
500+
run: |
501+
sed -i -e "s:^security.useSystemPropertiesFile=.*:security.useSystemPropertiesFile=true:" ${{ env.imageroot }}/conf/security/java.security
502+
503+
- name: Run tests
504+
run: >
505+
JDK_IMAGE_DIR=${{ env.imageroot }}
506+
TEST_IMAGE_DIR=${HOME}/jdk-linux-x64${{ matrix.artifact }}/jdk-${{ env.JDK_VERSION }}-internal+0_linux-x64_bin-tests${{ matrix.artifact }}
507+
BOOT_JDK=${HOME}/bootjdk/${BOOT_JDK_VERSION}
508+
JT_HOME=${HOME}/jtreg
509+
make test-prebuilt
510+
CONF_NAME=run-test-prebuilt
511+
LOG_CMDLINES=true
512+
JTREG_VERBOSE=fail,error,time
513+
TEST="${{ matrix.suites }}"
514+
TEST_OPTS_JAVA_OPTIONS=
515+
JTREG_KEYWORDS="!headful"
516+
JTREG="JAVA_OPTIONS='-Djava.security.debug=properties -XX:-CreateCoredumpOnCrash'"
517+
518+
- name: Check that all tests executed successfully
519+
if: always()
520+
run: >
521+
if ! grep --include=test-summary.txt -lqr build/*/test-results -e "TEST SUCCESS" ; then
522+
cat build/*/test-results/*/text/newfailures.txt ;
523+
cat build/*/test-results/*/text/other_errors.txt ;
524+
exit 1 ;
525+
fi
526+
527+
- name: Create suitable test log artifact name
528+
if: always()
529+
run: echo "logsuffix=`echo ${{ matrix.test }} | sed -e 's!/!_!'g -e 's! !_!'g`" >> $GITHUB_ENV
530+
531+
- name: Package test results
532+
if: always()
533+
working-directory: build/run-test-prebuilt/test-results/
534+
run: >
535+
zip -r9
536+
"$HOME/linux-x64${{ matrix.artifact }}-fips_testresults_${{ env.logsuffix }}.zip"
537+
.
538+
continue-on-error: true
539+
540+
- name: Package test support
541+
if: always()
542+
working-directory: build/run-test-prebuilt/test-support/
543+
run: >
544+
zip -r9
545+
"$HOME/linux-x64${{ matrix.artifact }}-fips_testsupport_${{ env.logsuffix }}.zip"
546+
.
547+
-i *.jtr
548+
-i */hs_err*.log
549+
-i */replay*.log
550+
continue-on-error: true
551+
552+
- name: Persist test results
553+
if: always()
554+
uses: actions/upload-artifact@v2
555+
with:
556+
path: ~/linux-x64${{ matrix.artifact }}-fips_testresults_${{ env.logsuffix }}.zip
557+
continue-on-error: true
558+
559+
- name: Persist test outputs
560+
if: always()
561+
uses: actions/upload-artifact@v2
562+
with:
563+
path: ~/linux-x64${{ matrix.artifact }}-fips_testsupport_${{ env.logsuffix }}.zip
564+
continue-on-error: true
565+
405566
linux_additional_build:
406567
name: Linux additional
407568
runs-on: "ubuntu-20.04"
@@ -1685,6 +1846,7 @@ jobs:
16851846
- linux_additional_build
16861847
- windows_aarch64_build
16871848
- linux_x64_test
1849+
- linux_x64_test_fips
16881850
- linux_x86_test
16891851
- windows_x64_test
16901852
- macos_x64_test

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

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757

5858
public final class Security {
5959

60+
private static final String SYS_PROP_SWITCH =
61+
"java.security.disableSystemPropertiesFile";
62+
private static final String SEC_PROP_SWITCH =
63+
"security.useSystemPropertiesFile";
64+
6065
/* Are we debugging? -- for developers */
6166
private static final Debug sdebug =
6267
Debug.getInstance("properties");
@@ -101,6 +106,7 @@ private static void initialize() {
101106
props = new Properties();
102107
boolean loadedProps = false;
103108
boolean overrideAll = false;
109+
boolean systemSecPropsEnabled = false;
104110

105111
// first load the system properties file
106112
// to determine the value of security.overridePropertiesFile
@@ -211,26 +217,59 @@ private static void initialize() {
211217
}
212218
}
213219

214-
String disableSystemProps = System.getProperty("java.security.disableSystemPropertiesFile");
215-
if ((disableSystemProps == null || "false".equalsIgnoreCase(disableSystemProps)) &&
216-
"true".equalsIgnoreCase(props.getProperty("security.useSystemPropertiesFile"))) {
217-
if (!SystemConfigurator.configureSysProps(props)) {
220+
boolean sysUseProps = Boolean.valueOf(System.getProperty(SYS_PROP_SWITCH, "false"));
221+
boolean secUseProps = Boolean.valueOf(props.getProperty(SEC_PROP_SWITCH));
222+
if (sdebug != null) {
223+
sdebug.println(SYS_PROP_SWITCH + "=" + sysUseProps);
224+
sdebug.println(SEC_PROP_SWITCH + "=" + secUseProps);
225+
}
226+
if (!sysUseProps && secUseProps) {
227+
systemSecPropsEnabled = SystemConfigurator.configureSysProps(props);
228+
if (!systemSecPropsEnabled) {
218229
if (sdebug != null) {
219-
sdebug.println("WARNING: System properties could not be loaded.");
230+
sdebug.println("WARNING: System security properties could not be loaded.");
220231
}
221232
}
233+
} else {
234+
if (sdebug != null) {
235+
sdebug.println("System security property support disabled by user.");
236+
}
222237
}
223238

224239
// FIPS support depends on the contents of java.security so
225240
// ensure it has loaded first
226-
if (loadedProps) {
227-
boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
228-
if (sdebug != null) {
229-
if (fipsEnabled) {
230-
sdebug.println("FIPS support enabled.");
231-
} else {
232-
sdebug.println("FIPS support disabled.");
241+
if (loadedProps && systemSecPropsEnabled) {
242+
boolean shouldEnable;
243+
String sysProp = System.getProperty("com.redhat.fips");
244+
if (sysProp == null) {
245+
shouldEnable = true;
246+
if (sdebug != null) {
247+
sdebug.println("com.redhat.fips unset, using default value of true");
233248
}
249+
} else {
250+
shouldEnable = Boolean.valueOf(sysProp);
251+
if (sdebug != null) {
252+
sdebug.println("com.redhat.fips set, using its value " + shouldEnable);
253+
}
254+
}
255+
if (shouldEnable) {
256+
boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
257+
if (sdebug != null) {
258+
if (fipsEnabled) {
259+
sdebug.println("FIPS mode support configured and enabled.");
260+
} else {
261+
sdebug.println("FIPS mode support disabled.");
262+
}
263+
}
264+
} else {
265+
if (sdebug != null ) {
266+
sdebug.println("FIPS mode support disabled by user.");
267+
}
268+
}
269+
} else {
270+
if (sdebug != null) {
271+
sdebug.println("WARNING: FIPS mode support can not be enabled without " +
272+
"system security properties being enabled.");
234273
}
235274
}
236275
}

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public Void run() {
7878
* security.useSystemPropertiesFile is true.
7979
*/
8080
static boolean configureSysProps(Properties props) {
81-
boolean loadedProps = false;
81+
boolean systemSecPropsLoaded = false;
8282

8383
try (BufferedInputStream bis =
8484
new BufferedInputStream(
8585
new FileInputStream(CRYPTO_POLICIES_JAVA_CONFIG))) {
8686
props.load(bis);
87-
loadedProps = true;
87+
systemSecPropsLoaded = true;
8888
if (sdebug != null) {
8989
sdebug.println("reading system security properties file " +
9090
CRYPTO_POLICIES_JAVA_CONFIG);
@@ -97,7 +97,7 @@ static boolean configureSysProps(Properties props) {
9797
e.printStackTrace();
9898
}
9999
}
100-
return loadedProps;
100+
return systemSecPropsLoaded;
101101
}
102102

103103
/*
@@ -169,6 +169,8 @@ static boolean configureFIPS(Properties props) {
169169
sdebug.println("FIPS support enabled without plain key support");
170170
}
171171
}
172+
} else {
173+
if (sdebug != null) { sdebug.println("FIPS mode not detected"); }
172174
}
173175
} catch (Exception e) {
174176
if (sdebug != null) {
@@ -209,37 +211,39 @@ static boolean isPlainKeySupportEnabled() {
209211
return plainKeySupportEnabled;
210212
}
211213

212-
/*
213-
* OpenJDK FIPS mode will be enabled only if the com.redhat.fips
214-
* system property is true (default) and the system is in FIPS mode.
214+
/**
215+
* Determines whether FIPS mode should be enabled.
216+
*
217+
* OpenJDK FIPS mode will be enabled only if the system is in
218+
* FIPS mode.
219+
*
220+
* Calls to this method only occur if the system property
221+
* com.redhat.fips is not set to false.
215222
*
216223
* There are 2 possible ways in which OpenJDK detects that the system
217224
* is in FIPS mode: 1) if the NSS SECMOD_GetSystemFIPSEnabled API is
218225
* available at OpenJDK's built-time, it is called; 2) otherwise, the
219226
* /proc/sys/crypto/fips_enabled file is read.
227+
*
228+
* @return true if the system is in FIPS mode
220229
*/
221230
private static boolean enableFips() throws Exception {
222-
boolean shouldEnable = Boolean.valueOf(System.getProperty("com.redhat.fips", "true"));
223-
if (shouldEnable) {
231+
if (sdebug != null) {
232+
sdebug.println("Calling getSystemFIPSEnabled (libsystemconf)...");
233+
}
234+
try {
235+
boolean fipsEnabled = getSystemFIPSEnabled();
224236
if (sdebug != null) {
225-
sdebug.println("Calling getSystemFIPSEnabled (libsystemconf)...");
237+
sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) returned: "
238+
+ fipsEnabled);
226239
}
227-
try {
228-
shouldEnable = getSystemFIPSEnabled();
229-
if (sdebug != null) {
230-
sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) returned: "
231-
+ shouldEnable);
232-
}
233-
return shouldEnable;
234-
} catch (IOException e) {
235-
if (sdebug != null) {
236-
sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) failed:");
237-
sdebug.println(e.getMessage());
238-
}
239-
throw e;
240+
return fipsEnabled;
241+
} catch (IOException e) {
242+
if (sdebug != null) {
243+
sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) failed:");
244+
sdebug.println(e.getMessage());
240245
}
241-
} else {
242-
return false;
246+
throw e;
243247
}
244248
}
245249
}

src/java.base/share/conf/security/java.security

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ security.provider.tbd=Apple
8080
security.provider.tbd=SunPKCS11
8181

8282
#
83-
# Security providers used when global crypto-policies are set to FIPS.
83+
# Security providers used when FIPS mode support is active
8484
#
8585
fips.provider.1=SunPKCS11 ${java.home}/conf/security/nss.fips.cfg
8686
fips.provider.2=SUN
@@ -346,7 +346,7 @@ security.overridePropertiesFile=true
346346
# using the system properties file stored at
347347
# /etc/crypto-policies/back-ends/java.config
348348
#
349-
security.useSystemPropertiesFile=true
349+
security.useSystemPropertiesFile=false
350350

351351
#
352352
# Determines the default key and trust manager factory algorithms for

0 commit comments

Comments
 (0)