Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions .github/workflows/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,52 @@ concurrency:

jobs:
make_check:
runs-on: ubuntu-latest
timeout-minutes: 20

strategy:
matrix:
config: [
# Add new configs here
'',
'OPENSSL_TAG=master',
'WOLFSSL_TAG=master',
'OPENSSL_TAG=master WOLFSSL_TAG=master',
]
name: make check
runs-on: ubuntu-latest
# This should be a safe limit for the tests to run.
timeout-minutes: 10
config:
- ''
- 'OPENSSL_TAG=master'
- 'WOLFSSL_TAG=master'
- 'OPENSSL_TAG=master WOLFSSL_TAG=master'
force_fail:
- ''
- 'WOLFPROV_FORCE_FAIL=1'

steps:
- uses: actions/checkout@v4
name: Checkout wolfProvider
name: Checkout repository

- name: Test wolfProvider
- name: Run build and tests
run: |
${{ matrix.config }} ./scripts/build-wolfprovider.sh
# Build first with matrix config
${{ matrix.config }} ${{ matrix.force_fail }} ./scripts/build-wolfprovider.sh || BUILD_RESULT=$?

- name: Print errors
if: ${{ failure() }}
# Run all tests regardless of build result
${{ matrix.force_fail }} ./scripts/cmd_test/do-cmd-tests.sh || TEST_RESULT=$?

# For force_fail, we expect failures (return 1)
if [ -n "${{ matrix.force_fail }}" ]; then
if [ $BUILD_RESULT -eq 0 ] || [ $TEST_RESULT -eq 0 ]; then
echo "Build/Test unexpectedly succeeded with force fail enabled"
exit 1 # failure was not seen when expected
else
echo "Build/Test failed as expected with force fail enabled"
exit 0 # expected failure occurred
fi
else
# Normal case - expect success
if [ $BUILD_RESULT -ne 0 ] || [ $TEST_RESULT -ne 0 ]; then
exit 1 # unexpected failure
fi
fi

- name: Print test logs
if: always()
run: |
if [ -f test-suite.log ] ; then
cat test-suite.log
fi

2 changes: 1 addition & 1 deletion .github/workflows/socat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ jobs:
./socat -V

# Run the tests with expected failures
SOCAT=$GITHUB_WORKSPACE/socat-1.8.0.0/socat ./test.sh -t 0.5 --expect-fail 146,216,309,310,399,467,468,478,491,528
SOCAT=$GITHUB_WORKSPACE/socat-1.8.0.0/socat ./test.sh -t 0.5 --expect-fail 36,64,146,214,216,217,309,310,386,399,402,403,459,460,467,468,475,478,491,492,528,529,530
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,17 @@ make check
## Testing

### Unit Tests
To run automated unit tests:

To run automated unit tests:
* `make test`

### Command Tests

To run the command tests:
* `./scripts/cmd_test/do-cmd-tests.sh`

### Integration Tests

To run the cipher suite testing:
* ./scripts/test-wp-cs.sh
* `./scripts/test-wp-cs.sh`

131 changes: 131 additions & 0 deletions scripts/cmd_test/aes-cmd-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/bash

# Set up environment
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
REPO_ROOT="$( cd "${SCRIPT_DIR}/../.." &> /dev/null && pwd )"
UTILS_DIR="${REPO_ROOT}/scripts"
export LOG_FILE="${SCRIPT_DIR}/aes-test.log"
touch "$LOG_FILE"

# Source wolfProvider utilities
source "${UTILS_DIR}/utils-general.sh"
source "${UTILS_DIR}/utils-openssl.sh"
source "${UTILS_DIR}/utils-wolfssl.sh"
source "${UTILS_DIR}/utils-wolfprovider.sh"

# Initialize the environment
init_wolfprov

# Fail flag
FAIL=0

# Verify wolfProvider is properly loaded
echo -e "\nVerifying wolfProvider configuration:"
if ! $OPENSSL_BIN list -providers | grep -q "wolf"; then
echo "[FAIL] wolfProvider not found in OpenSSL providers!"
echo "Current provider list:"
$OPENSSL_BIN list -providers
FAIL=1
else
echo "[PASS] wolfProvider is properly configured"
fi

# Print environment for verification
echo "Environment variables:"
echo "OPENSSL_MODULES: ${OPENSSL_MODULES}"
echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"
echo "OPENSSL_BIN: ${OPENSSL_BIN}"

# Create test data and output directories
mkdir -p aes_outputs
echo "This is test data for AES encryption testing." > test.txt

# Arrays for test configurations
KEY_SIZES=("128" "192" "256")
# Only include modes supported by wolfProvider
MODES=("ecb" "cbc" "ctr" "cfb")

echo "=== Running AES Algorithm Comparisons ==="

# Run tests for each key size and mode
for key_size in "${KEY_SIZES[@]}"; do
for mode in "${MODES[@]}"; do
echo -e "\n=== Testing AES-${key_size}-${mode} ==="

# Generate random key and IV
key=$($OPENSSL_BIN rand -hex $((key_size/8)))
iv=""
if [ "$mode" != "ecb" ]; then
iv="-iv $($OPENSSL_BIN rand -hex 16)"
fi

# Output files
enc_file="aes_outputs/aes${key_size}_${mode}.enc"
dec_file="aes_outputs/aes${key_size}_${mode}.dec"

# Interop testing: Encrypt with default provider, decrypt with wolfProvider
echo "Interop testing (encrypt with default, decrypt with wolfProvider):"

