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 90 91 92 93 94 95
|
#!/bin/sh
#
# Copyright © 2021 Daniel Lenski
#
# This file is part of openconnect.
#
# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# This test uses LD_PRELOAD
PRELOAD=1
srcdir=${srcdir:-.}
top_builddir=${top_builddir:-..}
. `dirname $0`/common.sh
FINGERPRINT="--servercert=pin-sha256:xp3scfzy3rO"
CERT=$certdir/server-cert.pem
KEY=$certdir/server-key.pem
FAKE_TOKEN="--token-mode=totp --token-secret=ABCD"
echo "Testing Juniper auth against fake server ..."
OCSERV=${srcdir}/fake-juniper-server.py
launch_simple_sr_server $ADDRESS 443 $CERT $KEY > /dev/null 2>&1
PID=$!
wait_server $PID
SERVURL="https://$ADDRESS:443"
CLIENT="$OPENCONNECT --protocol=nc $FINGERPRINT -u test --passwd-on-stdin -q"
export LD_PRELOAD=libsocket_wrapper.so
echo -n "frmLogin with username/password"
( echo "test" | $CLIENT $SERVURL --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password/authgroup"
( echo "test" | $CLIENT $SERVURL/?realms=xyz,abc,def --authgroup=abc --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password/token-as-2nd-password"
( echo "test" | $CLIENT $SERVURL/?token_form=frmLogin $FAKE_TOKEN --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password → frmTotpToken"
( echo "test" | $CLIENT $SERVURL/?token_form=frmTotpToken $FAKE_TOKEN --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password → frmDefender → frmConfirmation"
( echo "test" | $CLIENT "$SERVURL/?token_form=frmDefender&confirm=1" $FAKE_TOKEN --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password → frmNextToken"
( echo "test" | $CLIENT $SERVURL/?token_form=frmNextToken $FAKE_TOKEN --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
ok
# --authgroup will now fill in EITHER the role and/or the realm
echo -n "frmLogin with username/password → frmConfirmation → frmSelectRoles"
( echo "test" | $CLIENT "$SERVURL/?confirm=1&roles=foo,bar,baz" --authgroup=bar --cookieonly >/dev/null 2>&1) ||
fail $PID "Could not receive cookie from fake Juniper server"
echo ok
echo -n "frmLogin with username/password, then proceeding to tunnel stage... "
echo "test" | $CLIENT $SERVURL >/dev/null 2>&1
test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
fail $PID "Something went wrong in fake Juniper server (other than the expected rejection of cookie)"
echo ok
cleanup
exit 0
|