Skip to content

Commit 3754b1a

Browse files
committed
Unify script code
1 parent d0e67ce commit 3754b1a

File tree

11 files changed

+117
-189
lines changed

11 files changed

+117
-189
lines changed

.github/workflows/cmdline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ jobs:
3535
3636
- name: Run tests
3737
run: |
38+
source $GITHUB_WORKSPACE/scripts/env-setup
3839
${{ matrix.force_fail }} ${{ matrix.debug }} ./scripts/cmd_test/do-cmd-tests.sh

.github/workflows/debian-package.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,11 @@ jobs:
8282
${{ matrix.fips_ref == 'FIPS' && '--fips' || '' }}
8383
8484
- name: Test OpenSSL provider functionality
85+
shell: bash
8586
run: |
86-
WOLFPROV_CONF_BACKUP="/tmp/wolfprovider.conf.backup"
87-
88-
# Temporarily move wolfprovider config so we can toggle between providers
89-
echo "Temporarily disabling wolfprovider for default provider tests:"
90-
mkdir -p /tmp/openssl-test
91-
if [ -f $WOLFPROV_CONF_FILE ]; then
92-
mv $WOLFPROV_CONF_FILE $WOLFPROV_CONF_BACKUP
93-
echo " - Moved $WOLFPROV_CONF_FILE to $WOLFPROV_CONF_BACKUP"
94-
else
95-
echo "$WOLFPROV_CONF_FILE not found!"
96-
exit 1
97-
fi
98-
9987
# Run the do-cmd-test.sh script to execute interoperability tests
10088
echo "Running OpenSSL provider interoperability tests..."
10189
OPENSSL_BIN=$(eval which openssl) ${{ matrix.force_fail }} ${{ matrix.fips_ref == 'FIPS' && 'WOLFSSL_ISFIPS=1' || '' }} ./scripts/cmd_test/do-cmd-tests.sh
102-
103-
# Restore wolfprovider configuration
104-
echo "Restoring wolfprovider configuration:"
105-
if [ -f $WOLFPROV_CONF_BACKUP ]; then
106-
mv $WOLFPROV_CONF_BACKUP $WOLFPROV_CONF_FILE
107-
echo " - Restored $WOLFPROV_CONF_FILE from $WOLFPROV_CONF_BACKUP"
108-
fi
109-
11090
echo "PASS: All provider interoperability tests successful"
11191
11292
- name: Uninstall package and verify cleanup

scripts/cmd_test/aes-cmd-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23-
source "${SCRIPT_DIR}/cmd-test-common.sh"
24-
source "${SCRIPT_DIR}/clean-cmd-test.sh"
22+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
24+
source "${CMD_TEST_DIR}/clean-cmd-test.sh"
2525

2626
if [ -z "${DO_CMD_TESTS:-}" ]; then
2727
echo "This script is designed to be called from do-cmd-tests.sh"

scripts/cmd_test/cmd-test-common.sh

Lines changed: 39 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -19,63 +19,15 @@
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

2623
if [ -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
3027
fi
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
8133
cmd_test_env_setup() {
@@ -96,10 +48,10 @@ cmd_test_env_setup() {
9648
# Individual test setup (called by each test script)
9749
cmd_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
11467
use_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
160105
use_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
200148
check_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

scripts/cmd_test/do-cmd-tests.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

2222
# Get the directory where this script is located
23-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
24-
REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
23+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
24+
REPO_ROOT="$( cd "${CMD_TEST_DIR}/../.." &> /dev/null && pwd )"
2525
UTILS_DIR="${REPO_ROOT}/scripts"
2626

2727
# Flag to indicate that this script is being called from do-cmd-tests.sh
@@ -110,7 +110,7 @@ if [ $RUN_ALL -eq 1 ]; then
110110
RUN_REQ=1
111111
fi
112112

113-
source "${SCRIPT_DIR}/cmd-test-common.sh"
113+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
114114
cmd_test_env_setup
115115

116116
echo "==========================================
@@ -120,9 +120,6 @@ echo ""
120120
echo "Running command-line test suite..."
121121
echo ""
122122

123-
# Detect installation mode and setup environment
124-
cmd_test_env_setup
125-
126123
echo ""
127124
echo "=== Running wolfProvider Command-Line Tests ==="
128125
echo "Using OPENSSL_BIN: ${OPENSSL_BIN}"

scripts/cmd_test/ecc-cmd-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23-
source "${SCRIPT_DIR}/cmd-test-common.sh"
24-
source "${SCRIPT_DIR}/clean-cmd-test.sh"
22+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
24+
source "${CMD_TEST_DIR}/clean-cmd-test.sh"
2525

2626
if [ -z "${DO_CMD_TESTS:-}" ]; then
2727
echo "This script is designed to be called from do-cmd-tests.sh"

scripts/cmd_test/hash-cmd-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23-
source "${SCRIPT_DIR}/cmd-test-common.sh"
24-
source "${SCRIPT_DIR}/clean-cmd-test.sh"
22+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
24+
source "${CMD_TEST_DIR}/clean-cmd-test.sh"
2525

2626
if [ -z "${DO_CMD_TESTS:-}" ]; then
2727
echo "This script is designed to be called from do-cmd-tests.sh"

scripts/cmd_test/req-cmd-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23-
source "${SCRIPT_DIR}/cmd-test-common.sh"
24-
source "${SCRIPT_DIR}/clean-cmd-test.sh"
22+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
24+
source "${CMD_TEST_DIR}/clean-cmd-test.sh"
2525

2626
if [ -z "${DO_CMD_TESTS:-}" ]; then
2727
echo "This script is designed to be called from do-cmd-tests.sh"

scripts/cmd_test/rsa-cmd-test.sh

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
2121

22-
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23-
source "${SCRIPT_DIR}/cmd-test-common.sh"
24-
source "${SCRIPT_DIR}/clean-cmd-test.sh"
22+
CMD_TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
23+
source "${CMD_TEST_DIR}/cmd-test-common.sh"
24+
source "${CMD_TEST_DIR}/clean-cmd-test.sh"
2525
cmd_test_init "rsa-test.log"
2626
clean_cmd_test "rsa"
2727

@@ -42,19 +42,6 @@ PROVIDER_ARGS=("-provider-path $WOLFPROV_PATH -provider libwolfprov" "-provider
4242

4343
OPENSSL_BIN=${OPENSSL_BIN:-openssl}
4444

45-
rsa_check_force_fail() {
46-
local openssl_providers=$($OPENSSL_BIN list -providers)
47-
is_openssl_default_provider=$(echo "$openssl_providers" | grep -qi "OpenSSL Default Provider" && echo 1 || echo 0)
48-
if [ $is_openssl_default_provider -eq 1 ]; then
49-
# With the OpenSSL provider, don't expect failures
50-
echo "OPENSSL Default provider active, no forced failures expected."
51-
elif [ "${WOLFPROV_FORCE_FAIL}" = "1" ]; then
52-
echo "[PASS] Test passed when force fail was enabled"
53-
FORCE_FAIL_PASSED=1
54-
exit 1
55-
fi
56-
}
57-
5845
# Function to validate key
5946
validate_key() {
6047
local key_type=$1

0 commit comments

Comments
 (0)