Skip to content

Commit 0fd5c04

Browse files
aidangarskeTest User
andauthored
Add FIPS version selection support (#294)
* Add FIPS version selection support * Fix spelling from codespell * remove FIPS_VERSION and simply use tag and detect configure * Add fix for CI and make tets --------- Co-authored-by: Test User <[email protected]>
1 parent ed5532f commit 0fd5c04

File tree

4 files changed

+100
-40
lines changed

4 files changed

+100
-40
lines changed

.github/workflows/fips-ready.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- name: Build wolfProvider with FIPS Ready Bundle
5151
run: |
5252
./scripts/build-wolfprovider.sh --fips-bundle="$FIPS_BUNDLE_PATH" \
53-
--fips-version=ready --wolfssl-ver=v${{matrix.wolfssl_bundle_ref}}-stable
53+
--fips-check=ready --wolfssl-ver=v${{matrix.wolfssl_bundle_ref}}-stable
5454
5555
- name: Run FIPS Command Tests
5656
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ unzip wolfssl-fips-ready.zip
150150

151151
Then use the following command to build wolfProvider with FIPS enabled.
152152
```
153-
./scripts/build-wolfprovider.sh --fips-bundle="path/to/fips-bundle" --fips-version=ready --distclean
153+
./scripts/build-wolfprovider.sh --fips-bundle="path/to/fips-bundle" --fips-check=ready --distclean
154154
```
155155

156156
## Testing

scripts/build-wolfprovider.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ show_help() {
1414
echo " --disable-err-trace No debug trace messages from library errors in wolfSSL"
1515
echo " --openssl-ver=VER Which version of OpenSSL to clone"
1616
echo " --wolfssl-ver=VER Which version of wolfSSL to clone"
17-
echo " --enable-fips Build wolfProvider with a cloned FIPS bundle. Cloned FIPS bundle can be changed with --fips-check"
18-
echo " --fips-bundle=DIR Build wolfProvider with a directory containing a wolfSSL FIPS bundle instead of cloning from GitHub. Requires a FIPS version to be given by --fips-version"
19-
echo " --fips-check=TAG Choose a FIPS tag to clone. May require a version to be given by --fips-version"
20-
echo " --fips-version=VER Choose the wolfSSL FIPS version"
17+
echo " --enable-fips Build wolfProvider with a cloned FIPS bundle. Use with --fips-check to specify tag (default: v5.2.4)"
18+
echo " --fips-bundle=DIR Build wolfProvider with a directory containing a wolfSSL FIPS bundle. Use with --fips-check to specify tag"
19+
echo " --fips-check=TAG Choose a FIPS tag (v5.2.1, v5.2.4, linuxv5.2.1, v6.0.0, ready, etc). Automatically determines configure option"
2120
echo " --debian Build a Debian package"
2221
echo " --debian --enable-fips Build a Debian package with FIPS support"
2322
echo " --quicktest Disable some tests for a faster testing suite"
@@ -30,8 +29,7 @@ show_help() {
3029
echo " WOLFSSL_TAG wolfSSL tag to use (e.g., v5.8.0-stable)"
3130
echo " WOLFSSL_ISFIPS If set to 1, clones a wolfSSL FIPS bundle from GitHub"
3231
echo " WOLFSSL_FIPS_BUNDLE Directory containing the wolfSSL FIPS bundle to use instead of cloning from GitHub"
33-
echo " WOLFSSL_FIPS_VERSION Version of wolfSSL FIPS bundle (v5, v6, ready), used as an argument for --enable-fips when configuring wolfSSL"
34-
echo " WOLFSSL_FIPS_CHECK_TAG Tag for wolfSSL FIPS bundle (linuxv5.2.1, v6.0.0, etc), used as an argument for fips-check.sh when cloning a wolfSSL FIPS version"
32+
echo " WOLFSSL_FIPS_CHECK_TAG Tag for wolfSSL FIPS bundle (v5.2.1, v5.2.4, linuxv5.2.1, v6.0.0, ready, etc). Automatically determines configure option (default: v5.2.4)"
3533
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
3634
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
3735
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
@@ -86,7 +84,6 @@ for arg in "$@"; do
8684
WOLFSSL_ISFIPS=1
8785
;;
8886
--fips-bundle=*)
89-
unset WOLFSSL_FIPS_CHECK_TAG
9087
IFS='=' read -r trash fips_bun <<< "$arg"
9188
if [ -z "$fips_bun" ]; then
9289
echo "No directory given for --fips-bundle"
@@ -95,22 +92,13 @@ for arg in "$@"; do
9592
WOLFSSL_FIPS_BUNDLE="$fips_bun"
9693
;;
9794
--fips-check=*)
98-
unset WOLFSSL_FIPS_BUNDLE
9995
IFS='=' read -r trash fips_tag <<< "$arg"
10096
if [ -z "$fips_tag" ]; then
10197
echo "No tag given for --fips-check"
10298
args_wrong+="$arg, "
10399
fi
104100
WOLFSSL_FIPS_CHECK_TAG="$fips_tag"
105101
;;
106-
--fips-version=*)
107-
IFS='=' read -r trash fips_ver <<< "$arg"
108-
if [ -z "$fips_ver" ]; then
109-
echo "No version given for --fips-version"
110-
args_wrong+="$arg, "
111-
fi
112-
WOLFSSL_FIPS_VERSION="$fips_ver"
113-
;;
114102
--debian)
115103
build_debian=1
116104
;;

