Skip to content

Commit 35907f9

Browse files
authored
Merge pull request #32537 from abutch3r/cli_fips_support
Add FIPS Env Var support for CLI commands
2 parents 27b66ff + f2abae3 commit 35907f9

File tree

9 files changed

+349
-77
lines changed

9 files changed

+349
-77
lines changed

dev/build.image/build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ task copyPropertiesToBuildImage (type:Copy) {
4848
tokens: [PRODUCT_VERSION: bnd.libertyRelease, PRODUCT_EDITION: bnd.productEdition, PRODUCT_LICENSE_TYPE: bnd.productLicenseType])
4949
}
5050

51+
task copyFips1403PropertiesToBuildImage( type: Copy) {
52+
dependsOn jar
53+
from project.file('publish/wlp/security')
54+
into project.file('wlp/lib/security/fips140_3')
55+
include 'FIPS140-3-Liberty.properties'
56+
}
57+
5158
task copyPublicKeyToBuildImage (type:Copy) {
5259
dependsOn jar
5360
from project.file('publish')
@@ -154,6 +161,7 @@ jar {
154161
assemble {
155162
dependsOn publishTemplates
156163
dependsOn copyPropertiesToBuildImage
164+
dependsOn copyFips1403PropertiesToBuildImage
157165
dependsOn addServiceFingerprint
158166
dependsOn copyReadmeToBuildImage
159167
dependsOn copyBetaLicenseToBuildImage
@@ -317,6 +325,12 @@ class PackageLibertyWithFeatures extends DefaultTask {
317325
into "$outputTo/wlp"
318326
}
319327

328+
project.copy {
329+
from project.file('wlp')
330+
include 'lib/security/fips140_3/FIPS140-3-Liberty.properties'
331+
into "$outputTo/wlp"
332+
}
333+
320334
if(isBeta) {
321335
//Now add the BETA_NOTICES file
322336
project.copy {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# org.objectweb.asm.commons.SerialVersionUIDAdder: Allow for SHA-1 to generate SerialVersionUID's to conform Java specification
2+
# org.eclipse.persistence.internal.libraries.asm.commons.SerialVersionUIDAdder: Allow for SHA-1 to generate SerialVersionUID's to conform Java specification
3+
# org.apache.yoko.rmi.impl.ValueDescriptor: Alloww for SHA-1 to generate the hash code for the RepositoryId
4+
# com.ibm.ws.wsoc.util.Utils: Allow SHA-1 for the generation of the Sec-WebSocket-Accept header
5+
# com.ibm.security.certclient.util.PkUtils: Allof for SHA-1 to generate of certificate Key Identifier(KID) value
6+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.desc.name = OpenJCEPlusFIPS Cryptographic Module FIPS 140-3 for Liberty
7+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.extends = RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced
8+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.1 = com.ibm.crypto.plus.provider.OpenJCEPlusFIPS [+ \
9+
{MessageDigest, SHA-1, *, FullClassName:org.objectweb.asm.commons.SerialVersionUIDAdder}, \
10+
{MessageDigest, SHA-1, *, FullClassName:org.eclipse.persistence.internal.libraries.asm.commons.SerialVersionUIDAdder}, \
11+
{MessageDigest, SHA-1, *, FullClassName:org.apache.yoko.rmi.impl.ValueDescriptor}, \
12+
{MessageDigest, SHA-1, *, FullClassName:com.ibm.ws.wsoc.util.Utils}, \
13+
{MessageDigest, SHA-1, *, FullClassName:com.ibm.security.certclient.util.PkUtils}]
14+
15+
# For Collectives
16+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.7 = com.ibm.ws.collective.security.internal.provider.CollectiveProvider
17+
18+
# For WebServices / SAML (uses JCE underneath)
19+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.8 = org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI
20+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.9 = org.apache.wss4j.dom.transform.STRTransformProvider
21+
# Reserved Providers in case new providers are required
22+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.10 = io.openliberty.PLACEHOLDER
23+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.11 = io.openliberty.PLACEHOLDER
24+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.12 = io.openliberty.PLACEHOLDER
25+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.13 = io.openliberty.PLACEHOLDER
26+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.14 = io.openliberty.PLACEHOLDER
27+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Liberty.jce.provider.15 = io.openliberty.PLACEHOLDER
28+

dev/build.sharedResources/usrShared/resources/security/semeruFips140_3CustomProfile.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Custom.jce.provider.4 = com.sun.cry
2020
{SecretKeyFactory, PBEWithMD5AndDES, *, ModuleAndFullClassName:java.base/sun.security.pkcs12.PKCS12KeyStore}, \
2121
{Cipher, PBEWithHmacSHA256AndAES_256, *, ModuleAndFullClassName:java.base/sun.security.pkcs12.PKCS12KeyStore}, \
2222
{Mac, HmacPBESHA256, *, ModuleAndFullClassName:java.base/sun.security.pkcs12.PKCS12KeyStore}]
23+
RestrictedSecurity.OpenJCEPlusFIPS.FIPS140-3-Custom.jce.provider.5 = com.ibm.ws.collective.security.internal.provider.CollectiveProvider

dev/cnf/resources/bin/tool

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,34 @@ if [ -z "${JAVA_HOME}" ]; then
278278
JAVA_PATH_FROM_PATH=$(command -v java)
279279
if [ -n "${JAVA_PATH_FROM_PATH}" ] ; then
280280
JPMS_MODULE_FILE_LOCATION=$(dirname $(dirname $JAVA_PATH_FROM_PATH))/lib/modules
281+
IBM_SDK_FIPS140_3_FILE_LOCATION=$(dirname "$(dirname "${JAVA_PATH_FROM_PATH}")")/jre/fips140-3
281282
fi
282283
else
283284
JPMS_MODULE_FILE_LOCATION="${JAVA_HOME}/lib/modules"
285+
IBM_SDK_FIPS140_3_FILE_LOCATION="${JAVA_HOME}/fips140-3"
284286
fi
285287

286288
# If this is a Java 9 JDK, add some JDK 9 workarounds to the JVM_ARGS
287289
if [ -f "${JPMS_MODULE_FILE_LOCATION}" ]; then
288290
JVM_ARGS="--add-opens java.base/java.lang=ALL-UNNAMED ${JVM_ARGS}"
289291
fi
290292

293+
# If ENABLE_FIPS140_3 is set by the user then add appropiate FIPS140-3 JVM options
294+
if [ -n "${ENABLE_FIPS140_3+set}" ] && [ "${ENABLE_FIPS140_3}" != false ]; then
295+
if [ -d "${IBM_SDK_FIPS140_3_FILE_LOCATION}" ]; then
296+
JVM_ARGS="-Xenablefips140-3 -Dcom.ibm.jsse2.usefipsprovider=true -Dcom.ibm.jsse2.usefipsProviderName=IBMJCEPlusFIPS ${JVM_ARGS}"
297+
else
298+
if grep -q "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "${JAVA_HOME}/conf/security/java.security" ; then
299+
SEMERU_FIPS=true
300+
elif grep -q "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "$(dirname $(dirname $(command -v java)))/conf/security/java.security" ; then
301+
SEMERU_FIPS=true
302+
fi
303+
if [ -n SEMERU_FIPS ]; then
304+
JVM_ARGS="-Dsemeru.fips=true -Dsemeru.customprofile=OpenJCEPlusFIPS.FIPS140-3-Liberty -Djava.security.properties=${WLP_INSTALL_DIR}/lib/security/fips140_3/FIPS140-3-Liberty.properties ${JVM_ARGS}"
305+
fi
306+
fi
307+
fi
308+
291309
# Prevent the Java invocation appearing as an application on a mac
292310
# Setting on all platforms to avoid cross platform bugs
293311
JVM_ARGS="-Djava.awt.headless=true ${JVM_ARGS}"

dev/cnf/resources/bin/tool.bat

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ if NOT defined JAVA_HOME (
5656
@REM If this is a Java 9 JDK, add some JDK 9 workarounds to the JVM_ARGS
5757
if exist "%JAVA_HOME%\lib\modules" set JVM_ARGS=--add-opens java.base/java.lang=ALL-UNNAMED !JVM_ARGS!
5858

59+
@REM If ENABLE_FIPS140_3 is specified and has a value, add FIPS140-3
60+
if defined ENABLE_FIPS140_3 (
61+
if "%ENABLE_FIPS140_3" neq "false" (
62+
@REM determine if we are using IBM SDK 8 with FIPS140-3 support
63+
if exist "%JAVA_HOME%\fips140-3" set IBM_SDK_8=true
64+
if NOT defined IBM_SDK_8 (
65+
if exist "%JRE_HOME%\fips140-3" set IBM_SDK_8=true
66+
if NOT defined IBM_SDK_8 (
67+
if exist "%WLP_DEFAULT_JAVA_HOME%\jre\fips140-3" set IBM_SDK_8=true
68+
)
69+
)
70+
if not defined IBM_SDK_8 (
71+
for /f "delims=" %%a in ('find "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "!JAVA_HOME!\conf\security\java.security"') do (
72+
if defined SKIP_FIRST_LINE (
73+
set SEMERU_FIPS=true
74+
) else (
75+
set SKIP_FIRST_LINE="true"
76+
)
77+
)
78+
)
79+
if defined IBM_SDK_8 (
80+
set JVM_ARGS=-Xenablefips140-3 -Dcom.ibm.jsse2.usefipsprovider=true -Dcom.ibm.jsse2.usefipsProviderName=IBMJCEPlusFIPS !JVM_ARGS!
81+
) else if defined SEMERU_FIPS (
82+
set JVM_ARGS=-Dsemeru.fips=true -Dsemeru.customprofile=OpenJCEPlusFIPS.FIPS140-3-Liberty -Djava.security.properties=!WLP_INSTALL_DIR!\lib\security\fips140_3\FIPS140-3-Liberty.properties !JVM_ARGS!
83+
)
84+
)
85+
)
86+
5987
set JVM_ARGS=-Djava.awt.headless=true !JVM_ARGS!
6088
set TOOL_JAVA_CMD_QUOTED=!JAVA_CMD_QUOTED! !JVM_ARGS! -jar "!WLP_INSTALL_DIR!\bin\@TOOL_JAR@"
6189

dev/com.ibm.ws.appclient.boot.ws-client/publish/bin/client

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ clientEnvDefaults()
390390
JVM_ARGS="${JVM_ARGS} -Dfile.encoding=$defaultFileEncoding"
391391
fi
392392
fi
393-
393+
394394
clientUmask
395395
}
396396

@@ -441,6 +441,8 @@ clientEnvAndJVMOptions()
441441
mergeJVMOptions "${WLP_INSTALL_DIR}/lib/platform/java/java9.options"
442442
fi
443443

444+
enableFIPS140_3
445+
444446
return $rc
445447
}
446448

@@ -468,6 +470,39 @@ mergeJVMOptions()
468470
fi
469471
}
470472

473+
enableFIPS140_3()
474+
{
475+
if [ -n "${ENABLE_FIPS140_3+set}" ] && [ "$ENABLE_FIPS140_3" != false ]; then
476+
if [ -d "${JAVA_HOME}/jre/fips140-3" ] || [ -d "${JAVA_HOME}/fips140-3" ] || [ -d "$(dirname $(dirname $(command -v java)))/jre/fips140-3" ]; then
477+
JVM_ARGS="${JVM_ARGS} -Xenablefips140-3 -Dcom.ibm.jsse2.usefipsprovider=true -Dcom.ibm.jsse2.usefipsProviderName=IBMJCEPlusFIPS"
478+
else
479+
if [ -f "${JAVA_HOME}/conf/security/java.security" ]; then
480+
if grep -q "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "${JAVA_HOME}/conf/security/java.security" ; then
481+
SEMERU_FIPS=true
482+
elif grep -q "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "$(dirname $(dirname $(command -v java)))/conf/security/java.security" ; then
483+
SEMERU_FIPS=true
484+
fi
485+
if [ -n "${SEMERU_FIPS}" ]; then
486+
saveIFS=$IFS
487+
IFS=":"
488+
ENABLE_FIPS140_3="${WLP_INSTALL_DIR}/lib/security/fips140_3/FIPS140-3-Liberty.properties:${ENABLE_FIPS140_3}"
489+
for file in ${ENABLE_FIPS140_3}; do
490+
profileFile=$file
491+
done
492+
IFS=$saveIFS
493+
for line in $(readNativeFile "$profileFile" '[#_A-Za-z=]' | tr -d '\r'); do
494+
match=$(echo "$line" | sed -n 's/.*RestrictedSecurity\.\([a-zA-Z0-9\.-]*\)\.extends$/\1/p')
495+
if [ -n "$match" ]; then
496+
profile=$match
497+
fi
498+
done
499+
JVM_ARGS="${JVM_ARGS} -Dsemeru.fips=true -Dsemeru.customprofile=${profile} -Djava.security.propertiesList=${ENABLE_FIPS140_3}"
500+
fi
501+
fi
502+
fi
503+
fi
504+
}
505+
471506
##
472507
## readClientEnv: Read client.env file and export environment variables.
473508
readClientEnv()

dev/com.ibm.ws.appclient.boot.ws-client/publish/bin/client.bat

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ goto:eof
175175
if %RC% == 2 goto:eof
176176

177177
call:clientWorkingDirectory
178+
call:enableFIPS140_3
179+
178180
!JAVA_CMD_QUOTED! !JAVA_AGENT_QUOTED! !JVM_OPTIONS! !JAVA_PARAMS_QUOTED! --batch-file !PARAMS_QUOTED!
179181
set RC=%errorlevel%
180182
call:javaCmdResult
@@ -260,7 +262,6 @@ goto:eof
260262
if exist "%JAVA_HOME%\jre\bin\java.exe" set JAVA_HOME=!JAVA_HOME!\jre
261263
set JAVA_CMD_QUOTED="!JAVA_HOME!\bin\java"
262264
)
263-
264265
goto:eof
265266

266267
@REM
@@ -302,7 +303,7 @@ goto:eof
302303
)
303304

