summaryrefslogtreecommitdiff
path: root/tests/keytrans
blob: 285d17bff711a6c998ca18e7aad3353b3b29cca4 (plain)
  1. #!/usr/bin/env bash
  2. # Tests to ensure that the monkeysphere is working
  3. # Authors:
  4. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  5. # Jameson Rollins <jrollins@fifthhorseman.net>
  6. # Micah Anderson <micah@riseup.net>
  7. #
  8. # Copyright: 2008-2009
  9. # License: GPL v3 or later
  10. # these tests should all be able to run as a non-privileged user.
  11. # all subcommands in this script should complete without failure:
  12. set -e
  13. # piped commands should return the code of the first non-zero return
  14. set -o pipefail
  15. export TESTDIR=$(dirname "$0")
  16. source "$TESTDIR"/common
  17. ## setup trap
  18. trap failed_cleanup EXIT
  19. ######################################################################
  20. ### SETUP VARIABLES
  21. ## set up some variables to ensure that we're operating strictly in
  22. ## the tests, not system-wide:
  23. # make temp dir
  24. TEMPDIR="$TESTDIR"/tmp
  25. if [ -e "$TEMPDIR" ] ; then
  26. echo "tempdir '$TEMPDIR' already exists."
  27. exit 1
  28. fi
  29. mkdir -p "$TEMPDIR"
  30. # Use the local copy of executables first, instead of system ones.
  31. # This should help us test without installing.
  32. export PATH="$TESTDIR"/../src/keytrans:"$PATH"
  33. ######################################################################
  34. ### TEST KEYTRANS
  35. echo "##################################################"
  36. echo "### generating openpgp key..."
  37. export GNUPGHOME="$TEMPDIR"
  38. chmod 700 "$TEMPDIR"
  39. # generate a key
  40. gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
  41. Key-Type: RSA
  42. Key-Length: 1024
  43. Key-Usage: sign
  44. Name-Real: testtest
  45. Expire-Date: 0
  46. %commit
  47. %echo done
  48. EOF
  49. echo "##################################################"
  50. echo "### retrieving key timestamp..."
  51. timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
  52. grep ^pub: | cut -d: -f6)
  53. echo "##################################################"
  54. echo "### exporting key to ssh file..."
  55. gpg --export-secret-key | openpgp2ssh > \
  56. "$TEMPDIR"/test.pem
  57. echo "##################################################"
  58. echo "### reconvert key, and compare to key in gpg keyring..."
  59. diff -u \
  60. <(gpg --export-secret-key | hd) \
  61. <(PEM2OPENPGP_USAGE_FLAGS=sign,certify \
  62. PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest < \
  63. "$TEMPDIR"/test.pem | hd )
  64. trap - EXIT
  65. echo "##################################################"
  66. echo " Monkeysphere keytrans test completed successfully!"
  67. echo "##################################################"
  68. cleanup