vinix-ports / tests / userland / wget.sh
55 lines · 51 sloc · 1.98 KB · f1a25feafde8d98a74839464c4f17045476ccf27
Raw
1#!/bin/sh
2# Exercise the release BusyBox applet and the installed TLS helper inside Vinix.
3set -eu
4export PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/tmp LC_ALL=C
5unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY SSL_CERT_FILE SSL_CERT_DIR
6phase=identity
7server=
8finish() {
9 status=$?
10 if [ -n "$server" ]; then kill "$server" 2>/dev/null || true; fi
11 if [ "$status" -ne 0 ]; then echo "VPAC WGET FAIL at $phase with status $status"; fi
12 /sbin/poweroff -f
13}
14trap finish EXIT
15test "$(uname -o)" = Vinix
16test -x /usr/bin/ssl_client
17mkdir -p /tmp/wget/empty
18cd /tmp/wget
19printf '\n127.0.0.1 vinix.test wrong.test\n' >>/etc/hosts
20printf 'Signed Vinix networking packages\n' >body.txt
21openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 \
22 -subj /CN=vinix.test -addext subjectAltName=DNS:vinix.test -keyout key.pem -out cert.pem
23openssl s_server -accept 127.0.0.1:21443 -cert cert.pem -key key.pem -WWW >server.log 2>&1 &
24server=$!
25
26phase=trusted-peer
27url=https://vinix.test:21443/body.txt
28tries=0
29until SSL_CERT_FILE="$PWD/cert.pem" SSL_CERT_DIR="$PWD/empty" \
30 /bin/busybox wget -T 5 -O received "$url" >client.log 2>&1; do
31 tries=$((tries + 1))
32 if [ "$tries" -ge 5 ]; then cat client.log server.log; exit 1; fi
33 sleep 1
34done
35cmp body.txt received
36
37phase=untrusted-ca
38if /bin/busybox wget -T 5 -O rejected "$url" >client.log 2>&1; then exit 1; fi
39cat client.log
40grep -Eiq 'certificate verify failed|certificate verification failed' client.log
41test ! -s rejected
42
43phase=system-store
44mkdir -p /usr/local/share/ca-certificates
45cp cert.pem /usr/local/share/ca-certificates/vinix-fixture.crt
46update-ca-certificates
47/bin/busybox wget -T 5 -O received "$url"
48cmp body.txt received
49
50phase=wrong-hostname
51if /bin/busybox wget -T 5 -O wrong https://wrong.test:21443/body.txt >client.log 2>&1; then exit 1; fi
52cat client.log
53grep -Eiq 'hostname mismatch|certificate verify failed|certificate verification failed' client.log
54test ! -s wrong
55echo 'VPAC FIXTURE GUEST PASS'
56