summaryrefslogtreecommitdiff
path: root/tests/basic
blob: cb3730daddc27bef1cfddaebbf77f5858d31a959 (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 %1
  22. echo "### removing temp dir..."
  23. rm -rf "$TEMPDIR"
  24. wait
  25. }
  26. ## setup trap
  27. trap cleanup EXIT
  28. ## set up some variables to ensure that we're operating strictly in
  29. ## the tests, not system-wide:
  30. export TESTDIR=$(pwd)
  31. # make temp dir
  32. TEMPDIR="$TESTDIR"/tmp
  33. if [ -e "$TEMPDIR" ] ; then
  34. echo "tempdir '$TEMPDIR' already exists."
  35. exit 1
  36. fi
  37. mkdir "$TEMPDIR"
  38. # Use the local copy of executables first, instead of system ones.
  39. # This should help us test without installing.
  40. export PATH="$TESTDIR"/../src:"$TESTDIR"/../src/keytrans:"$PATH"
  41. export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
  42. export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
  43. export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src
  44. export MONKEYSPHERE_MONKEYSPHERE_USER="$USER"
  45. export MONKEYSPHERE_CHECK_KEYSERVER=false
  46. SSHD_CONFIG="$TEMPDIR"/sshd_config
  47. export SOCKET="$TEMPDIR"/ssh-socket
  48. # copy in admin and testuser home to tmp
  49. echo "### copying admin and testuser homes..."
  50. cp -a "$TESTDIR"/home/admin "$TEMPDIR"/
  51. cp -a "$TESTDIR"/home/testuser "$TEMPDIR"/
  52. cat <<EOF > "$TEMPDIR"/testuser/.ssh/config
  53. UserKnownHostsFile $TEMPDIR/testuser/.ssh/known_hosts
  54. EOF
  55. cat <<EOF > "$TEMPDIR"/testuser/.monkeysphere/monkeysphere.conf
  56. KNOWN_HOSTS=$TEMPDIR/testuser/.ssh/known_hosts
  57. EOF
  58. ### SERVER TESTS
  59. # setup monkeysphere temp gnupghome directories
  60. mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
  61. mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
  62. cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
  63. primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
  64. keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
  65. EOF
  66. # create a new host key
  67. echo "### generating server key..."
  68. # add gpg.conf with quick-random
  69. echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  70. echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
  71. # remove the gpg.conf
  72. rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  73. HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
  74. # certify it with the "Admin's Key".
  75. # (this would normally be done via keyservers)
  76. echo "### certifying server key..."
  77. monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
  78. echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
  79. # FIXME: how can we test publish-key without flooding junk into the
  80. # keyservers?
  81. # add admin as identity certifier for testhost
  82. echo "### adding admin as certifier..."
  83. echo y | monkeysphere-server add-identity-certifier "$TEMPDIR"/admin/.gnupg/pubkey.gpg
  84. # initialize base sshd_config
  85. cp etc/ssh/sshd_config "$SSHD_CONFIG"
  86. # write the sshd_config
  87. cat <<EOF >> "$SSHD_CONFIG"
  88. HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
  89. AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
  90. EOF
  91. # launch test sshd with the new host key.
  92. echo "### starting sshd..."
  93. socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
  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