summaryrefslogtreecommitdiff
path: root/tests/basic
blob: 83d69209d4265423d5c53048feed1fab56e51698 (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. # these tests assume a commonly-trusted "Admin's key", a fake key
  13. # permanently stored in ./home/admin/.gnupg:
  14. gpgadmin() {
  15. GNUPGHOME="$TESTDIR"/home/admin/.gnupg gpg "$@"
  16. }
  17. # cleanup:
  18. cleanup() {
  19. echo
  20. read -p "press enter to cleanup and remove tmp:"
  21. echo "### stop sshd..."
  22. kill "$SSHD_PID"
  23. echo "### removing temp dir..."
  24. rm -rf "$TEMPDIR"
  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. ### SERVER TESTS
  49. # setup monkeysphere temp gnupghome directories
  50. mkdir -p -m 750 "$MONKEYSPHERE_SYSDATADIR"/gnupg-host
  51. mkdir -p -m 700 "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication
  52. cat <<EOF > "$MONKEYSPHERE_SYSDATADIR"/gnupg-authentication/gpg.conf
  53. primary-keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-authentication/pubring.gpg
  54. keyring ${MONKEYSPHERE_SYSDATADIR}/gnupg-host/pubring.gpg
  55. EOF
  56. # create a new host key
  57. echo "### generating server key..."
  58. # add gpg.conf with quick-random
  59. echo "quick-random" >> "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  60. echo | monkeysphere-server gen-key --length 1024 --expire 0 testhost
  61. # remove the gpg.conf
  62. rm "$MONKEYSPHERE_SYSCONFIGDIR"/gnupg-host/gpg.conf
  63. HOSTKEYID=$( monkeysphere-server show-key | tail -n1 | cut -f3 -d\ )
  64. # certify it with the "Admin's Key".
  65. # (this would normally be done via keyservers)
  66. echo "### certifying server key..."
  67. monkeysphere-server gpg-authentication-cmd "--armor --export $HOSTKEYID" | gpgadmin --import
  68. echo y | gpgadmin --command-fd 0 --sign-key "$HOSTKEYID"
  69. # FIXME: how can we test publish-key without flooding junk into the
  70. # keyservers?
  71. # add admin as identity certifier for testhost
  72. echo "### adding admin as certifier..."
  73. echo y | monkeysphere-server add-identity-certifier "$TESTDIR"/home/admin/.gnupg/pubkey.gpg
  74. # initialize base sshd_config
  75. cp etc/ssh/sshd_config "$SSHD_CONFIG"
  76. # write the sshd_config
  77. cat <<EOF >> "$SSHD_CONFIG"
  78. HostKey ${MONKEYSPHERE_SYSDATADIR}/ssh_host_rsa_key
  79. AuthorizedKeysFile ${MONKEYSPHERE_SYSDATADIR}/authorized_keys/%u
  80. EOF
  81. # launch test sshd with the new host key.
  82. echo "### starting sshd..."
  83. socat EXEC:"/usr/sbin/sshd -f ${SSHD_CONFIG} -i -d -d -d -D -e" "UNIX-LISTEN:${SOCKET}" 2> "$TEMPDIR"/sshd.log &
  84. export SSHD_PID=$!
  85. ### TESTUSER TESTS
  86. # copy testuser home directory into temp dir
  87. echo "### seting up testuser home..."
  88. cp -r "$TESTDIR"/home/testuser "$TEMPDIR"/
  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!