304305
set JVM_OPTIONS=!JVM_OPTIONS!%JVM_TEMP_OPTIONS%
305-
306+
306307
goto:eof
307308

308309
@REM
@@ -350,6 +351,61 @@ goto:eof
350351
cd /d "%CLIENT_OUTPUT_DIR%"
351352
goto:eof
352353

354+
@REM Check if the ENABLE_FIPS140_3 variable has been set by the user
355+
@REM If ENABLE_FIPS140_3 is set, determine the correct JVM options depending on the version of Java to be used and add to list
356+
@REM The version of java is determined to correctly set IBM SDK 8 or Semeru FIPS140-3 flags
357+
:enableFIPS140_3
358+
@REM CHeck if FIPS140-3 is enabled for the client
359+
if defined ENABLE_FIPS140_3 (
360+
if "%ENABLE_FIPS140_3%" neq "false" (
361+
@REM determine if we are using IBM SDK 8 with FIPS140-3 support
362+
if exist "%JAVA_HOME%\fips140-3" set IBM_SDK_8=true
363+
if NOT defined IBM_SDK_8 (
364+
if exist "%JRE_HOME%\fips140-3" set IBM_SDK_8=true
365+
if NOT defined IBM_SDK_8 (
366+
if exist "%WLP_DEFAULT_JAVA_HOME%\jre\fips140-3" set IBM_SDK_8=true
367+
)
368+
)
369+
if not defined IBM_SDK_8 (
370+
for /f "delims=" %%a in ('find "OpenJCEPlusFIPS.FIPS140-3-Strongly-Enforced" "!JAVA_HOME!\conf\security\java.security"') do (
371+
if defined SKIP_FIRST_LINE (
372+
set SEMERU_FIPS=true
373+
) else (
374+
set SKIP_FIRST_LINE="true"
375+
)
376+
)
377+
)
378+
379+
if defined IBM_SDK_8 (
380+
set JVM_OPTIONS=-Xenablefips140-3 -Dcom.ibm.jsse2.usefipsprovider=true -Dcom.ibm.jsse2.usefipsProviderName=IBMJCEPlusFIPS !JVM_OPTIONS!
381+
) else (
382+
if defined SEMERU_FIPS (
383+
@REM de-quote input variable
384+
set ENABLE_FIPS140_3=!ENABLE_FIPS140_3:"=!
385+
@REM add Liberty FIPS profile
386+
set ENABLE_FIPS140_3=!WLP_INSTALL_DIR!\lib\security\fips140_3\FIPS140-3-Liberty.properties;!ENABLE_FIPS140_3!
387+
@REM Retrieve name of Semeru FIPS140-3 profile from the last file in provided paths
388+
for %%i in ("!ENABLE_FIPS140_3:;=";"!") do (
389+
set "file=%%~i"
390+
)
391+
for /f "delims== " %%l in (!file!) do (
392+
set line=%%l
393+
if /i "!line:~0,18!" == "RestrictedSecurity" (
394+
set "line=!line:~19!"
395+
if "!line:~-7!" == "extends" (
396+
set profileName=!line:~0,-8!
397+
)
398+
)
399+
)
400+
set JVM_OPTIONS=-Dsemeru.fips=true -Dsemeru.customprofile=!profileName! -Djava.security.propertiesList=!ENABLE_FIPS140_3! !JVM_OPTIONS!
401+
)
402+
)
403+
)
404+
)
405+
406+
goto:eof
407+
408+
353409
@REM
354410
@REM Check the result of a Java command.
355411
@REM

0 commit comments

Comments
 (0)