Skip to content

Commit f5c01b7

Browse files
committed
Code review feedback
1 parent 934696e commit f5c01b7

File tree

6 files changed

+227
-103
lines changed

6 files changed

+227
-103
lines changed

.github/workflows/cjose.yml

Lines changed: 4 additions & 0 deletions
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
@@ -88,6 +90,8 @@ jobs:
8890
apt install --reinstall -y \
8991
${{ env.WOLFPROV_PACKAGES_PATH }}/libwolfprov_*.deb
9092
93+
$GITHUB_WORKSPACE/scripts/verify-install.sh ${{ matrix.replace_default && '-replace-default' || '' }} ${{ matrix.fips && '--fips' || '' }}
94+
9195
- name: Download cjose
9296
uses: actions/checkout@v4
9397
with:

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: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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+
echo "Provider list:"
100+
echo "$provider_output"
101+
handle_error "wolfProvider not found in provider list"
102+
fi
103+
104+
if [ $replace_default -eq 0 ]; then
105+
if echo "$provider_output" | grep -qi "libwolfprov"; then
106+
log_success "wolfProvider is non-default"
107+
else
108+
handle_error "wolfProvider is default"
109+
fi
110+
111+
# Expect "libwolfprov" for non-FIPS, "libwolfprov-fips" for FIPS
112+
if [ $fips -eq 0 ]; then
113+
if echo "$provider_output" | grep -qi "libwolfprov"; then
114+
log_success "libwolfprov is in the provider list"
115+
else
116+
handle_error "libwolfprov is not in the provider list"
117+
fi
118+
else
119+
if echo "$provider_output" | grep -qi "libwolfprov-fips"; then
120+
log_success "libwolfprov-fips is in the provider list"
121+
else
122+
handle_error "libwolfprov-fips is not in the provider list"
123+
fi
124+
fi
125+
else
126+
if echo "$provider_output" | grep -qi "default"; then
127+
log_success "wolfProvider is default"
128+
else
129+
handle_error "wolfProvider is not default"
130+
fi
131+
fi
132+
}
133+
134+
verify_openssl_version() {
135+
local replace_default="$1"
136+
local fips="$2"
137+
138+
# When replace-default is 0, expect something like this:
139+
# $openssl version
140+
# OpenSSL 3.0.17 1 Jul 2025 (Library: OpenSSL 3.0.17 1 Jul 2025
141+
142+
# When replace-default is 1 and fips is 0, expect something like this:
143+
# $ openssl version
144+
# OpenSSL 3.5.2+wolfProvider-nonfips 03 Oct 2025 (Library: OpenSSL 3.5.2+wolfProvider-nonfips 03 Oct 2025)
145+
146+
log_info "Verifying OpenSSL version..."
147+
148+
local version_output
149+
version_output=$(openssl version -a 2>&1)
150+
151+
echo "OpenSSL version information:"
152+
echo "$version_output"
153+
154+
if [ $replace_default -eq 0 ]; then
155+
# Verify that wolfProv (case-insensitive) is in the version output
156+
if echo "$version_output" | grep -qi "wolfProv"; then
157+
log_success "wolfProv is in the version output"
158+
else
159+
handle_error "wolfProv is not in the version output"
160+
fi
161+
else
162+
# Verify that wolfProvider (case-insensitive) is in the version output
163+
# for both the OpenSSL version and the Library version
164+
# Check for both "# OpenSSL 3.x.y+wolfProvider" and "Library: OpenSSL 3.x.y+wolfProvider" separately
165+
if echo "$version_output" | grep -qiE "OpenSSL 3\.[0-9]+\.[0-9]+\+wolfProvider"; then
166+
log_success "OpenSSL version is correct"
167+
else
168+
handle_error "OpenSSL version is incorrect for replace default"
169+
fi
170+
171+
if echo "$version_output" | grep -qiE "Library: OpenSSL 3\.[0-9]+\.[0-9]+\+wolfProvider"; then
172+
log_success "libssl3 version is correct"
173+
else
174+
handle_error "libssl3 version is incorrect for replace default"
175+
fi
176+
177+
if [ $fips -eq 0 ]; then
178+
# For non-FIPS, expect "wolfProvider-nonfips" in the version output
179+
# For FIPS, expect "wolfProvider-fips" in the version output
180+
if echo "$version_output" | grep -qi "wolfProvider-nonfips"; then
181+
log_success "wolfProvider-nonfips is in the version output"
182+
else
183+
handle_error "wolfProvider-nonfips is not in the version output"
184+
fi
185+
else
186+
if echo "$version_output" | grep -qi "wolfProvider-fips"; then
187+
log_success "wolfProvider-fips is in the version output"
188+
else
189+
handle_error "wolfProvider-fips is not in the version output"
190+
fi
191+
fi
192+
fi
193+
}
194+
195+
# Main verification function
196+
verify_wolfprovider() {
197+
local replace_default="$1"
198+
local fips="$2"
199+
200+
# echo "Replace default value: $replace_default"
201+
# echo "FIPS value: $fips"
202+
203+
echo "--------------------------------"
204+
verify_provider_loaded $replace_default $fips
205+
echo "--------------------------------"
206+
verify_openssl_version $replace_default $fips
207+
echo "--------------------------------"
208+
echo "wolfProvider installed correctly"
209+
210+
return 0
211+
}
212+
213+
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)