|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SCRIPTS_DIR="$GITHUB_WORKSPACE/.github/scripts/x11vnc" |
| 4 | + |
| 5 | +killall x11vnc > /dev/null 2> /dev/null |
| 6 | +killall Xvfb > /dev/null 2> /dev/null |
| 7 | + |
| 8 | +X11VNC_TEST_FAIL=0 |
| 9 | + |
| 10 | + |
| 11 | +# CA / cert generation |
| 12 | + |
| 13 | + |
| 14 | +echo -e "\n\nTesting -sslGenCA\n" > x11vnc_test.log |
| 15 | + |
| 16 | +$SCRIPTS_DIR/x11vnc_sslgenca.exp >> x11vnc_test.log 2>> x11vnc_test.log |
| 17 | + |
| 18 | +if [ $? -eq 0 ] && [ -f "ca-dir/CA/cacert.pem" ] && [ -f "ca-dir/CA/private/cakey.pem" ] |
| 19 | +then |
| 20 | + echo "[ PASSED ] -sslGenCA" |
| 21 | +else |
| 22 | + echo "[ FAILED ] -sslGenCA" |
| 23 | + X11VNC_TEST_FAIL=1 |
| 24 | +fi |
| 25 | + |
| 26 | + |
| 27 | +echo -e "\n\nTesting -sslGenCert client\n" >> x11vnc_test.log |
| 28 | + |
| 29 | +$SCRIPTS_DIR/x11vnc_sslgencert_client.exp >> x11vnc_test.log 2>> x11vnc_test.log |
| 30 | + |
| 31 | +if [ $? -eq 0 ] && [ -f "ca-dir/clients/wolf.pem" ] && [ -f "ca-dir/clients/wolf.crt" ] |
| 32 | +then |
| 33 | + echo "[ PASSED ] -sslGenCert client" |
| 34 | +else |
| 35 | + echo "[ FAILED ] -sslGenCert client" |
| 36 | + X11VNC_TEST_FAIL=1 |
| 37 | +fi |
| 38 | + |
| 39 | + |
| 40 | +echo -e "\n\nTesting -sslGenCert server\n" >> x11vnc_test.log |
| 41 | + |
| 42 | +$SCRIPTS_DIR/x11vnc_sslgencert_server.exp >> x11vnc_test.log 2>> x11vnc_test.log |
| 43 | + |
| 44 | +if [ $? -eq 0 ] && [ -f "ca-dir/server-wolf.pem" ] && [ -f "ca-dir/server-wolf.crt" ] |
| 45 | +then |
| 46 | + echo "[ PASSED ] -sslGenCert server" |
| 47 | +else |
| 48 | + echo "[ FAILED ] -sslGenCert server" |
| 49 | + X11VNC_TEST_FAIL=1 |
| 50 | +fi |
| 51 | + |
| 52 | + |
| 53 | +echo -e "\n\nTesting -sslCertInfo\n" >> x11vnc_test.log |
| 54 | + |
| 55 | +OPENSSL_CONF='' OPENSSL_MODULES='' timeout 1 x11vnc -sslCertInfo ca-dir/server-wolf.pem > cert_info_ossl.txt |
| 56 | +timeout 1 x11vnc -sslCertInfo ca-dir/server-wolf.pem > cert_info.txt |
| 57 | + |
| 58 | +if [ $? -eq 0 ] && diff -y cert_info.txt cert_info_ossl.txt >> x11vnc_test.log 2>> x11vnc_test.log \ |
| 59 | + && cat cert_info.txt >> x11vnc_test.log |
| 60 | +then |
| 61 | + echo "[ PASSED ] -sslCertInfo" |
| 62 | +else |
| 63 | + echo "[ FAILED ] -sslCertInfo" |
| 64 | + X11VNC_TEST_FAIL=1 |
| 65 | +fi |
| 66 | + |
| 67 | + |
| 68 | +echo -e "\n\nTesting -sslEncKey\n" >> x11vnc_test.log |
| 69 | + |
| 70 | +$SCRIPTS_DIR/x11vnc_sslenckey.exp >> x11vnc_test.log 2>> x11vnc_test.log |
| 71 | + |
| 72 | +if [ $? -eq 0 ] && grep -q "BEGIN ENCRYPTED PRIVATE KEY" ca-dir/server-wolf.pem |
| 73 | +then |
| 74 | + echo "[ PASSED ] -sslEncKey" |
| 75 | +else |
| 76 | + echo "[ FAILED ] -sslEncKey" |
| 77 | + X11VNC_TEST_FAIL=1 |
| 78 | +fi |
| 79 | + |
| 80 | + |
| 81 | +# SSL |
| 82 | + |
| 83 | + |
| 84 | +# Setup Xvfb, which is a purely virtual display, i.e., humans cannot see it |
| 85 | +# but it works the same as any other X server |
| 86 | +Xvfb :0 -screen 0 100x100x8 2>> x11vnc_test.log & |
| 87 | +sleep 2 |
| 88 | + |
| 89 | + |
| 90 | +# Testing with SSL will use the TLSNone security type |
| 91 | +echo -e "\n\nTesting -ssl handshake, authentication, initialization...\n" >> x11vnc_test.log |
| 92 | + |
| 93 | +PORT=`x11vnc -ssl TMP -display :0 -localhost -bg -o server.log` |
| 94 | +PORT=`echo "$PORT" | grep -m 1 "PORT=" | sed -e 's/PORT=//'` |
| 95 | + |
| 96 | +timeout 10 vncviewer -GnuTLSPriority=LEGACY -DesktopSize=0 -display :0 -log *:stderr:100 localhost::$PORT 2> client.log |
| 97 | + |
| 98 | +if grep -Eq "SSL: handshake with helper process[[0-9]+] succeeded" server.log \ |
| 99 | + && grep -q "CConnection: Authentication success" client.log \ |
| 100 | + && grep -q "CConnection: initialisation done" client.log |
| 101 | +then |
| 102 | + echo "[ PASSED ] -ssl handshake, authentication, initialization" |
| 103 | +else |
| 104 | + echo "[ FAILED ] -ssl handshake, authentication, initialization" |
| 105 | + X11VNC_TEST_FAIL=1 |
| 106 | +fi |
| 107 | +killall x11vnc > /dev/null 2> /dev/null |
| 108 | +cat server.log client.log >> x11vnc_test.log |
| 109 | + |
| 110 | + |
| 111 | +# Testing with a password changes the security type from TLSNone to TLSVnc |
| 112 | +echo -e "\n\nTesting -ssl with a password...\n" >> x11vnc_test.log |
| 113 | + |
| 114 | +x11vnc -storepasswd wolfprov passwd 2>> x11vnc_test.log |
| 115 | + |
| 116 | +PORT=`x11vnc -ssl TMP -display :0 -localhost -bg -o server.log -rfbauth passwd` |
| 117 | +PORT=`echo "$PORT" | grep -m 1 "PORT=" | sed -e 's/PORT=//'` |
| 118 | + |
| 119 | +timeout 10 vncviewer -GnuTLSPriority=LEGACY -DesktopSize=0 -display :0 -passwd passwd -log *:stderr:100 localhost::$PORT 2> client.log |
| 120 | + |
| 121 | +if grep -Eq "SSL: handshake with helper process[[0-9]+] succeeded" server.log \ |
| 122 | + && grep -q "CConnection: Authentication success" client.log \ |
| 123 | + && grep -q "CConnection: initialisation done" client.log |
| 124 | +then |
| 125 | + echo "[ PASSED ] -ssl with a password" |
| 126 | +else |
| 127 | + echo "[ FAILED ] -ssl with a password" |
| 128 | + X11VNC_TEST_FAIL=1 |
| 129 | +fi |
| 130 | +killall x11vnc > /dev/null 2> /dev/null |
| 131 | +cat server.log client.log >> x11vnc_test.log |
| 132 | + |
| 133 | + |
| 134 | +# HTTP HTTPS |
| 135 | + |
| 136 | + |
| 137 | +echo "<html><body>Use WolfSSL!</body></html>" > index.html |
| 138 | + |
| 139 | + |
| 140 | +PORT=`x11vnc -ssl TMP -display :0 -localhost -httpdir . -https 5678 -bg -o server.log` |
| 141 | +PORT=`echo "$PORT" | grep -m 1 -Eo "http://localhost:[0-9]+" server.log | sed -e 's/http:\/\/localhost://'` |
| 142 | + |
| 143 | +echo -e "\n\nTesting -https with http...\n" >> x11vnc_test.log |
| 144 | + |
| 145 | +if OPENSSL_CONF='' OPENSSL_MODULES='' curl -ks "http://localhost:$PORT/index.html" >> x11vnc_test.log |
| 146 | +then |
| 147 | + echo "[ PASSED ] -https with an http request" |
| 148 | +else |
| 149 | + echo "[ FAILED ] -https with an http request" |
| 150 | + X11VNC_TEST_FAIL=1 |
| 151 | +fi |
| 152 | + |
| 153 | + |
| 154 | +echo -e "\n\nTesting -https with https...\n" >> x11vnc_test.log |
| 155 | + |
| 156 | +if OPENSSL_CONF='' OPENSSL_MODULES='' curl -ks "https://localhost:5678/index.html" >> x11vnc_test.log |
| 157 | +then |
| 158 | + echo "[ PASSED ] -https with an https request" |
| 159 | +else |
| 160 | + echo "[ FAILED ] -https with an https request" |
| 161 | + X11VNC_TEST_FAIL=1 |
| 162 | +fi |
| 163 | + |
| 164 | +killall x11vnc > /dev/null 2> /dev/null |
| 165 | +killall Xvfb > /dev/null 2> /dev/null |
| 166 | +cat server.log >> x11vnc_test.log |
| 167 | + |
| 168 | +$GITHUB_WORKSPACE/.github/scripts/check-workflow-result.sh $X11VNC_TEST_FAIL "$WOLFPROV_FORCE_FAIL_STR" x11vnc |
| 169 | +X11VNC_TEST_FAIL=$? |
| 170 | + |
| 171 | +if [[ $X11VNC_TEST_FAIL -eq 1 ]]; then cat x11vnc_test.log; fi |
| 172 | + |
| 173 | +exit $X11VNC_TEST_FAIL |
0 commit comments