22set -eo pipefail
33set -x
44
5+ # OpenVPN setup
6+ if ! command -v openvpn > /dev/null 2>&1 ; then
7+ echo " Installing OpenVPN..."
8+ sudo apt-get update
9+ sudo apt-get install -y openvpn
10+ fi
11+
12+ : " ${OVPN_CONF:? OVPN_CONF not set} "
13+
14+ # Strip route-nopull so that server-pushed routes are accepted.
15+ # Keep pull-filter ignore "redirect-gateway" to avoid full traffic redirect.
16+ OVPN_CONF_FIXED=$( echo " $OVPN_CONF " | grep -v ' ^route-nopull$' )
17+ echo " $OVPN_CONF_FIXED " | sudo tee /tmp/openvpn.ovpn > /dev/null
18+
19+ # Kill any previous openvpn instances to avoid duplicate routes / stale tunnels
20+ sudo killall openvpn 2> /dev/null || true
21+ sleep 1
22+
23+ # Remove stale tun0 interface to avoid "File exists" route conflicts
24+ sudo ip link del tun0 2> /dev/null || true
25+ sleep 1
26+
27+ VPN_LOG=/tmp/vpn.log
28+ sudo truncate -s 0 " $VPN_LOG " 2> /dev/null || sudo touch " $VPN_LOG "
29+ sudo chmod 644 " $VPN_LOG "
30+
31+ sudo openvpn --config /tmp/openvpn.ovpn \
32+ --log " $VPN_LOG " \
33+ --daemon
34+
35+ echo " Waiting for VPN connection..."
36+
37+ for _i in {1..30}; do
38+ if grep -q " Initialization Sequence Completed" " $VPN_LOG " ; then
39+ echo " VPN connected"
40+ break
41+ fi
42+ sleep 1
43+ done
44+
45+ if ! grep -q " Initialization Sequence Completed" " $VPN_LOG " ; then
46+ echo " Error: VPN not connected"
47+ cat " $VPN_LOG "
48+ exit 1
49+ fi
50+
51+ echo " VPN logs:"
52+ tail -n 50 " $VPN_LOG "
53+
554# Crypt2pay-only tests (Linux only)
655SCRIPT_DIR=$( cd " $( dirname " $0 " ) " && pwd)
756source " ${SCRIPT_DIR} /../common.sh"
857
58+ REPO_ROOT=$( get_repo_root " $SCRIPT_DIR " )
959init_build_env " $@ "
1060setup_test_logging
1161
@@ -20,10 +70,42 @@ echo "========================================="
2070
2171export HSM_USER_PASSWORD=" ${CRYPT2PAY_PASSWORD:? CRYPT2PAY_PASSWORD not set} "
2272
23- # Note: This script assumes Crypt2pay HSM setup is already configured
24- # Users need to set up the Crypt2pay HSM environment and related variables
73+ # Setup Crypt2pay HSM client tools
74+ if ! source " $REPO_ROOT /.github/reusable_scripts/prepare_crypt2pay.sh" ; then
75+ echo " Warning: Failed to source prepare_crypt2pay.sh with return code $? ."
76+ if [ -f /lib/libpkcs11c2p.so ] && [ -f /etc/c2p/c2p.xml ]; then
77+ echo " Continuing: Crypt2Pay client appears installed despite prepare script self-test failure."
78+ else
79+ echo " Error: Crypt2Pay client setup is incomplete."
80+ exit 1
81+ fi
82+ fi
83+
84+ export C2P_CONF=" ${C2P_CONF:-/ etc/ c2p/ c2p.xml} "
85+
86+ # Extract the C2P HSM host and port from the config
87+ C2P_HOST=$( grep -ioP ' (?<=<ip>)[^<]+' " $C2P_CONF " | head -1)
88+ C2P_PORT=$( grep -ioP ' (?<=<port>)[^<]+' " $C2P_CONF " | head -1)
89+
90+ if [ -n " $C2P_HOST " ] && [ -n " $C2P_PORT " ]; then
91+ echo " Checking HSM connectivity at $C2P_HOST :$C2P_PORT ..."
92+ HSM_REACHABLE=false
93+ for _i in {1..30}; do
94+ if timeout 3 bash -c " echo >/dev/tcp/$C2P_HOST /$C2P_PORT " 2> /dev/null; then
95+ echo " HSM service is reachable"
96+ HSM_REACHABLE=true
97+ break
98+ fi
99+ echo " retry $_i /30 - waiting 2s..."
100+ sleep 2
101+ done
102+ if [ " $HSM_REACHABLE " = false ]; then
103+ echo " Error: HSM service $C2P_HOST :$C2P_PORT is not reachable over the VPN"
104+ exit 1
105+ fi
106+ fi
25107
26- # CRYPT2PAY integration test (KMS)
108+ # CRYPT2PAY integration test (KMS server )
27109env \
28110 PATH=" $PATH " \
29111 HSM_MODEL=" crypt2pay" \
34116 ${FEATURES_FLAG[@]+" ${FEATURES_FLAG[@]} " } \
35117 -- tests::hsm::test_hsm_all --ignored --exact
36118
119+ # CRYPT2PAY PKCS#11 loader test
37120env \
38121 PATH=" $PATH " \
39122 HSM_MODEL=" crypt2pay" \
0 commit comments