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