auth-swtpm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2016 Red Hat, Inc.
  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. SERV="${SERV:-../src/ocserv}"
  22. srcdir=${srcdir:-.}
  23. top_builddir=${top_builddir:-..}
  24. . `dirname $0`/common.sh
  25. swtpm_list=${swtpm_list:-`echo ${certdir}/swtpm*-key-tpm.pem`}
  26. echo "Testing TPMv2 auth with swtpm..."
  27. launch_simple_sr_server -d 1 -f -c configs/test-user-cert.config
  28. PID=$!
  29. wait_server $PID
  30. mkdir -p ${SOCKDIR}/swtpm
  31. LD_PRELOAD=libsocket_wrapper.so ${SWTPM} socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --tpmstate dir=`pwd`/${SOCKDIR}/swtpm --log file=swtpm-log -d
  32. sleep 0.5
  33. LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 --load permanent ${srcdir}/swtpm-perm.state
  34. LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -i
  35. export TPM_INTERFACE_TYPE=socsim
  36. # We don't actually *require* either of the startup tools
  37. # to be present; we can fall back to killing swtpm and then
  38. # restarting it with the startup-clear option. Sadly, there
  39. # isn't a way for swtpm_ioctl to start it once swtpm is
  40. # running.
  41. #
  42. # We are also inconsistent: the Esys build will automatically
  43. # start the TPM while the IBM TSS build won't. I'd "fix" that
  44. # to make the tests work, but I actually think *not* doing so
  45. # is probably correct.
  46. if ! tsstartup && ! tpm2_startup -T swtpm -c; then
  47. LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
  48. LD_PRELOAD=libsocket_wrapper.so ${SWTPM} socket --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --tpmstate dir=`pwd`/${SOCKDIR}/swtpm --log file=swtpm-log --flags not-need-init,startup-clear -d
  49. fi
  50. for KEY in ${swtpm_list}; do
  51. echo -n "Connecting to obtain cookie (with key ${KEY##*/})... "
  52. if [ "${KEY%%.p12}" != "${KEY}" ]; then
  53. CERTARGS="-c ${KEY} --key-password password"
  54. else
  55. CERT="${KEY%-key-*.pem}-cert.pem"
  56. if [ ! -r "$CERT" ]; then CERT="${certdir}/$CERT"; fi
  57. CERTARGS="--sslkey ${KEY} -c ${CERT}"
  58. fi
  59. if ! echo "test" | LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q $ADDRESS:443 -u test $CERTARGS --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly -vvvvv --passwd-on-stdin; then
  60. LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
  61. fail $PID "Could not connect with key ${KEY##*/}!"
  62. fi
  63. done
  64. echo ok
  65. LD_PRELOAD=libsocket_wrapper.so ${SWTPM_IOCTL} --tcp 127.0.0.1:2322 -s
  66. cleanup
  67. exit 0