1919
2020# Global variables to store wolfProvider installation mode
2121# Only initialize if not already set (allows parent script to export values)
22- WOLFPROV_REPLACE_DEFAULT=${WOLFPROV_REPLACE_DEFAULT:- 0}
23- WOLFPROV_FIPS=${WOLFPROV_FIPS:- 0}
24- WOLFPROV_INSTALLED=${WOLFPROV_INSTALLED:- 0}
2522
2623if [ -z " ${DO_CMD_TESTS:- } " ]; then
2724 echo " This script is designed to be called from do-cmd-tests.sh"
2825 echo " Do not run this script directly - use do-cmd-tests.sh instead"
2926 exit 1
3027fi
3128
32- # Function to detect wolfProvider installation mode
33- detect_wolfprovider_mode () {
34- if [ -z " ${REPO_ROOT:- } " ]; then
35- REPO_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " /../.. & > /dev/null && pwd ) "
36- fi
37-
38- # Get OpenSSL version and initial provider info
39- local openssl_version=$( ${OPENSSL_BIN} version 2> /dev/null)
40- local openssl_providers=$( ${OPENSSL_BIN} list -providers 2> /dev/null)
41-
42- # Detect if wolfProvider is currently active
43- if echo " $openssl_providers " | grep -qi " wolfSSL Provider" ; then
44- WOLFPROV_INSTALLED=1
45- echo " Detected: wolfProvider is currently active"
46- else
47- WOLFPROV_INSTALLED=0
48- echo " Detected: wolfProvider is not currently active"
49- fi
50-
51- # Detect if FIPS mode is active
52- if echo " $openssl_providers " | grep -qi " wolfSSL Provider FIPS" ; then
53- WOLFPROV_FIPS=1
54- echo " Detected: wolfProvider FIPS mode"
55- else
56- WOLFPROV_FIPS=0
57- echo " Detected: wolfProvider non-FIPS mode"
58- fi
59-
60- # Detect replace-default mode
61- if echo " $openssl_providers " | grep -q " default" && echo " $openssl_providers " | grep -qi " wolfSSL Provider" ; then
62- WOLFPROV_REPLACE_DEFAULT=1
63- echo " Detected: wolfProvider installed in replace-default mode (provider: default)"
64- elif echo " $openssl_providers " | grep -qi " libwolfprov" ; then
65- WOLFPROV_REPLACE_DEFAULT=0
66- echo " Detected: wolfProvider installed in non-replace-default mode (provider: libwolfprov)"
67- else
68- WOLFPROV_REPLACE_DEFAULT=0
69- echo " Detected: wolfProvider not in replace-default mode"
70- fi
71-
72- # Print detection summary
73- echo " wolfProvider mode detection:"
74- echo " REPLACE_DEFAULT: $WOLFPROV_REPLACE_DEFAULT "
75- echo " FIPS: $WOLFPROV_FIPS "
76- echo " INSTALLED: $WOLFPROV_INSTALLED "
77- }
78-
29+ CMD_TEST_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
30+ source " ${CMD_TEST_DIR} /../utils-general.sh"
7931
8032# Function to setup the environment for the command-line tests
8133cmd_test_env_setup () {
@@ -96,10 +48,10 @@ cmd_test_env_setup() {
9648# Individual test setup (called by each test script)
9749cmd_test_init () {
9850 local log_file_name=$1
99- SCRIPT_DIR =" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
51+ CMD_TEST_DIR =" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
10052
10153 # Set up log file
102- export LOG_FILE=" ${SCRIPT_DIR } /${log_file_name} "
54+ export LOG_FILE=" ${CMD_TEST_DIR } /${log_file_name} "
10355 touch " $LOG_FILE "
10456
10557 # Redirect all output to log file
@@ -110,99 +62,98 @@ cmd_test_init() {
11062 FORCE_FAIL_PASSED=0
11163}
11264
65+
11366# Function to use default provider only
11467use_default_provider () {
11568 unset OPENSSL_MODULES
11669 unset OPENSSL_CONF
70+ if ! declare -F detect_wolfprovider_mode > /dev/null; then
71+ echo " ERROR: detect_wolfprovider_mode function not found"
72+ exit 1
73+ fi
74+
75+ detect_wolfprovider_mode
11776
11877 # Check if wolfProvider is in replace-default mode
119- if [ " $WOLFPROV_REPLACE_DEFAULT " = " 1" ]; then
78+ if [ " $is_openssl_replace_default " = " 1" ]; then
12079 echo " INFO: wolfProvider is installed in replace-default mode"
12180 echo " INFO: wolfProvider IS the default provider and cannot be switched off"
12281
12382 # Verify that wolfProvider (as default) is active
124- local providers=$( ${OPENSSL_BIN} list -providers 2> /dev/null)
125- if echo " $providers " | grep -q " default" && echo " $providers " | grep -qi " wolfSSL Provider" ; then
83+ if [ " $is_wp_active " = " 1" ] && [ " $is_wp_default " = " 1" ]; then
12684 echo " Using default provider (wolfProvider in replace-default mode)"
12785 else
128- echo " FAIL: Expected wolfProvider as default, but provider list doesn't match"
129- echo " Provider list:"
130- echo " $providers "
86+ echo " FAIL: Expected wolfProvider as default, but is_wp_active: $is_wp_active and is_wp_default: $is_wp_default "
13187 exit 1
13288 fi
13389 else
13490 # In non-replace-default mode, unsetting OPENSSL_MODULES should disable wolfProvider
13591 echo " INFO: wolfProvider is installed in non-replace-default mode"
13692
13793 # Verify that we are using the OpenSSL default provider (not wolfProvider)
138- local providers=$( ${OPENSSL_BIN} list -providers 2> /dev/null)
139- if echo " $providers " | grep -qi " libwolfprov" ; then
94+ if [ " $is_openssl_default_provider " != " 1" ]; then
14095 echo " FAIL: unable to switch to default provider, wolfProvider is still active"
141- echo " Provider list:"
142- echo " $providers "
143- exit 1
144- fi
145-
146- # Check if OpenSSL default provider is active
147- if echo " $providers " | grep -q " default" && echo " $providers " | grep -qi " OpenSSL Default Provider" ; then
148- echo " Switched to default provider (OpenSSL)"
149- else
150- echo " FAIL: Expected OpenSSL Default Provider, but provider list doesn't match"
151- echo " Provider list:"
152- echo " $providers "
96+ echo " is_openssl_default_provider: $is_openssl_default_provider "
15397 exit 1
15498 fi
99+ echo " INFO: Switched to default provider (OpenSSL)"
155100 fi
156101}
157102
158103
159104# Function to use wolf provider only
160105use_wolf_provider () {
106+ export OPENSSL_MODULES=$WOLFPROV_PATH
107+ export OPENSSL_CONF=${WOLFPROV_CONFIG}
108+ if ! declare -F detect_wolfprovider_mode > /dev/null; then
109+ echo " ERROR: detect_wolfprovider_mode function not found"
110+ exit 1
111+ fi
112+ detect_wolfprovider_mode
113+
161114 # Check if wolfProvider is in replace-default mode
162- if [ " $WOLFPROV_REPLACE_DEFAULT " = " 1" ]; then
115+ if [ " $is_openssl_replace_default " = " 1" ]; then
163116 # In replace-default mode, wolfProvider is already the default
164117 # No need to set OPENSSL_MODULES or OPENSSL_CONF
165118 echo " INFO: wolfProvider is installed in replace-default mode"
166119 echo " INFO: wolfProvider is already active as the default provider"
167120
168121 # Verify that wolfProvider is active
169- local providers=$( ${OPENSSL_BIN} list -providers 2> /dev/null)
170- if echo " $providers " | grep -qi " wolfSSL Provider" ; then
122+ if [ " $is_wp_active " = " 1" ] && [ " $is_wp_default " = " 1" ]; then
171123 echo " Using wolfProvider (replace-default mode)"
172124 else
173125 echo " FAIL: wolfProvider is not active"
174- echo " Provider list: "
175- echo " $providers "
126+ echo " is_wp_active: $is_wp_active "
127+ echo " is_wp_default: $is_wp_default "
176128 exit 1
177129 fi
178130 else
179131 # In non-replace-default mode, we need to set OPENSSL_MODULES and OPENSSL_CONF
180132 echo " INFO: wolfProvider is installed in non-replace-default mode"
181- export OPENSSL_MODULES=$WOLFPROV_PATH
182- export OPENSSL_CONF=${WOLFPROV_CONFIG}
183133
184134 # Verify that we are using wolfProvider
185- local providers=$( ${OPENSSL_BIN} list -providers 2> /dev/null)
186- if ! echo " $providers " | grep -qi " wolfprov" ; then
135+ if [ " $is_wp_active " != " 1" ]; then
187136 echo " FAIL: unable to switch to wolfProvider, default provider is still active"
188- echo " Provider list:"
189- echo " $providers "
190- echo " OPENSSL_MODULES: $OPENSSL_MODULES "
191- echo " OPENSSL_CONF: $OPENSSL_CONF "
137+ $OPENSSL_BIN list -providers
138+ echo " is_wp_active: $is_wp_active "
139+ echo " is_wp_default: $is_wp_default "
192140 exit 1
193141 fi
194- echo " Switched to wolfProvider"
142+ echo " INFO: Switched to wolfProvider"
195143 fi
196144}
197145
198146
199147# Helper function to handle force fail checks
200148check_force_fail () {
201- if is_default_provider && ! is_replace_default; then
149+ detect_wolfprovider_mode
150+ if [ " $is_openssl_default_provider " = " 1" ]; then
151+ # With the OpenSSL provider, don't expect failures
202152 echo " OPENSSL Default provider active, no forced failures expected."
203- elif [ " ${ WOLFPROV_FORCE_FAIL} " = " 1" ]; then
153+ elif [ " $WOLFPROV_FORCE_FAIL " = " 1" ]; then
204154 echo " [PASS] Test passed when force fail was enabled"
205155 FORCE_FAIL_PASSED=1
156+ exit 1
206157 fi
207158}
208159
0 commit comments