juniper-auth 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. #
  3. # Copyright © 2021 Daniel Lenski
  4. #
  5. # This file is part of openconnect.
  6. #
  7. # This is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public License
  9. # as published by the Free Software Foundation; either version 2.1 of
  10. # the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. # This test uses LD_PRELOAD
  20. PRELOAD=1
  21. srcdir=${srcdir:-.}
  22. top_builddir=${top_builddir:-..}
  23. . `dirname $0`/common.sh
  24. FINGERPRINT="--servercert=d66b507ae074d03b02eafca40d35f87dd81049d3"
  25. CERT=$certdir/server-cert.pem
  26. KEY=$certdir/server-key.pem
  27. FAKE_TOKEN="--token-mode=totp --token-secret=ABCD"
  28. echo "Testing Juniper auth against fake server ..."
  29. OCSERV=${srcdir}/fake-juniper-server.py
  30. launch_simple_sr_server $ADDRESS 443 $CERT $KEY > /dev/null 2>&1
  31. PID=$!
  32. wait_server $PID
  33. echo -n "frmLogin with username/password"
  34. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443 -u test $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  35. fail $PID "Could not receive cookie from fake Juniper server"
  36. echo ok
  37. echo -n "frmLogin with username/password/authgroup"
  38. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443/?realms=xyz,abc,def --authgroup=abc -u test $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  39. fail $PID "Could not receive cookie from fake Juniper server"
  40. echo ok
  41. echo -n "frmLogin with username/password/token-as-2nd-password"
  42. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443/?token_form=frmLogin -u test $FAKE_TOKEN $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  43. fail $PID "Could not receive cookie from fake Juniper server"
  44. echo ok
  45. echo -n "frmLogin with username/password → frmTotpToken"
  46. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443/?token_form=frmTotpToken -u test $FAKE_TOKEN $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  47. fail $PID "Could not receive cookie from fake Juniper server"
  48. echo ok
  49. echo -n "frmLogin with username/password → frmDefender → frmConfirmation"
  50. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q "$ADDRESS:443/?token_form=frmDefender&confirm=1" -u test $FAKE_TOKEN $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  51. fail $PID "Could not receive cookie from fake Juniper server"
  52. echo ok
  53. echo -n "frmLogin with username/password → frmNextToken"
  54. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443/?token_form=frmNextToken -u test $FAKE_TOKEN $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  55. fail $PID "Could not receive cookie from fake Juniper server"
  56. ok
  57. # --authgroup will now fill in EITHER the role and/or the realm
  58. echo -n "frmLogin with username/password → frmConfirmation → frmSelectRoles"
  59. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q "$ADDRESS:443/?confirm=1&roles=foo,bar,baz" --authgroup=bar -u test $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  60. fail $PID "Could not receive cookie from fake Juniper server"
  61. echo ok
  62. echo -n "frmLogin with username/password, then proceeding to tunnel stage... "
  63. echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=nc -q $ADDRESS:443 -u test $FINGERPRINT >/dev/null 2>&1
  64. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  65. fail $PID "Something went wrong in fake Juniper server (other than the expected rejection of cookie)"
  66. echo ok
  67. cleanup
  68. exit 0