Skip to content

Commit f8142a2

Browse files
authored
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 e9772be commit f8142a2

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 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"
@@ -1667,6 +1828,7 @@ jobs:
16671828
- linux_additional_build
16681829
- windows_aarch64_build
16691830
- linux_x64_test
1831+
- linux_x64_test_fips
16701832
- linux_x86_test
16711833
- windows_x64_test
16721834
- 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)