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