summaryrefslogtreecommitdiff
path: root/tests/keytrans
blob: bad2ae3a15839f8dd27d2245f3bd2fcfce3ac178 (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. mkdir -p "$TESTDIR"/tmp
  24. TEMPDIR=$(mktemp -d "${TMPDIR:-$TESTDIR/tmp}/monkeyspheretest.XXXXXXX")
  25. mkdir "$TEMPDIR"/bin
  26. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/openpgp2ssh
  27. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/pem2openpgp
  28. # Use the local copy of executables first, instead of system ones.
  29. # This should help us test without installing.
  30. export PATH="$TEMPDIR"/bin:"$PATH"
  31. ######################################################################
  32. ### TEST KEYTRANS
  33. echo "##################################################"
  34. echo "### generating openpgp key..."
  35. export GNUPGHOME="$TEMPDIR"
  36. chmod 700 "$TEMPDIR"
  37. # generate a key
  38. gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
  39. Key-Type: RSA
  40. Key-Length: 1024
  41. Key-Usage: sign
  42. Name-Real: testtest
  43. Expire-Date: 0
  44. %commit
  45. %echo done
  46. EOF
  47. echo "##################################################"
  48. echo "### retrieving key timestamp..."
  49. timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
  50. grep ^pub: | cut -d: -f6)
  51. echo "##################################################"
  52. echo "### exporting key to ssh file..."
  53. gpg --export-secret-key | openpgp2ssh > \
  54. "$TEMPDIR"/test.pem
  55. echo "##################################################"
  56. echo "### reconvert key, and compare to key in gpg keyring..."
  57. diff -u \
  58. <(gpg --export-secret-key | hd) \
  59. <(PEM2OPENPGP_USAGE_FLAGS=sign,certify \
  60. PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest < \
  61. "$TEMPDIR"/test.pem | hd )
  62. trap - EXIT
  63. echo "##################################################"
  64. echo " Monkeysphere keytrans test completed successfully!"
  65. echo "##################################################"
  66. cleanup