Skip to content

Commit c171250

Browse files
committed
Make OpenSSL version match when building via build-wolfprovider.sh and install-openssl.sh
1 parent e6968a2 commit c171250

File tree

5 files changed

+95
-181
lines changed

5 files changed

+95
-181
lines changed

debian/install-openssl.sh

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
set -e
2424

2525
REPO_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
26+
source ${REPO_ROOT}/scripts/utils-general.sh
2627

2728
openssl_clone() {
2829
local debian_version=${1:-bookworm}
@@ -47,59 +48,9 @@ openssl_clone() {
4748
cd $openssl_dir
4849
}
4950

50-
openssl_patch_version() {
51-
local replace_default=${1:-0}
52-
printf "\tPatching OpenSSL version"
53-
# Patch the OpenSSL version with our BUILD_METADATA
54-
if [ "$replace_default" = "1" ]; then
55-
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-replace-default/g' VERSION.dat
56-
else
57-
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider/g' VERSION.dat
58-
fi
59-
# Patch the OpenSSL RELEASE_DATE field with the current date in the format DD MMM YYYY
60-
sed -i "s/RELEASE_DATE=.*/RELEASE_DATE=$(date '+%d %b %Y')/g" VERSION.dat
61-
}
62-
63-
openssl_is_patched() {
64-
# Return 0 if patched, 1 if not
65-
local file="crypto/provider_predefined.c"
66-
67-
# File must exist to be patched
68-
[[ -f "$file" ]] || return 1
69-
70-
# Any time we see libwolfprov, we're patched
71-
if grep -q 'libwolfprov' -- "$file"; then
72-
return 0
73-
fi
74-
75-
# Not patched
76-
return 1
77-
}
78-
79-
openssl_patch() {
80-
local replace_default=${1:-0}
81-
82-
if openssl_is_patched; then
83-
printf "\tOpenSSL already patched\n"
84-
elif [ "$replace_default" = "1" ]; then
85-
printf "\tApplying OpenSSL default provider patch ... "
86-
87-
# Apply the patch
88-
patch -p1 < ${REPO_ROOT}/patches/openssl3-replace-default.patch
89-
if [ $? != 0 ]; then
90-
printf "ERROR.\n"
91-
printf "\n\nPatch application failed.\n"
92-
exit 1
93-
fi
94-
fi
95-
# Patch the OpenSSL version with our metadata
96-
openssl_patch_version $replace_default
97-
51+
openssl_build() {
9852
DEBFULLNAME="${DEBFULLNAME:-WolfSSL Developer}" DEBEMAIL="${DEBEMAIL:-support@wolfssl.com}" dch -l +wolfprov "Adjust VERSION.dat for custom build"
9953
DEBIAN_FRONTEND=noninteractive EDITOR=true dpkg-source --commit . adjust-version-dat
100-
}
101-
102-
openssl_build() {
10354
DEB_BUILD_OPTIONS="parallel=$(nproc) nocheck" dpkg-buildpackage -us -uc
10455
}
10556

@@ -171,7 +122,7 @@ main() {
171122
exit 0
172123
fi
173124

174-
if [ -n "output_dir" ]; then
125+
if [ -n "$output_dir" ]; then
175126
output_dir=$(realpath $output_dir)
176127
fi
177128

scripts/cmd_test/do-cmd-tests.sh

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,9 @@ REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
2525
UTILS_DIR="${REPO_ROOT}/scripts"
2626

2727
source "${SCRIPT_DIR}/cmd-test-common.sh"
28-
29-
# If OPENSSL_BIN is not set, assume we are using a local build
30-
if [ -z "${OPENSSL_BIN:-}" ]; then
31-
# Check if the install directories exist
32-
if [ ! -d "${REPO_ROOT}/openssl-install" ] ||
33-
[ ! -d "${REPO_ROOT}/wolfssl-install" ]; then
34-
echo "[FAIL] OpenSSL or wolfSSL install directories not found"
35-
echo "Please set OPENSSL_BIN or run build-wolfprovider.sh first"
36-
exit 1
37-
fi
38-
39-
# Setup the environment for a local build
40-
source "${REPO_ROOT}/scripts/env-setup"
41-
else
42-
# We are using a user-provided OpenSSL binary, manually set the test
43-
# environment variables rather than using env-setup.
44-
# Find the location of the wolfProvider modules
45-
if [ -z "${WOLFPROV_PATH:-}" ]; then
46-
export WOLFPROV_PATH=$(find /usr/lib /usr/local/lib -type d -name ossl-modules 2>/dev/null | head -n 1)
47-
fi
48-
# Set the path to the wolfProvider config file
49-
if [ -z "${WOLFPROV_CONFIG:-}" ]; then
50-
if [ "${WOLFSSL_ISFIPS:-0}" = "1" ]; then
51-
export WOLFPROV_CONFIG="${REPO_ROOT}/provider-fips.conf"
52-
else
53-
export WOLFPROV_CONFIG="${REPO_ROOT}/provider.conf"
54-
fi
55-
fi
56-
fi
28+
cmd_test_env_setup
5729

5830
echo "=== Running wolfProvider Command-Line Tests ==="
59-
echo "Using OPENSSL_BIN: ${OPENSSL_BIN}"
60-
echo "Using WOLFPROV_PATH: ${WOLFPROV_PATH}"
61-
echo "Using WOLFPROV_CONFIG: ${WOLFPROV_CONFIG}"
6231

6332
# Ensure we can switch providers before proceeding
6433
use_default_provider

scripts/utils-general.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# the wolfProvider library
44

55
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
REPO_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}
67

78
if [ "$UTILS_GENERAL_LOADED" != "yes" ]; then # only set once
89
kill_servers() {
@@ -27,6 +28,7 @@ if [ "$UTILS_GENERAL_LOADED" != "yes" ]; then # only set once
2728
export UTILS_GENERAL_LOADED=yes
2829
fi
2930

31+
# Check if the current git repository matches the target commit/tag/branch
3032
# Usage: check_git_match <target_ref> [<repo_dir>]
3133
check_git_match() {
3234
local target_ref="$1"
@@ -64,3 +66,69 @@ check_git_match() {
6466
exit 1
6567
fi
6668
}
69+
70+
# Apply patch for OpenSSL version info
71+
openssl_patch_metadata() {
72+
local replace_default=${1:-0}
73+
local openssl_source_dir=${2:-.}
74+
printf "\tPatching OpenSSL version metadata ... "
75+
# Patch the OpenSSL version with our BUILD_METADATA
76+
if [ "$replace_default" = "1" ]; then
77+
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-replace-default/g' $openssl_source_dir/VERSION.dat
78+
else
79+
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider/g' $openssl_source_dir/VERSION.dat
80+
fi
81+
# Patch the OpenSSL RELEASE_DATE field with the current date in the format DD MMM YYYY
82+
sed -i "s/RELEASE_DATE=.*/RELEASE_DATE=\"$(date '+%d %b %Y')\"/g" $openssl_source_dir/VERSION.dat
83+
84+
printf "Done.\n"
85+
}
86+
87+
# Check if replace-default patch is applied
88+
# Return 0 if patched, 1 if not
89+
openssl_is_patched() {
90+
local openssl_source_dir=${1:-.}
91+
local file="$openssl_source_dir/crypto/provider_predefined.c"
92+
local ret=1
93+
94+
# File must exist to be patched
95+
if [[ ! -f "$file" ]]; then
96+
printf "\tOpenSSL source file not found: %s\n" "$file"
97+
elif grep -q 'libwolfprov' -- "$file"; then
98+
# Any time we see libwolfprov, we're patched
99+
ret=0
100+
else
101+
: # Not patched
102+
fi
103+
104+
return $ret
105+
}
106+
107+
# Apply replace-default and version patches
108+
openssl_patch() {
109+
local replace_default=${1:-0}
110+
local openssl_source_dir=${2:-.}
111+
local patch_file="${REPO_ROOT}/patches/openssl3-replace-default.patch"
112+
113+
if openssl_is_patched $openssl_source_dir; then
114+
printf "\tOpenSSL already patched\n"
115+
elif [ "$replace_default" = "1" ]; then
116+
if [ ! -f "${patch_file}" ]; then
117+
printf "ERROR: OpenSSL replace-default patch file not found: ${patch_file}\n"
118+
printf " Looked in directory: $(dirname ${patch_file})\n"
119+
exit 1
120+
fi
121+
122+
printf "\tApplying OpenSSL default provider patch ... "
123+
124+
# Apply the patch
125+
patch -d $openssl_source_dir -p1 < ${patch_file}
126+
if [ $? != 0 ]; then
127+
printf "ERROR.\n"
128+
printf "\n\nPatch application failed.\n"
129+
exit 1
130+
fi
131+
fi
132+
# Patch the OpenSSL version with our metadata
133+
openssl_patch_metadata $replace_default $openssl_source_dir
134+
}

scripts/utils-openssl.sh

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -97,97 +97,24 @@ clone_openssl() {
9797
fi
9898
}
9999

100-
is_openssl_patched() {
101-
# Return 0 if patched, 1 if not
102-
local dir="${OPENSSL_SOURCE_DIR:?OPENSSL_SOURCE_DIR not set}"
103-
local file="${dir%/}/crypto/provider_predefined.c"
104-
105-
# File must exist to be patched
106-
[[ -f "$file" ]] || return 1
107-
108-
# Any time we see libwolfprov, we're patched
109-
if grep -q 'libwolfprov' -- "$file"; then
110-
return 0
111-
fi
112-
113-
# Not patched
114-
return 1
115-
}
116-
117-
patch_openssl_version() {
118-
# Patch the OpenSSL version (wolfProvider/openssl-source/VERSION.dat)
119-
# with our BUILD_METADATA, depending on the FIPS flag. Either "wolfProvider" or "wolfProvider-fips".
120-
if [ ${WOLFSSL_ISFIPS:-0} -eq 1 ]; then
121-
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-fips/g' ${OPENSSL_SOURCE_DIR}/VERSION.dat
122-
else
123-
sed -i 's/BUILD_METADATA=.*/BUILD_METADATA=wolfProvider-nonfips/g' ${OPENSSL_SOURCE_DIR}/VERSION.dat
124-
fi
125-
126-
# Patch the OpenSSL RELEASE_DATE field with the current date in the format DD MMM YYYY
127-
sed -i "s/RELEASE_DATE=.*/RELEASE_DATE=$(date '+%d %b %Y')/g" ${OPENSSL_SOURCE_DIR}/VERSION.dat
128-
}
129-
130-
patch_openssl() {
131-
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ]; then
132-
133-
if [ -d "${OPENSSL_INSTALL_DIR}" ]; then
134-
# If openssl is already installed, patching makes no sense as
135-
# it will not be rebuilt. It may already be built as patched,
136-
# just return and let check_openssl_replace_default_mismatch
137-
# check for the mismatch.
138-
return 0
139-
fi
140-
141-
printf "\tApplying OpenSSL default provider patch ... "
142-
pushd ${OPENSSL_SOURCE_DIR} &> /dev/null
143-
144-
# Check if patch is already applied
145-
if is_openssl_patched; then
146-
printf "Already applied.\n"
147-
popd &> /dev/null
148-
return 0
149-
fi
150-
151-
# Apply the patch
152-
patch -p1 < ${SCRIPT_DIR}/../patches/openssl3-replace-default.patch >>$LOG_FILE 2>&1
153-
if [ $? != 0 ]; then
154-
printf "ERROR.\n"
155-
printf "\n\nPatch application failed. Last 40 lines of log:\n"
156-
tail -n 40 $LOG_FILE
157-
do_cleanup
158-
exit 1
159-
fi
160-
patch_openssl_version
161-
printf "Done.\n"
162-
163-
popd &> /dev/null
164-
else
165-
printf "\tPatching OpenSSL version only ... "
166-
pushd ${OPENSSL_SOURCE_DIR} &> /dev/null
167-
patch_openssl_version
168-
printf "Done.\n"
169-
popd &> /dev/null
170-
fi
171-
}
172-
173100
check_openssl_replace_default_mismatch() {
174-
local openssl_is_patched=0
101+
local is_patched=0
175102

176103
# Check if the source was patched for --replace-default
177-
if is_openssl_patched; then
178-
openssl_is_patched=1
104+
if openssl_is_patched $OPENSSL_SOURCE_DIR; then
105+
is_patched=1
179106
printf "INFO: OpenSSL source modified - wolfProvider integrated as default provider (non-stock build).\n"
180107
fi
181108

182109
# Check for mismatch
183-
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ] && [ "$openssl_is_patched" = "0" ]; then
110+
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ] && [ "$is_patched" = "0" ]; then
184111
printf "ERROR: --replace-default build mode mismatch!\n"
185112
printf "Existing OpenSSL was built WITHOUT --replace-default patch\n"
186113
printf "Current request: --replace-default build\n\n"
187114
printf "Fix: ./scripts/build-wolfprovider.sh --distclean\n"
188115
printf "Then rebuild with desired configuration.\n"
189116
exit 1
190-
elif [ "$WOLFPROV_REPLACE_DEFAULT" != "1" ] && [ "$openssl_is_patched" = "1" ]; then
117+
elif [ "$WOLFPROV_REPLACE_DEFAULT" != "1" ] && [ "$is_patched" = "1" ]; then
191118
printf "ERROR: Standard build mode mismatch!\n"
192119
printf "Existing OpenSSL was built WITH --replace-default patch\n"
193120
printf "Current request: standard build\n\n"
@@ -200,7 +127,7 @@ check_openssl_replace_default_mismatch() {
200127
install_openssl() {
201128
printf "\nInstalling OpenSSL ${OPENSSL_TAG} ...\n"
202129
clone_openssl
203-
patch_openssl
130+
openssl_patch "$WOLFPROV_REPLACE_DEFAULT" "${OPENSSL_SOURCE_DIR}"
204131
check_openssl_replace_default_mismatch
205132

206133
pushd ${OPENSSL_SOURCE_DIR} &> /dev/null

scripts/verify-install.sh

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,18 @@ verify_wolfprovider() {
322322
# version: 1.0.2
323323
# status: active
324324

325-
# When replace-default is 0, expect:
326-
# $ openssl version
325+
# When using base openssl, expect:
326+
# $ openssl version
327327
# OpenSSL 3.0.17 1 Jul 2025 (Library: OpenSSL 3.0.17 1 Jul 2025
328328

329+
# When using wolfProvider's openssl with replace-default 0, expect:
330+
# openssl version
331+
# OpenSSL 3.0.17+wolfProvider 03 Nov 2025 (Library: OpenSSL 3.0.17+wolfProvider 03 Nov 2025)
332+
329333
# When replace-default is 1 and fips is 0, expect:
330-
# $ openssl version
334+
# $ openssl version
331335
# OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025 (Library: OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025)
332336

333-
# When fips is 1, expect:
334-
# $ openssl version
335-
# OpenSSL 3.0.17+wolfProvider-fips 11 Oct 2025 (Library: OpenSSL 3.0.17+wolfProvider-fips 11 Oct 2025)
336-
337337
# When fips is 1, expect:
338338
# $ dpkg -l | grep libwolfssl
339339
# ii libwolfssl 5.8.2+commercial.fips.linuxv5.2.4 amd64 wolfSSL encryption library
@@ -353,8 +353,8 @@ self_test() {
353353

354354
# Mock strings for openssl version
355355
local ver_base="OpenSSL 3.0.17 1 Jul 2025 (Library: OpenSSL 3.0.17 1 Jul 2025)"
356-
local ver_replace_default_nonfips="OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025 (Library: OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025)"
357-
local ver_replace_default_fips="OpenSSL 3.0.17+wolfProvider-fips 11 Oct 2025 (Library: OpenSSL 3.0.17+wolfProvider-fips 11 Oct 2025)"
356+
local ver_wp="OpenSSL 3.0.17+wolfProvider 03 Nov 2025 (Library: OpenSSL 3.0.17+wolfProvider 03 Nov 2025)"
357+
local ver_replace_default="OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025 (Library: OpenSSL 3.0.17+wolfProvider-nonfips 30 Sep 2025)"
358358

359359
# Mock strings for provider listings
360360
read -r -d '' providers_libwolfprov_nonfips <<'EOF'
@@ -458,27 +458,26 @@ EOF
458458

459459
# Positive cases per comment expectations
460460
run_case "pos: replace_default=0,fips=0" 0 0 0 0 ver_base providers_libwolfprov_nonfips dpkg_installed_nonfips
461-
run_case "pos: replace_default=1,fips=0" 0 0 1 0 ver_replace_default_nonfips providers_default_wolf_nonfips dpkg_installed_nonfips
462-
run_case "pos: replace_default=1,fips=1" 0 1 1 0 ver_replace_default_fips providers_default_wolf_fips dpkg_installed_fips
461+
run_case "pos: replace_default=1,fips=0" 0 0 1 0 ver_replace_default providers_default_wolf_nonfips dpkg_installed_nonfips
463462
run_case "pos: replace_default=0,fips=1" 0 1 0 0 ver_base providers_libwolfprov_fips dpkg_installed_fips
464463
# run positive test cases with providers_default_openssl_only
465464
run_case "pos: no_wp true with OpenSSL default, default provider" 0 0 0 1 ver_base providers_default_openssl_only dpkg_installed_nonfips
466-
run_case "pos: no_wp true but wolfProvider active" 1 0 0 1 ver_base providers_libwolfprov_nonfips dpkg_installed_nonfips
465+
run_case "pos: no_wp true but wolfProvider active" 1 0 0 1 ver_wp providers_libwolfprov_nonfips dpkg_installed_nonfips
467466

468467
# Negative cases
469-
run_case "neg: rd=0 but OpenSSL replace-default" 1 0 0 0 ver_replace_default_nonfips providers_libwolfprov_nonfips dpkg_installed_nonfips
468+
run_case "neg: rd=0 but OpenSSL replace-default" 1 0 0 0 ver_replace_default providers_libwolfprov_nonfips dpkg_installed_nonfips
469+
run_case "neg: rd=0 but OpenSSL wp metadata" 1 0 0 0 ver_wp providers_libwolfprov_nonfips dpkg_installed_nonfips
470470
run_case "neg: rd=0 but provider default" 1 0 0 0 ver_base providers_both_default_and_libwolfprov dpkg_installed_nonfips
471471
run_case "neg: rd=0 but no providers listed" 1 0 0 0 ver_base providers_none dpkg_installed_nonfips
472472
run_case "neg: rd=0 missing provider" 1 0 0 0 ver_base providers_default_openssl_only dpkg_installed_nonfips
473-
run_case "neg: rd=1,fips=0 but OpenSSL FIPS" 1 0 1 0 ver_replace_default_fips providers_default_wolf_nonfips dpkg_installed_nonfips
474-
run_case "neg: rd=1,fips=0 but provider FIPS" 1 0 1 0 ver_replace_default_nonfips providers_default_wolf_fips dpkg_installed_nonfips
475-
run_case "neg: rd=1,fips=0 but no providers listed" 1 0 1 0 ver_replace_default_nonfips providers_none dpkg_installed_nonfips
476-
run_case "neg: rd=1,fips=1 but OpenSSL non-FIPS" 1 1 1 0 ver_replace_default_nonfips providers_default_wolf_fips dpkg_installed_fips
473+
run_case "neg: rd=1,fips=0 but provider FIPS" 1 0 1 0 ver_replace_default providers_default_wolf_fips dpkg_installed_nonfips
474+
run_case "neg: rd=1,fips=0 but no providers listed" 1 0 1 0 ver_replace_default providers_none dpkg_installed_nonfips
475+
run_case "neg: rd=1,fips=1 but OpenSSL non-FIPS" 1 1 1 0 ver_replace_default providers_default_wolf_fips dpkg_installed_fips
477476
run_case "neg: fips=1 but wolfSSL non-FIPS" 1 1 0 0 ver_base providers_libwolfprov_fips dpkg_installed_nonfips
478477

479478
# no_wp positive and negative cases
480479
run_case "neg: no_wp true with OpenSSL default, default provider" 1 0 0 1 ver_base providers_none dpkg_installed_nonfips
481-
run_case "neg: no_wp true but wolfProvider active" 1 0 0 1 ver_base providers_libwolfprov_nonfips dpkg_installed_nonfips
480+
run_case "neg: no_wp true but wolfProvider active" 1 0 0 1 ver_wp providers_libwolfprov_nonfips dpkg_installed_nonfips
482481

483482
log_info "self_test results: ${pass_count} passed, ${fail_count} failed"
484483
if [ "$fail_count" -gt 0 ]; then

0 commit comments

Comments
 (0)