scripts/utils-wolfssl.sh

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ WOLFSSL_TAG=${WOLFSSL_TAG:-"v5.8.2-stable"}
2626
WOLFSSL_SOURCE_DIR=${SCRIPT_DIR}/../wolfssl-source
2727
WOLFSSL_INSTALL_DIR=${SCRIPT_DIR}/../wolfssl-install
2828
WOLFSSL_ISFIPS=${WOLFSSL_ISFIPS:-0}
29+
WOLFSSL_FIPS_VERSION=${WOLFSSL_FIPS_VERSION:-"5.2.4"}
2930
WOLFSSL_FIPS_CONFIG_OPTS=${WOLFSSL_CONFIG_OPTS:-'--enable-opensslcoexist '}
3031
WOLFSSL_FIPS_CONFIG_CFLAGS=${WOLFSSL_CONFIG_CFLAGS:-"-I${OPENSSL_INSTALL_DIR}/include -DWOLFSSL_OLD_OID_SUM -DWOLFSSL_DH_EXTRA"}
3132
WOLFSSL_CONFIG_OPTS=${WOLFSSL_CONFIG_OPTS:-'--enable-all-crypto --with-eccminsz=192 --with-max-ecc-bits=1024 --enable-opensslcoexist --enable-sha'}
@@ -110,7 +111,7 @@ install_wolfssl() {
110111
do_cleanup
111112
exit 1
112113
fi
113-
114+
114115
printf "\nSkipping wolfSSL installation - libwolfssl and libwolfssl-dev packages are already installed.\n"
115116
# Set WOLFSSL_INSTALL_DIR to system installation directory
116117
WOLFSSL_INSTALL_DIR="/usr"
@@ -141,38 +142,96 @@ install_wolfssl() {
141142
elif [ "$WOLFSSL_DEBUG_ASN_TEMPLATE" = "1" ] && ( [ "$WOLFSSL_ISFIPS" = "1" ] || [ -n "$WOLFSSL_FIPS_BUNDLE" ] ); then
142143
WOLFSSL_FIPS_CONFIG_CFLAGS+=" -DWOLFSSL_DEBUG_ASN_TEMPLATE"
143144
fi
144-
if [ -n "$WOLFSSL_FIPS_BUNDLE" ]; then
145-
if [ ! -n "$WOLFSSL_FIPS_VERSION" ]; then
146-
printf "ERROR, must specify version if using FIPS bundle (v5, v6, ready)"
145+
if [ -n "$WOLFSSL_FIPS_BUNDLE" ] || [ "$WOLFSSL_ISFIPS" = "1" ]; then
146+
if [ -n "$WOLFSSL_FIPS_BUNDLE" ] && [ -z "$WOLFSSL_FIPS_CHECK_TAG" ]; then
147+
printf "ERROR, must specify tag if using FIPS bundle (v5.2.1, v5.2.4, linuxv5.2.1, v6.0.0, ready)"
147148
do_cleanup
148149
exit 1
149150
fi
150-
printf "using FIPS bundle ... "
151-
CONF_ARGS+=" --enable-fips=$WOLFSSL_FIPS_VERSION"
152-
WOLFSSL_CONFIG_OPTS=$WOLFSSL_FIPS_CONFIG_OPTS
153-
WOLFSSL_CONFIG_CFLAGS=$WOLFSSL_FIPS_CONFIG_CFLAGS
154-
elif [ "$WOLFSSL_ISFIPS" = "1" ]; then
155-
printf "with FIPS ... "
156-
if [ -n "$WOLFSSL_FIPS_VERSION" ]; then
157-
CONF_ARGS+=" --enable-fips=$WOLFSSL_FIPS_VERSION"
151+
152+
# Determine FIPS tag - use FIPS_CHECK_TAG if provided, default to v5.2.4
153+
local fips_tag="${WOLFSSL_FIPS_CHECK_TAG}"
154+
fips_tag="${fips_tag:-v5.2.4}"
155+
156+
# Determine configure option from tag
157+
local fips_configure_arg=""
158+
case "$fips_tag" in
159+
v5.2.*|v5.3.*|v5.4.*|v5.5.*|linuxv5.*)
160+
fips_configure_arg="v5"
161+
;;
162+
v6.*|linuxv6.*)
163+
fips_configure_arg="v6"
164+
;;
165+
*)
166+
# For ready, v5, v6, or other tags, use as-is
167+
fips_configure_arg="$fips_tag"
168+
;;
169+
esac
170+
171+
if [ -n "$WOLFSSL_FIPS_BUNDLE" ]; then
172+
printf "using FIPS bundle ${fips_tag} ... "
158173
else
159-
CONF_ARGS+=" --enable-fips=v5"
174+
printf "with FIPS ${fips_tag} ... "
160175
fi
176+
CONF_ARGS+=" --enable-fips=$fips_configure_arg"
161177
WOLFSSL_CONFIG_OPTS=$WOLFSSL_FIPS_CONFIG_OPTS
162178
WOLFSSL_CONFIG_CFLAGS=$WOLFSSL_FIPS_CONFIG_CFLAGS
163-
if [ ! -e "XXX-fips-test" ]; then
164-
# Sometimes the system OpenSSL is different than the one we're using. So for the 'git' commands, we'll just use whatever the system comes with
165-
if [ -n "$WOLFSSL_FIPS_CHECK_TAG" ]; then
166-
LD_LIBRARY_PATH="" ./fips-check.sh "$WOLFSSL_FIPS_CHECK_TAG" keep nomakecheck >>$LOG_FILE 2>&1
179+
# Only run fips-check if not using a bundle
180+
if [ -z "$WOLFSSL_FIPS_BUNDLE" ] && [ ! -e "XXX-fips-test" ]; then
181+
# Determine which FIPS check script to use based on tag
182+
local fips_check_script=""
183+
case "$fips_tag" in
184+
v5.2.*|v5.3.*|v5.4.*|v5.5.*)
185+
fips_check_script="fips-check-PILOT.sh"
186+
;;
187+
linuxv5.*|linuxv6.*)
188+
fips_check_script="fips-check.sh"
189+
;;
190+
*)
191+
fips_check_script="fips-check.sh"
192+
;;
193+
esac
194+
195+
# Copy fips-check-PILOT.sh from fips-src repo if needed
196+
if [ "$fips_check_script" = "fips-check-PILOT.sh" ] && [ ! -f "$fips_check_script" ]; then
197+
if command -v git >/dev/null 2>&1; then
198+
# Try to get the script from fips-src repo
199+
if [ -d "../fips-src" ]; then
200+
cp ../fips-src/fips-check-PILOT.sh . 2>/dev/null || true
201+
fi
202+
# If we still can't find it clone it temporarily
203+
if [ ! -f "$fips_check_script" ]; then
204+
LD_LIBRARY_PATH="" git clone --depth=1 [email protected]:wolfSSL/fips-src.git fips-src >>$LOG_FILE 2>&1
205+
cp fips-src/fips-check-PILOT.sh . 2>/dev/null || true
206+
rm -rf fips-src
207+
fi
208+
fi
209+
if [ ! -f "$fips_check_script" ]; then
210+
printf "ERROR: Could not find fips-check-PILOT.sh script\n"
211+
rm -rf ${WOLFSSL_INSTALL_DIR}
212+
do_cleanup
213+
exit 1
214+
fi
215+
fi
216+
217+
# Sometimes the system OpenSSL is different than the one we're using.
218+
# So for the 'git' commands, we'll just use whatever the system comes with.
219+
if [ "$fips_check_script" = "fips-check-PILOT.sh" ]; then
220+
# PILOT script has different usage: [flavor] [keep]
221+
LD_LIBRARY_PATH="" ./$fips_check_script "$fips_tag" keep >$LOG_FILE 2>&1
222+
RET_CODE=$?
167223
else
168-
LD_LIBRARY_PATH="" ./fips-check.sh linuxv5.2.1 keep nomakecheck >>$LOG_FILE 2>&1
224+
# Regular fips-check.sh usage: [flavor] [keep] [nomakecheck]
225+
LD_LIBRARY_PATH="" ./$fips_check_script "$fips_tag" keep nomakecheck >$LOG_FILE 2>&1
226+
RET_CODE=$?
169227
fi
170-
if [ $? != 0 ]; then
171-
printf "ERROR checking out FIPS\n"
228+
if [ $RET_CODE != 0 ]; then
229+
printf "ERROR checking out FIPS (return code: $RET_CODE)\n"
172230
rm -rf ${WOLFSSL_INSTALL_DIR}
173231
do_cleanup
174232
exit 1
175233
fi
234+
176235
(cd XXX-fips-test && ./autogen.sh && ./configure ${CONF_ARGS} ${WOLFSSL_CONFIG_OPTS} CFLAGS="${WOLFSSL_CONFIG_CFLAGS}" && make && ./fips-hash.sh) >>$LOG_FILE 2>&1
177236
if [ $? != 0 ]; then
178237
printf "ERROR compiling FIPS version of wolfSSL\n"
@@ -181,7 +240,10 @@ install_wolfssl() {
181240
exit 1
182241
fi
183242
fi
184-
cd XXX-fips-test
243+
# Change to test directory for FIPS builds
244+
if [ -n "$WOLFSSL_FIPS_BUNDLE" ] || [ "$WOLFSSL_ISFIPS" = "1" ]; then
245+
cd XXX-fips-test
246+
fi
185247
fi
186248

187249
./configure ${CONF_ARGS} ${WOLFSSL_CONFIG_OPTS} CFLAGS="${WOLFSSL_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1
@@ -215,10 +277,20 @@ install_wolfssl() {
215277
do_cleanup
216278
exit 1
217279
fi
280+
printf "Done.\n"
281+
218282
if [ "$WOLFSSL_ISFIPS" = "1" ]; then
283+
printf "\tTesting wolfSSL FIPS ${WOLFSSL_TAG} ... "
284+
make test >>$LOG_FILE 2>&1
285+
if [ $? != 0 ]; then
286+
printf "ERROR.\n"
287+
rm -rf ${WOLFSSL_INSTALL_DIR}
288+
do_cleanup
289+
exit 1
290+
fi
219291
cd ..
292+
printf "Done.\n"
220293
fi
221-
printf "Done.\n"
222294
fi
223295

224296
cd ..

0 commit comments

Comments
 (0)