summaryrefslogtreecommitdiff
path: root/tests/keytrans
blob: ab95f596d91bfe70abf5608c8c054549e2edcb37 (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. # make sure the TESTDIR is an absolute path, not a relative one.
  16. export TESTDIR=$(cd $(dirname "$0") && pwd)
  17. source "$TESTDIR"/common
  18. ## setup trap
  19. trap failed_cleanup EXIT
  20. ######################################################################
  21. ### SETUP VARIABLES
  22. ## set up some variables to ensure that we're operating strictly in
  23. ## the tests, not system-wide:
  24. mkdir -p "$TESTDIR"/tmp
  25. TEMPDIR=$(mktemp -d "${TMPDIR:-$TESTDIR/tmp}/monkeyspheretest.XXXXXXX")
  26. mkdir "$TEMPDIR"/bin
  27. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/openpgp2ssh
  28. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/pem2openpgp
  29. # Use the local copy of executables first, instead of system ones.
  30. # This should help us test without installing.
  31. export PATH="$TEMPDIR"/bin:"$PATH"
  32. ######################################################################
  33. ### TEST KEYTRANS
  34. echo "##################################################"
  35. echo "### generating openpgp key..."
  36. export GNUPGHOME="$TEMPDIR"
  37. chmod 700 "$TEMPDIR"
  38. # create the key with the same preferences that monkeysphere uses.
  39. cat > "$TEMPDIR"/gpg.conf <<EOF
  40. default-preference-list SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1 ZLIB BZIP2 ZIP AES256 AES192 AES CAST5 3DES
  41. cert-digest-algo SHA256
  42. EOF
  43. # generate a key
  44. gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
  45. Key-Type: RSA
  46. Key-Length: 1024
  47. Key-Usage: sign
  48. Name-Real: testtest
  49. Expire-Date: 0
  50. %commit
  51. %echo done
  52. EOF
  53. echo "##################################################"
  54. echo "### retrieving key timestamp..."
  55. timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
  56. grep ^pub: | cut -d: -f6)
  57. echo "##################################################"
  58. echo "### exporting key to ssh file..."
  59. gpg --export-secret-key | openpgp2ssh > \
  60. "$TEMPDIR"/test.pem
  61. gpg --export-secret-key > "$TEMPDIR"/secret.key
  62. PEM2OPENPGP_USAGE_FLAGS=sign,certify \
  63. PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest \
  64. < "$TEMPDIR"/test.pem > "$TEMPDIR"/converted.secret.key
  65. echo "##################################################"
  66. echo "### reconvert key, and compare to key in gpg keyring..."
  67. diff -u \
  68. <(gpg --list-packets < "$TEMPDIR"/secret.key) \
  69. <(gpg --list-packets < "$TEMPDIR"/converted.secret.key)
  70. diff -u \
  71. <(hd "$TEMPDIR"/secret.key) \
  72. <(hd "$TEMPDIR"/converted.secret.key)
  73. trap - EXIT
  74. echo "##################################################"
  75. echo " Monkeysphere keytrans test completed successfully!"
  76. echo "##################################################"
  77. cleanup