summaryrefslogtreecommitdiff
path: root/tests/basic
blob: e97f998fc6f14fac2d5ea48776426d92e51032ad (plain)
  1. #!/usr/bin/env bash
  2. # Tests to ensure that the monkeysphere is working
  3. # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  4. # Date: 2008-09-13 13:40:15-0400
  5. # these tests might be best run under fakeroot, particularly the
  6. # "server-side" tests. Using fakeroot, they should be able to be run
  7. # as a non-privileged user.
  8. # NOTE: these tests have *not* themselves been tested yet
  9. # (2008-09-13). Please exercise with caution!
  10. # fail on fail
  11. set -e
  12. # gpg command for test admin user
  13. gpgadmin() {
  14. GNUPGHOME="$TEMPDIR"/admin/.gnupg gpg "$@"
  15. }
  16. # cleanup:
  17. cleanup() {
  18. echo
  19. read -p "press enter to cleanup and remove tmp:"
  20. echo "### stop sshd..."
  21. kill "$SSHD_PID"
  22. echo "### removing temp dir..."
  23. rm -rf "$TEMPDIR"
  24. }
  25. ## setup trap
  26. trap cleanup EXIT
  27. ## set up some variables to ensure that we're operating strictly in
  28. ## the tests, not system-wide:
  29. export TESTDIR=$(pwd)
  30. # make temp dir
  31. TEMPDIR="$TESTDIR"/tmp
  32. if [ -e "$TEMPDIR" ] ; then
  33. echo "tempdir '$TEMPDIR' already exists."
  34. exit 1
  35. fi
  36. mkdir "$TEMPDIR"
  37. # Use the local copy of executables first, instead of system ones.
  38. # This should help us test without installing.
  39. export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
  40. export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
  41. export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
  42. export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
  43. export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
  44. export MONKEYSPHERE_CHECK_KEYSERVER=false
  45. SSHD_CONFIG="$TEMPDIR"/sshd_config
  46. export SOCKET="$TEMPDIR"/ssh-socket
  47. # copy in admin and testuser home to tmp
  48. echo "### copying admin and testuser homes..."
  49. cp -r "$TESTDIR"/home/admin "$TEMPDIR"/
  50. cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
  51. ### SERVER TESTS
  52. # setup monkeysphere temp gnupghome directories
  53. mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
  54. mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
  55. cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
  56. primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
  57. keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
  58. EOF
  59. # create a new host key
  60. echo "### generating server key..."
  61. # add gpg.conf with quick-random
  62. echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  63. echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
  64. # remove the gpg.conf
  65. rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  66. HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
  67. # certify it with the "Admin's Key".
  68. # (this would normally be done via keyservers)
  69. echo "### certifying server key..."
  70. monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
  71. echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
  72. # FIXME: how can we test publish-key without flooding junk into the
  73. # keyservers?
  74. # add admin as identity certifier for testhost
  75. echo "### adding admin as certifier..."
  76. echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
  77. # initialize base sshd_config
  78. cp etc/ssh/sshd_config "$SSHD_CONFIG"
  79. # write the sshd_config
  80. cat <<EOF >> "$SSHD_CONFIG"
  81. HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
  82. AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
  83. EOF
  84. # launch test sshd with the new host key.
  85. echo "### starting sshd..."
  86. socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
  87. export SSHD_PID=$!
  88. ### TESTUSER TESTS
  89. # generate an auth subkey for the test user
  90. echo "### generating key for testuser..."
  91. MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
  92. monkeysphere gen-subkey --expire 0
  93. # add server key to testuser keychain
  94. echo "### export server key to testuser..."
  95. gpgadmin --armor --export "$HOSTKEYID" | \
  96. GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
  97. # connect to test sshd, using monkeysphere to verify the identity
  98. # before connection.
  99. echo "### testuser connecting to sshd socket..."
  100. PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
  101. GNUPGHOME="$TEMPDIR"/testuser/.gnupg ssh -oProxyCommand="$PROXY_COMMAND" testhost
  102. # create a new client side key, certify it with the "CA", use it to
  103. # log in.
  104. ## FIXME: implement!