@@ -95,14 +95,45 @@ clone_openssl() {
9595 fi
9696}
9797
98+ check_openssl_replace_default_mismatch () {
99+ # Only check if OpenSSL is already installed
100+ if [ -d " ${OPENSSL_INSTALL_DIR} " ]; then
101+ local openssl_is_patched=0
102+
103+ # Check if the source was patched for --replace-default
104+ if [ -f " ${OPENSSL_SOURCE_DIR} /crypto/provider_predefined.c" ]; then
105+ if grep -q " wolfprov_provider_init" " ${OPENSSL_SOURCE_DIR} /crypto/provider_predefined.c" 2> /dev/null; then
106+ openssl_is_patched=1
107+ fi
108+ fi
109+
110+ # Check for mismatch
111+ if [ " $WOLFPROV_REPLACE_DEFAULT " = " 1" ] && [ " $openssl_is_patched " = " 0" ]; then
112+ printf " ERROR: --replace-default build mode mismatch!\n"
113+ printf " Existing OpenSSL was built WITHOUT --replace-default patch\n"
114+ printf " Current request: --replace-default build\n\n"
115+ printf " Fix: ./scripts/build-wolfprovider.sh --distclean\n"
116+ printf " Then rebuild with desired configuration.\n"
117+ exit 1
118+ elif [ " $WOLFPROV_REPLACE_DEFAULT " != " 1" ] && [ " $openssl_is_patched " = " 1" ]; then
119+ printf " ERROR: Standard build mode mismatch!\n"
120+ printf " Existing OpenSSL was built WITH --replace-default patch\n"
121+ printf " Current request: standard build\n\n"
122+ printf " Fix: ./scripts/build-wolfprovider.sh --distclean\n"
123+ printf " Then rebuild with desired configuration.\n"
124+ exit 1
125+ fi
126+ fi
127+ }
128+
98129patch_openssl () {
99130 if [ " $WOLFPROV_REPLACE_DEFAULT " = " 1" ]; then
100131 printf " \tApplying OpenSSL default provider patch ... "
101132 cd ${OPENSSL_SOURCE_DIR}
102133
103134 # Check if patch is already applied
104135 if grep -q " wolfprov_provider_init" crypto/provider_predefined.c 2> /dev/null; then
105- printf " Already applied.\n"
136+ printf " Already applied.\n"
106137 return 0
107138 fi
108139
@@ -124,6 +155,7 @@ patch_openssl() {
124155install_openssl () {
125156 printf " \nInstalling OpenSSL ${OPENSSL_TAG} ...\n"
126157 clone_openssl
158+ check_openssl_replace_default_mismatch
127159 patch_openssl
128160 cd ${OPENSSL_SOURCE_DIR}
129161
0 commit comments