forked from wolfSSL/wolfProvider
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv-setup
More file actions
executable file
·89 lines (76 loc) · 3.02 KB
/
env-setup
File metadata and controls
executable file
·89 lines (76 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This file helps to set the environment variables to enable wolfProvider.
# It can be used on the command line, or by workflows.
# 'source' this file, don't run it directly
# To disable wolfProvider, run 'unset OPENSSL_CONF'
# To enable FIPS mode, set WOLFSSL_ISFIPS=1 before sourcing this file
if [[ -n "${ZSH_VERSION:-}" ]]; then
[[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && is_sourced=1 || is_sourced=0
else # bash
[ "$0" = "$BASH_SOURCE" ] && is_sourced=0 || is_sourced=1
fi
if [ $is_sourced -eq 0 ]; then
echo "Error: This script must be sourced, not executed."
exit 1
fi
if [ -n "$BASH_SOURCE" ]; then
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
elif [ -n "$ZSH_VERSION" ]; then
SCRIPT_DIR=$(dirname "${(%):-%x}")
else
echo "Unsupported shell"
exit 1
fi
pushd $SCRIPT_DIR
REPO_ROOT="${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}"
popd
echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "REPO_ROOT: $REPO_ROOT"
echo "PWD: $PWD"
# Detect the openssl library path
if [ -d $REPO_ROOT/openssl-install/lib ]; then
export OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib
elif [ -d $REPO_ROOT/openssl-install/lib64 ]; then
export OPENSSL_LIB_PATH=$REPO_ROOT/openssl-install/lib64
else
echo "Error: Could not find OpenSSL lib directory in $REPO_ROOT/openssl-install"
exit 1
fi
WOLFSSL_LIB_PATH="$REPO_ROOT/wolfssl-install/lib"
WOLFPROV_LIB_PATH="$REPO_ROOT/wolfprov-install/lib"
# Always reconstruct LD_LIBRARY_PATH with correctly detected OPENSSL_LIB_PATH
# (avoids conditional assignment that would skip update if LD_LIBRARY_PATH already set)
export LD_LIBRARY_PATH="$WOLFSSL_LIB_PATH:$OPENSSL_LIB_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
# Auto-detect FIPS mode and use appropriate config
if [ "${WOLFSSL_ISFIPS:-0}" = "1" ]; then
DEFAULT_PROVIDER_CONF="$REPO_ROOT/provider-fips.conf"
echo "FIPS mode detected, using provider-fips.conf"
else
DEFAULT_PROVIDER_CONF="$REPO_ROOT/provider.conf"
fi
export OPENSSL_CONF="${OPENSSL_CONF:=$DEFAULT_PROVIDER_CONF}"
export OPENSSL_MODULES="${OPENSSL_MODULES:=$WOLFPROV_LIB_PATH}"
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:=$OPENSSL_LIB_PATH/pkgconfig}"
# Other variables used by test scripts
export WOLFPROV_PATH="${WOLFPROV_LIB_PATH}"
export WOLFPROV_CONFIG="${DEFAULT_PROVIDER_CONF}"
export OPENSSL_BIN="${REPO_ROOT}/openssl-install/bin/openssl"
# If openssl-install does not exist, exit with failure status to terminate
# any workflows which depend on the result.
# For normal interactive command line usage, this result is fine to ignore.
if [ ! -d "$REPO_ROOT/openssl-install" ]; then
echo "Warning: openssl-install directory does not exist in $REPO_ROOT, cannot confirm providers"
if command -v tree >/dev/null 2>&1; then
tree -L 3 $REPO_ROOT
fi
return 1
fi
echo "Checking OpenSSL providers:"
PROVIDER_LIST=$(mktemp -t provider-list.XXXXXX)
$OPENSSL_BIN list -providers | tee $PROVIDER_LIST
if grep -q libwolfprov $PROVIDER_LIST; then
echo "libwolfprov found in OpenSSL providers"
else
echo "ERROR: libwolfprov not found in OpenSSL providers"
return 1
fi
echo "Done!"