fortinet-auth-and-config 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. echo "Testing Fortinet auth against fake server ..."
  28. OCSERV=${srcdir}/fake-fortinet-server.py
  29. launch_simple_sr_server $ADDRESS 443 $CERT $KEY > /dev/null 2>&1
  30. PID=$!
  31. wait_server $PID
  32. echo -n "Authenticating with username/password and DEFAULT realm... "
  33. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443 -u test $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  34. fail $PID "Could not receive cookie from fake Fortinet server"
  35. echo ok
  36. echo -n "Authenticating with username/password and NON-DEFAULT path... "
  37. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/fakeRealm -u test $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  38. fail $PID "Could not receive cookie from fake Fortinet server"
  39. echo ok
  40. echo -n "Authenticating with username/password/tokeninfo-2FA and DEFAULT path... "
  41. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/?want_2fa=1 -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  42. fail $PID "Could not receive cookie from fake Fortinet server"
  43. echo ok
  44. echo -n "Authenticating with username/password/HTML-2FA and DEFAULT path... "
  45. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q "$ADDRESS:443/?want_2fa=1&type_2fa=html" -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  46. fail $PID "Could not receive cookie from fake Fortinet server"
  47. echo ok
  48. echo -n "Authenticating with username/password/(2 rounds of tokeninfo-2FA) and DEFAULT path... "
  49. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/?want_2fa=2 -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --cookieonly >/dev/null 2>&1) ||
  50. fail $PID "Could not receive cookie from fake Fortinet server"
  51. echo ok
  52. echo -n "Authenticating with username/password/tokeninfo-2FA and NON-DEFAULT path... "
  53. ( echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443/fake+Realm?want_2fa=1 -u test --token-mode=totp --token-secret=FAKE $FINGERPRINT --pfs --cookieonly >/dev/null 2>&1) ||
  54. fail $PID "Could not receive cookie from fake Fortinet server"
  55. echo ok
  56. echo -n "Authenticating with username/password, then proceeding to tunnel stage... "
  57. echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT --protocol=fortinet -q $ADDRESS:443 -u test $FINGERPRINT >/dev/null 2>&1
  58. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  59. fail $PID "Something went wrong in fake Fortinet server (other than the expected rejection of cookie)"
  60. echo ok
  61. cleanup
  62. exit 0