# Encryption with OpenSSL default provider
if ! $OPENSSL_BIN enc -aes-${key_size}-${mode} -K $key $iv -provider default \
-in test.txt -out "$enc_file" -p; then
echo "[FAIL] Interop AES-${key_size}-${mode}: OpenSSL encrypt failed"
FAIL=1
fi

# Decryption with wolfProvider
if ! $OPENSSL_BIN enc -aes-${key_size}-${mode} -K $key $iv -provider-path $WOLFPROV_PATH -provider libwolfprov \
-in "$enc_file" -out "$dec_file" -d -p; then
echo "[FAIL] Interop AES-${key_size}-${mode}: wolfProvider decrypt failed"
FAIL=1
fi

if [ $FAIL -eq 0 ]; then
if cmp -s "test.txt" "$dec_file"; then
echo "[PASS] Interop AES-${key_size}-${mode}: OpenSSL encrypt, wolfProvider decrypt"
else
echo "[FAIL] Interop AES-${key_size}-${mode}: OpenSSL encrypt, wolfProvider decrypt"
FAIL=1
fi
else
echo "[INFO] Cannot verify encryption/decryption - no key available"
fi

# Interop testing: Encrypt with wolfProvider, decrypt with default provider
echo "Interop testing (encrypt with wolfProvider, decrypt with default):"

# Encryption with wolfProvider
if ! $OPENSSL_BIN enc -aes-${key_size}-${mode} -K $key $iv -provider-path $WOLFPROV_PATH -provider libwolfprov \
-in test.txt -out "$enc_file" -p; then
echo "[FAIL] Interop AES-${key_size}-${mode}: wolfProvider encrypt failed"
FAIL=1
fi

# Decryption with OpenSSL default provider
if ! $OPENSSL_BIN enc -aes-${key_size}-${mode} -K $key $iv -provider default \
-in "$enc_file" -out "$dec_file" -d -p; then
echo "[FAIL] Interop AES-${key_size}-${mode}: OpenSSL decrypt failed"
FAIL=1
fi

if [ $FAIL -eq 0 ]; then
if cmp -s "test.txt" "$dec_file"; then
echo "[PASS] Interop AES-${key_size}-${mode}: wolfProvider encrypt, OpenSSL decrypt"
else
echo "[FAIL] Interop AES-${key_size}-${mode}: wolfProvider encrypt, OpenSSL decrypt"
FAIL=1
fi
else
echo "[INFO] Cannot verify encryption/decryption - no key available"
fi
done
done

# Change end of script to check FAIL flag
if [ $FAIL -eq 0 ]; then
echo -e "\n=== All AES tests completed successfully ==="
exit 0
else
echo -e "\n=== AES tests completed with failures ==="
exit 1
fi
83 changes: 83 additions & 0 deletions scripts/cmd_test/do-cmd-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
# do-cmd-tests.sh
# Run all command-line tests for wolfProvider
#
# Copyright (C) 2006-2024 wolfSSL Inc.
#
# This file is part of wolfProvider.
#
# wolfProvider is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfProvider is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA

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

# Get the built versions
if [ -d "${REPO_ROOT}/openssl-source" ] && [ -d "${REPO_ROOT}/wolfssl-source" ]; then
# Get the actual versions that were built
export OPENSSL_TAG=$(cd ${REPO_ROOT}/openssl-source &&
(git describe --tags 2>/dev/null || git branch --show-current))
export WOLFSSL_TAG=$(cd ${REPO_ROOT}/wolfssl-source &&
(git describe --tags 2>/dev/null || git branch --show-current))
else
echo "[FAIL] OpenSSL or wolfSSL source directories not found"
echo "Please run build-wolfprovider.sh first"
exit 1
fi

# Use the current version tags for testing
export USE_CUR_TAG=1

# Source OpenSSL utilities and initialize OpenSSL
source "${UTILS_DIR}/utils-openssl.sh"
init_openssl

echo "=== Running wolfProvider Command-Line Tests ==="
echo "Using OpenSSL version: ${OPENSSL_TAG}"
echo "Using wolfSSL version: ${WOLFSSL_TAG}"

# Run the hash comparison test
echo -e "\n=== Running Hash Comparison Test ==="
"${REPO_ROOT}/scripts/cmd_test/hash-cmd-test.sh"
HASH_RESULT=$?

# Run the AES comparison test
echo -e "\n=== Running AES Comparison Test ==="
"${REPO_ROOT}/scripts/cmd_test/aes-cmd-test.sh"
AES_RESULT=$?

# Run the RSA key generation test
echo -e "\n=== Running RSA Key Generation Test ==="
"${REPO_ROOT}/scripts/cmd_test/rsa-cmd-test.sh"
RSA_RESULT=$?

# Run the ECC key generation test
echo -e "\n=== Running ECC Key Generation Test ==="
"${REPO_ROOT}/scripts/cmd_test/ecc-cmd-test.sh"
ECC_RESULT=$?

# Check results
if [ $HASH_RESULT -eq 0 ] && [ $AES_RESULT -eq 0 ] && [ $RSA_RESULT -eq 0 ] && [ $ECC_RESULT -eq 0 ]; then
echo -e "\n=== All Command-Line Tests Passed ==="
exit 0
else
echo -e "\n=== Command-Line Tests Failed ==="
echo "Hash Test Result: $HASH_RESULT (0=success)"
echo "AES Test Result: $AES_RESULT (0=success)"
echo "RSA Test Result: $RSA_RESULT (0=success)"
echo "ECC Test Result: $ECC_RESULT (0=success)"
exit 1
fi
Loading