summaryrefslogtreecommitdiff
path: root/tests/basic
blob: 30c6d17aba096e5e1b136ab0eae123ec5d407c23 (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 -a "$TESTDIR"/home/admin "$TEMPDIR"/
  50. cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
  51. cat <<EOF > "$TEMPDIR"/testuser/.ssh/config
  52. UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
  53. EOF
  54. cat <<EOF > "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
  55. KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
  56. EOF
  57. ### SERVER TESTS
  58. # setup monkeysphere temp gnupghome directories
  59. mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
  60. mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
  61. cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
  62. primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
  63. keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
  64. EOF
  65. # create a new host key
  66. echo "### generating server key..."
  67. # add gpg.conf with quick-random
  68. echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  69. echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
  70. # remove the gpg.conf
  71. rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  72. HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
  73. # certify it with the "Admin's Key".
  74. # (this would normally be done via keyservers)
  75. echo "### certifying server key..."
  76. monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
  77. echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
  78. # FIXME: how can we test publish-key without flooding junk into the
  79. # keyservers?
  80. # add admin as identity certifier for testhost
  81. echo "### adding admin as certifier..."
  82. echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
  83. # initialize base sshd_config
  84. cp etc/ssh/sshd_config "$SSHD_CONFIG"
  85. # write the sshd_config
  86. cat <<EOF >> "$SSHD_CONFIG"
  87. HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
  88. AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
  89. EOF
  90. # launch test sshd with the new host key.
  91. echo "### starting sshd..."
  92. socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
  93. export SSHD_PID=$!
  94. ### TESTUSER TESTS
  95. # generate an auth subkey for the test user
  96. echo "### generating key for testuser..."
  97. MONKEYSPHERE_GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
  98. SSH_ASKPASS=echo \
  99. monkeysphere gen-subkey --expire 0
  100. # add server key to testuser keychain
  101. echo "### export server key to testuser..."
  102. gpgadmin --armor --export "$HOSTKEYID" | \
  103. GNUPGHOME="$TEMPDIR"/testuser/.gnupg gpg --import
  104. # connect to test sshd, using monkeysphere-ssh-proxycommand to verify
  105. # the identity before connection. This should work in both directions!
  106. echo "### testuser connecting to sshd socket..."
  107. PROXY_COMMAND="monkeysphere-ssh-proxycommand --no-connect %h && socat STDIO UNIX:${SOCKET}"
  108. GNUPGHOME="$TEMPDIR"/testuser/.gnupg \
  109. MONKEYSPHERE_HOME="$TEMPDIR"/testuser/.monkeysphere \
  110. ssh -F "$TEMPDIR"/testuser/.ssh/config -v -v -v -oProxyCommand="$PROXY_COMMAND" testhost