Skip to content

Commit 979bbeb

Browse files
committed
Code review feedback
1 parent 934696e commit 979bbeb

6 files changed

Lines changed: 224 additions & 104 deletions

File tree

.github/workflows/cjose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
wolfssl_ref: [ 'v5.8.2-stable' ]
2525
openssl_ref: [ 'openssl-3.5.2' ]
2626
replace_default: [ true ]
27+
fips: [ false ]
2728

2829
test_cjose:
2930
runs-on: ubuntu-22.04
@@ -43,6 +44,7 @@ jobs:
4344
openssl_ref: [ 'openssl-3.5.2' ]
4445
force_fail: [ 'WOLFPROV_FORCE_FAIL=1', '' ]
4546
replace_default: [ true ]
47+
fips: [ false ]
4648
env:
4749
WOLFSSL_PACKAGES_PATH: /tmp/wolfssl-packages
4850
OPENSSL_PACKAGES_PATH: /tmp/openssl-packages
@@ -108,7 +110,7 @@ jobs:
108110
working-directory: cjose
109111
run: |
110112
# Verify wolfProvider is properly installed
111-
$GITHUB_WORKSPACE/scripts/verify-debian.sh
113+
$GITHUB_WORKSPACE/scripts/verify-install.sh ${{ matrix.replace_default && '-replace-default' || '' }} ${{ matrix.fips && '--fips' || '' }}
112114
export ${{ matrix.force_fail }}
113115
114116
make test 2>&1 | tee cjose-test.log

