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