2323set -e
2424
2525REPO_ROOT=${GITHUB_WORKSPACE:- $(git rev-parse --show-toplevel)}
26- source ${REPO_ROOT} /scripts/utils-general.sh
2726
2827openssl_clone () {
2928 local debian_version=${1:- bookworm}
@@ -48,9 +47,59 @@ openssl_clone() {
4847 cd $openssl_dir
4948}
5049
51- openssl_build () {
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+
5298 DEBFULLNAME=" ${DEBFULLNAME:- WolfSSL Developer} " DEBEMAIL=" ${DEBEMAIL:- support@ wolfssl.com} " dch -l +wolfprov " Adjust VERSION.dat for custom build"
5399 DEBIAN_FRONTEND=noninteractive EDITOR=true dpkg-source --commit . adjust-version-dat
100+ }
101+
102+ openssl_build () {
54103 DEB_BUILD_OPTIONS=" parallel=$( nproc) nocheck" dpkg-buildpackage -us -uc
55104}
56105
@@ -122,7 +171,7 @@ main() {
122171 exit 0
123172 fi
124173
125- if [ -n " $ output_dir" ]; then
174+ if [ -n " output_dir" ]; then
126175 output_dir=$( realpath $output_dir )
127176 fi
128177
0 commit comments