scripts/utils-openssl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ check_openssl_replace_default_mismatch() {
167167
patch_openssl_version() {
168168
# Patch the OpenSSL version (wolfProvider/openssl-source/VERSION.dat)
169169
# with our BUILD_METADATA, depending on the FIPS flag. Either "wolfProvider" or "wolfProvider-fips".
170-
if [ "$WOLFSSL_ISFIPS" = "1" ]; then
170+
if [ ${WOLFSSL_ISFIPS:-0} -eq 1 ]; then
171171
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-fips/g' ${OPENSSL_SOURCE_DIR}/VERSION.dat
172172
else
173173
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-nonfips/g' ${OPENSSL_SOURCE_DIR}/VERSION.dat

scripts/utils-wolfssl.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ WOLFSSL_CONFIG_CFLAGS=${WOLFSSL_CONFIG_CFLAGS:-"-I${OPENSSL_INSTALL_DIR}/include
3535
WOLFSSL_DEBUG_ASN_TEMPLATE=${DWOLFSSL_DEBUG_ASN_TEMPLATE:-0}
3636
WOLFPROV_DISABLE_ERR_TRACE=${WOLFPROV_DISABLE_ERR_TRACE:-0}
3737
WOLFPROV_DEBUG=${WOLFPROV_DEBUG:-0}
38+
WOLFPROV_BUILD_DEBIAN=${WOLFPROV_BUILD_DEBIAN:-0}
3839
USE_CUR_TAG=${USE_CUR_TAG:-0}
3940

4041
clean_wolfssl() {
@@ -106,7 +107,7 @@ install_wolfssl() {
106107
printf "ERROR: System wolfSSL is FIPS, but WOLFSSL_ISFIPS is not set to 1\n"
107108
do_cleanup
108109
exit 1
109-
elif [ $? -eq 0 ] && [ "$WOLFSSL_ISFIPS" != "0" ]; then
110+
elif [ $? -ne 0 ] && [ "$WOLFSSL_ISFIPS" != "0" ]; then
110111
printf "ERROR: System wolfSSL is non-FIPS, but WOLFSSL_ISFIPS is set to 1\n"
111112
do_cleanup
112113
exit 1

scripts/verify-debian.sh

Lines changed: 0 additions & 100 deletions
This file was deleted.

scripts/verify-install.sh

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2006-2024 wolfSSL Inc.
4+
#
5+
# This file is part of wolfProvider.
6+
#
7+
# wolfProvider is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# wolfProvider is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
# This script verifies that wolfProvider is correctly installed and configured.
21+
22+
# Default values
23+
REPLACE_DEFAULT=0
24+
FIPS=0
25+
26+
# Parse command line arguments
27+
while [[ $# -gt 0 ]]; do
28+
case $1 in
29+
--replace-default)
30+
REPLACE_DEFAULT=1
31+
shift
32+
;;
33+
--fips)
34+
FIPS=1
35+
shift
36+
;;
37+
--help|-h)
38+
echo "Usage: $0 [--replace-default] [--fips]"
39+
echo " --replace-default Set replace default to 1 (default: 0)"
40+
echo " --fips Set FIPS to 1 (default: 0)"
41+
echo " --help, -h Show this help message"
42+
exit 0
43+
;;
44+
*)
45+
echo "Unknown option: $1"
46+
echo "Use --help for usage information"
47+
exit 1
48+
;;
49+
esac
50+
done
51+
52+
handle_error() {
53+
local message="$1"
54+
local exit_code="${2:-1}"
55+
56+
echo "ERROR: $message" >&2
57+
exit $exit_code
58+
}
59+
60+
log_success() {
61+
echo "SUCCESS: $1"
62+
}
63+
log_info() {
64+
echo "INFO: $1"
65+
}
66+
67+
verify_provider_loaded() {
68+
local replace_default="$1"
69+
local fips="$2"
70+
71+
# When replace-default is 0, expect something like this:
72+
# $ openssl list -providers
73+
# Providers:
74+
# libwolfprov
75+
# name: wolfSSL Provider
76+
# version: 1.0.2
77+
# status: active
78+
79+
# When replace-default is 1, expect something like this:
80+
# $ openssl list -providers
81+
# Providers:
82+
# default
83+
# name: wolfSSL Provider
84+
# version: 1.0.2
85+
# status: active
86+
87+
log_info "Verifying wolfProvider is active..."
88+
89+
local provider_output
90+
provider_output=$(openssl list -providers 2>&1)
91+
92+
echo "Provider list:"
93+
echo "$provider_output"
94+
95+
# Check for the presence of "wolfSSL Provider" and "status: active"
96+
if echo "$provider_output" | grep -qi "wolfSSL Provider" && echo "$provider_output" | grep -qi "status: active"; then
97+
log_success "wolfProvider is loaded"
98+
else
99+
handle_error "wolfProvider not found in provider list"
100+
fi
101+
102+
if [ $replace_default -eq 0 ]; then
103+
if echo "$provider_output" | grep -qi "libwolfprov"; then
104+
log_success "wolfProvider is non-default"
105+
else
106+
handle_error "wolfProvider is default"
107+
fi
108+
else
109+
if echo "$provider_output" | grep -qi "default"; then
110+
log_success "wolfProvider is default"
111+
else
112+
handle_error "wolfProvider is non-default"
113+
fi
114+
fi
115+
116+
# Expect "wolfSSL Provider" for non-FIPS, "wolfSSL Provider FIPS" for FIPS
117+
if [ $fips -eq 0 ]; then
118+
if echo "$provider_output" | grep -q "wolfSSL Provider FIPS"; then
119+
handle_error "wolfSSL Provider is FIPS"
120+
else
121+
log_success "wolfSSL Provider is non-FIPS"
122+
fi
123+
else
124+
if echo "$provider_output" | grep -q "wolfSSL Provider FIPS"; then
125+
log_success "wolfSSL Provider is FIPS"
126+
else
127+
handle_error "wolfSSL Provider is non-FIPS"
128+
fi
129+
fi
130+
}
131+
132+
verify_openssl_version() {
133+
local replace_default="$1"
134+
local fips="$2"
135+
136+
# When replace-default is 0, expect something like this:
137+
# $openssl version
138+
# OpenSSL 3.0.17 1 Jul 2025 (Library: OpenSSL 3.0.17 1 Jul 2025
139+
140+
# When replace-default is 1 and fips is 0, expect something like this:
141+
# $ openssl version
142+
# OpenSSL 3.5.2+wolfProvider-nonfips 03 Oct 2025 (Library: OpenSSL 3.5.2+wolfProvider-nonfips 03 Oct 2025)
143+
144+
log_info "Verifying OpenSSL version..."
145+
146+
local version_output
147+
version_output=$(openssl version -a 2>&1)
148+
149+
echo "OpenSSL version information:"
150+
echo "$version_output"
151+
152+
if [ $replace_default -eq 0 ]; then
153+
# Verify that wolfProv (case-insensitive) is in the version output
154+
if echo "$version_output" | grep -qi "wolfProv"; then
155+
log_success "wolfProv is in the version output"
156+
else
157+
handle_error "wolfProv is not in the version output"
158+
fi
159+
else
160+
# Verify that wolfProvider (case-insensitive) is in the version output
161+
# for both the OpenSSL version and the Library version
162+
# Check for both "# OpenSSL 3.x.y+wolfProvider" and "Library: OpenSSL 3.x.y+wolfProvider" separately
163+
if echo "$version_output" | grep -qiE "OpenSSL 3\.[0-9]+\.[0-9]+\+wolfProvider"; then
164+
log_success "OpenSSL version is correct"
165+
else
166+
handle_error "OpenSSL version is incorrect for replace default"
167+
fi
168+
169+
if echo "$version_output" | grep -qiE "Library: OpenSSL 3\.[0-9]+\.[0-9]+\+wolfProvider"; then
170+
log_success "libssl3 version is correct"
171+
else
172+
handle_error "libssl3 version is incorrect for replace default"
173+
fi
174+
175+
if [ $fips -eq 0 ]; then
176+
# For non-FIPS, expect "wolfProvider-nonfips" in the version output
177+
# For FIPS, expect "wolfProvider-fips" in the version output
178+
if echo "$version_output" | grep -qi "wolfProvider-nonfips"; then
179+
log_success "wolfProvider-nonfips is in the version output"
180+
else
181+
handle_error "wolfProvider-nonfips is not in the version output"
182+
fi
183+
else
184+
if echo "$version_output" | grep -qi "wolfProvider-fips"; then
185+
log_success "wolfProvider-fips is in the version output"
186+
else
187+
handle_error "wolfProvider-fips is not in the version output"
188+
fi
189+
fi
190+
fi
191+
}
192+
193+
# Main verification function
194+
verify_wolfprovider() {
195+
local replace_default="$1"
196+
local fips="$2"
197+
198+
# echo "Replace default value: $replace_default"
199+
# echo "FIPS value: $fips"
200+
201+
echo "--------------------------------"
202+
verify_provider_loaded $replace_default $fips
203+
echo "--------------------------------"
204+
verify_openssl_version $replace_default $fips
205+
echo "--------------------------------"
206+
echo "wolfProvider installed correctly"
207+
208+
return 0
209+
}
210+
211+
verify_wolfprovider "$REPLACE_DEFAULT" "$FIPS"

src/wp_wolfprov.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,20 @@ static int wolfprov_get_params(void* provCtx, OSSL_PARAM params[])
310310
int ok = 1;
311311
OSSL_PARAM* p;
312312

313+
#ifdef HAVE_FIPS
314+
static const char* provider_name = "wolfSSL Provider FIPS";
315+
#else
316+
static const char* provider_name = "wolfSSL Provider";
317+
#endif
318+
313319
WOLFPROV_ENTER(WP_LOG_PROVIDER, "wolfprov_get_params");
314320

315321
(void)provCtx;
316322

317323
/* Look for provider name as a parameter to return. */
318324
p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
319325
/* Set the string if name requested. */
320-
if ((p != NULL) && (!OSSL_PARAM_set_utf8_ptr(p, "wolfSSL Provider"))) {
326+
if ((p != NULL) && (!OSSL_PARAM_set_utf8_ptr(p, provider_name))) {
321327
ok = 0;
322328
}
323329
if (ok) {

0 commit comments

Comments
 (0)