summaryrefslogtreecommitdiff
path: root/tests/keytrans
blob: 262b6536b1306d7c31c4be73b1cf3a3a28c6671e (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:"$TESTDIR"/../src/keytrans:"$PATH"
  33. export MONKEYSPHERE_SYSDATADIR="$TEMPDIR"
  34. export MONKEYSPHERE_SYSCONFIGDIR="$TEMPDIR"
  35. export MONKEYSPHERE_SYSSHAREDIR="$TESTDIR"/../src/share
  36. export MONKEYSPHERE_MONKEYSPHERE_USER=$(whoami)
  37. export MONKEYSPHERE_CHECK_KEYSERVER=false
  38. export MONKEYSPHERE_LOG_LEVEL=DEBUG
  39. ######################################################################
  40. ### TEST KEYTRANS
  41. echo "##################################################"
  42. echo "### test key conversion..."
  43. export GNUPGHOME="$TEMPDIR"
  44. chmod 700 "$TEMPDIR"
  45. # generate a key
  46. gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
  47. Key-Type: RSA
  48. Key-Length: 1024
  49. Key-Usage: sign
  50. Name-Real: testtest
  51. Expire-Date: 0
  52. %commit
  53. %echo done
  54. EOF
  55. # get the the key timestamp
  56. timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
  57. grep ^pub: | cut -d: -f6)
  58. # export the key to a file
  59. gpg --export-secret-key | openpgp2ssh > \
  60. "$TEMPDIR"/test.pem
  61. # reconvert key, and compare to key in gpg keyring
  62. diff -u \
  63. <(gpg --export-secret-key | hd) \
  64. <(PEM2OPENPGP_USAGE_FLAGS=sign,certify \
  65. PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest < \
  66. "$TEMPDIR"/test.pem | hd )
  67. # clear out the temp dir
  68. rm -rf "$TEMPDIR"
  69. mkdir -p "$TEMPDIR"