Skip to content

Commit fe8490c

Browse files
committed
RH2090378: Revert to disabling system security properties and FIPS mode support together (#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 5c8832f commit fe8490c

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
@@ -384,6 +384,167 @@ jobs:
384384
path: ~/linux-x64${{ matrix.artifact }}_testsupport_${{ env.logsuffix }}.zip
385385
continue-on-error: true
386386

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

104110
// first load the system properties file
105111
// to determine the value of security.overridePropertiesFile
@@ -210,27 +216,60 @@ private static void initialize() {
210216
}
211217
}
212218

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

223238
// FIPS support depends on the contents of java.security so
224239
// ensure it has loaded first
225-
if (loadedProps) {
226-
boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
227-
if (sdebug != null) {
228-
if (fipsEnabled) {
229-
sdebug.println("FIPS support enabled.");
230-
} else {
231-
sdebug.println("FIPS support disabled.");
240+
if (loadedProps && systemSecPropsEnabled) {
241+
boolean shouldEnable;
242+
String sysProp = System.getProperty("com.redhat.fips");
243+
if (sysProp == null) {
244+
shouldEnable = true;
245+
if (sdebug != null) {
246+
sdebug.println("com.redhat.fips unset, using default value of true");
247+
}
248+
} else {
249+
shouldEnable = Boolean.valueOf(sysProp);
250+
if (sdebug != null) {
251+
sdebug.println("com.redhat.fips set, using its value " + shouldEnable);
232252
}
233253
}
254+
if (shouldEnable) {
255+
boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
256+
if (sdebug != null) {
257+
if (fipsEnabled) {
258+
sdebug.println("FIPS mode support configured and enabled.");
259+
} else {
260+
sdebug.println("FIPS mode support disabled.");
261+
}
262+
}
263+
} else {
264+
if (sdebug != null ) {
265+
sdebug.println("FIPS mode support disabled by user.");
266+
}
267+
}
268+
} else {
269+
if (sdebug != null) {
270+
sdebug.println("WARNING: FIPS mode support can not be enabled without " +
271+
"system security properties being enabled.");
272+
}
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
@@ -77,13 +77,13 @@ public Void run() {
7777
* security.useSystemPropertiesFile is true.
7878
*/
7979
static boolean configureSysProps(Properties props) {
80-
boolean loadedProps = false;
80+
boolean systemSecPropsLoaded = false;
8181

8282
try (BufferedInputStream bis =
8383
new BufferedInputStream(
8484
new FileInputStream(CRYPTO_POLICIES_JAVA_CONFIG))) {
8585
props.load(bis);
86-
loadedProps = true;
86+
systemSecPropsLoaded = true;
8787
if (sdebug != null) {
8888
sdebug.println("reading system security properties file " +
8989
CRYPTO_POLICIES_JAVA_CONFIG);
@@ -96,7 +96,7 @@ static boolean configureSysProps(Properties props) {
9696
e.printStackTrace();
9797
}
9898
}
99-
return loadedProps;
99+
return systemSecPropsLoaded;
100100
}
101101

102102
/*
@@ -168,6 +168,8 @@ static boolean configureFIPS(Properties props) {
168168
sdebug.println("FIPS support enabled without plain key support");
169169
}
170170
}
171+
} else {
172+
if (sdebug != null) { sdebug.println("FIPS mode not detected"); }
171173
}
172174
} catch (Exception e) {
173175
if (sdebug != null) {
@@ -208,37 +210,39 @@ static boolean isPlainKeySupportEnabled() {
208210
return plainKeySupportEnabled;
209211
}
210212

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ security.provider.tbd=SunPKCS11
8686
#endif
8787

8888
#
89-
# Security providers used when global crypto-policies are set to FIPS.
89+
# Security providers used when FIPS mode support is active
9090
#
9191
fips.provider.1=SunPKCS11 ${java.home}/conf/security/nss.fips.cfg
9292
fips.provider.2=SUN
@@ -353,7 +353,7 @@ security.overridePropertiesFile=true
353353
# using the system properties file stored at
354354
# /etc/crypto-policies/back-ends/java.config
355355
#
356-
security.useSystemPropertiesFile=true
356+
security.useSystemPropertiesFile=false
357357

358358
#
359359
# Determines the default key and trust manager factory algorithms for

0 commit comments

Comments
 (0)