gp-auth-and-config 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 GlobalProtect auth against fake server ..."
  28. OCSERV=${srcdir}/fake-gp-server.py
  29. launch_simple_sr_server $ADDRESS 443 $CERT $KEY >/dev/null 2>&1
  30. PID=$!
  31. wait_server $PID
  32. SERVURL="https://$ADDRESS:443"
  33. CLIENT="$OPENCONNECT -q --protocol=gp $FINGERPRINT -u test"
  34. export LD_PRELOAD=libsocket_wrapper.so
  35. echo -n "Authenticating with username/password via portal... "
  36. ( echo "test" | $CLIENT $SERVURL/portal --cookieonly >/dev/null 2>&1) ||
  37. fail $PID "Could not receive cookie from fake GlobalProtect server"
  38. echo ok
  39. echo -n "Authenticating with username/password via gateway... "
  40. ( echo "test" | $CLIENT $SERVURL/gateway --cookieonly >/dev/null 2>&1) ||
  41. fail $PID "Could not receive cookie from fake GlobalProtect server"
  42. echo ok
  43. echo "Configuring fake server to present a choice of 3 gateways in the portal."
  44. curl -sk $SERVURL/CONFIGURE -d gateways=foo,bar,baz
  45. echo -n "Authenticating with username/password, and selecting gateway, via portal... "
  46. ( echo "test" | $CLIENT $SERVURL/portal --authgroup=bar --cookieonly >/dev/null 2>&1) ||
  47. fail $PID "Could not receive cookie from fake GlobalProtect server"
  48. echo ok
  49. echo "Configuring fake server to require 2FA-token and to propagate portal authentication to gateway."
  50. curl -sk $SERVURL/CONFIGURE -d portal_2fa=1 -d gw_2fa=1 -d portal_cookie=portal-userauthcookie
  51. echo -n "Authenticating with username/password/2FA-token via portal, then continuing through 2FA-requiring gateway... "
  52. ( echo "test" | $CLIENT $SERVURL/portal --token-mode=totp --token-secret=FAKE --cookieonly >/dev/null 2>&1) ||
  53. fail $PID "Could not receive cookie from fake GlobalProtect server"
  54. echo ok
  55. echo "Configuring fake server to require SAML for portal and gateway authentication, and to propagate portal authentication to gateway."
  56. curl -sk $SERVURL/CONFIGURE -d portal_saml=prelogin-cookie -d gateway_saml=prelogin-cookie -d portal_cookie=portal-userauthcookie
  57. echo -n "Simulating completed SAML to portal, then continuing through SAML-requiring gateway... "
  58. ( echo "prelogin-cookie" | $CLIENT $SERVURL/portal:prelogin-cookie --cookieonly >/dev/null 2>&1) ||
  59. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  60. fail $PID "Something went wrong in fake GlobalProtect server (other than the expected rejection of cookie)"
  61. echo ok
  62. echo "Configuring fake server to require SAML for gateway authentication only."
  63. curl -sk $SERVURL/CONFIGURE -d gateway_saml=prelogin-cookie
  64. echo -n "Simulating completed SAML to gateway... "
  65. ( echo "prelogin-cookie" | $CLIENT $SERVURL/gateway:prelogin-cookie --cookieonly >/dev/null 2>&1) ||
  66. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  67. fail $PID "Something went wrong in fake GlobalProtect server (other than the expected rejection of cookie)"
  68. echo ok
  69. echo "Configuring fake server to require 2FA-token for gateway authentication."
  70. curl -sk $SERVURL/CONFIGURE -d gw_2fa=1
  71. echo -n "Authenticating with username/password via portal, then +token via gateway... "
  72. ( echo "test" | $CLIENT $SERVURL/portal --token-mode=totp --token-secret=FAKE --cookieonly >/dev/null 2>&1) ||
  73. fail $PID "Could not receive cookie from fake GlobalProtect server"
  74. echo ok
  75. echo -n "Authenticating with username/password/token via gateway... "
  76. ( echo "test" | $CLIENT $SERVURL/gateway --token-mode=totp --token-secret=FAKE --cookieonly >/dev/null 2>&1) ||
  77. fail $PID "Could not receive cookie from fake GlobalProtect server"
  78. echo ok
  79. echo "Resetting fake server to default configuration."
  80. curl -sk $SERVURL/CONFIGURE -d ''
  81. echo -n "Authenticating with username/password via portal, then proceeding to tunnel stage... "
  82. echo "test" | $CLIENT $SERVURL/portal >/dev/null 2>&1
  83. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  84. fail $PID "Something went wrong in fake GlobalProtect server (other than the expected rejection of cookie)"
  85. echo ok
  86. echo -n "Authenticating with username/password via portal, then proceeding to tunnel stage (with IPv6 disabled)... "
  87. echo "test" | $CLIENT $SERVURL/portal --disable-ipv6 >/dev/null 2>&1
  88. test $? = 2 || # what OpenConnect returns when server rejects cookie upon tunnel connection, as the fake server does
  89. fail $PID "Something went wrong in fake GlobalProtect server (other than the expected rejection of cookie)"
  90. echo ok
  91. cleanup
  92. exit 0