summaryrefslogtreecommitdiff
path: root/tests/keytrans
blob: 199db3155f133e0c990fe1e62759c60ebbfc4c5c (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. perl -MCrypt::OpenSSL::RSA -e 1 2>/dev/null || { echo "You must have the perl module Crypt::OpenSSL::RSA installed to run this test.
  19. On debian-derived systems, you can set this up with:
  20. apt-get install libcrypt-openssl-rsa-perl" ; exit 1; }
  21. perl -MDigest::SHA -e 1 2>/dev/null || { echo "You must have the perl module Digest::SHA installed to run this test.
  22. On debian-derived systems, you can set this up with:
  23. apt-get install libdigest-sha1-perl" ; exit 1; }
  24. ######################################################################
  25. ### SETUP VARIABLES
  26. ## set up some variables to ensure that we're operating strictly in
  27. ## the tests, not system-wide:
  28. mkdir -p "$TESTDIR"/tmp
  29. TEMPDIR=$(mktemp -d "${TMPDIR:-$TESTDIR/tmp}/monkeyspheretest.XXXXXXX")
  30. mkdir "$TEMPDIR"/bin
  31. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/openpgp2ssh
  32. ln -s "$TESTDIR"/../src/share/keytrans "$TEMPDIR"/bin/pem2openpgp
  33. # Use the local copy of executables first, instead of system ones.
  34. # This should help us test without installing.
  35. export PATH="$TEMPDIR"/bin:"$PATH"
  36. ## setup trap
  37. trap failed_cleanup EXIT
  38. ######################################################################
  39. ### TEST KEYTRANS
  40. echo "##################################################"
  41. echo "### generating openpgp key..."
  42. export GNUPGHOME="$TEMPDIR"
  43. chmod 700 "$TEMPDIR"
  44. # create the key with the same preferences that monkeysphere uses.
  45. cat > "$TEMPDIR"/gpg.conf <<EOF
  46. default-preference-list SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1 ZLIB BZIP2 ZIP AES256 AES192 AES CAST5 3DES
  47. cert-digest-algo SHA256
  48. EOF
  49. # generate a key
  50. gpg --batch --$(get_gpg_prng_arg) --gen-key <<EOF
  51. Key-Type: RSA
  52. Key-Length: 1024
  53. Key-Usage: sign
  54. Name-Real: testtest
  55. Expire-Date: 0
  56. %commit
  57. %echo done
  58. EOF
  59. echo "##################################################"
  60. echo "### retrieving key timestamp..."
  61. timestamp=$(gpg --list-key --with-colons --fixed-list-mode | \
  62. grep ^pub: | cut -d: -f6)
  63. echo "##################################################"
  64. echo "### exporting key to ssh file..."
  65. gpg --export-secret-key | openpgp2ssh > \
  66. "$TEMPDIR"/test.pem
  67. gpg --export-secret-key > "$TEMPDIR"/secret.key
  68. PEM2OPENPGP_USAGE_FLAGS=sign,certify \
  69. PEM2OPENPGP_TIMESTAMP="$timestamp" pem2openpgp testtest \
  70. < "$TEMPDIR"/test.pem > "$TEMPDIR"/converted.secret.key
  71. echo "##################################################"
  72. echo "### reconvert key, and compare to key in gpg keyring..."
  73. diff -u \
  74. <(gpg --list-packets < "$TEMPDIR"/secret.key) \
  75. <(gpg --list-packets < "$TEMPDIR"/converted.secret.key)
  76. diff -u \
  77. <(hd "$TEMPDIR"/secret.key) \
  78. <(hd "$TEMPDIR"/converted.secret.key)
  79. trap - EXIT
  80. echo "##################################################"
  81. echo " Monkeysphere keytrans test completed successfully!"
  82. echo "##################################################"
  83. cleanup