summaryrefslogtreecommitdiff
path: root/src/share/mh/add_revoker
blob: 39dfacac6544774c0caaead19876c4cb22e26d9b (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere host add-revoker subcommand
  4. #
  5. # The monkeysphere scripts are written by:
  6. # Jameson Rollins <jrollins@finestructure.net>
  7. # Jamie McClelland <jm@mayfirst.org>
  8. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  9. #
  10. # They are Copyright 2008, and are all released under the GPL, version 3
  11. # or later.
  12. # add a revoker to the host key
  13. add_revoker() {
  14. local domain=
  15. local trust=full
  16. local depth=1
  17. local keyID
  18. local importinfo
  19. local fingerprint
  20. local ltsignCommand
  21. local trustval
  22. keyID="$1"
  23. if [ -z "$keyID" ] ; then
  24. failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
  25. fi
  26. if [ -f "$keyID" ] ; then
  27. log info "Reading key from file '$keyID':"
  28. importinfo=$(gpg_host --import < "$keyID" 2>&1) || failure "could not read key from '$keyID'"
  29. # FIXME: if this is tried when the key database is not
  30. # up-to-date, i got these errors (using set -x):
  31. # ++ su -m monkeysphere -c '\''gpg --import'\''
  32. # Warning: using insecure memory!
  33. # gpg: key D21739E9: public key "Daniel Kahn Gillmor <dkg@fifthhorseman.net>" imported
  34. # gpg: Total number processed: 1
  35. # gpg: imported: 1 (RSA: 1)
  36. # gpg: can'\''t create `/var/monkeysphere/gnupg-host/pubring.gpg.tmp'\'': Permission denied
  37. # gpg: failed to rebuild keyring cache: Permission denied
  38. # gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
  39. # gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
  40. # gpg: next trustdb check due at 2009-01-10'
  41. # + failure 'could not read key from '\''/root/dkg.gpg'\'''
  42. # + echo 'could not read key from '\''/root/dkg.gpg'\'''
  43. keyID=$(echo "$importinfo" | grep '^gpg: key ' | cut -f2 -d: | cut -f3 -d\ )
  44. if [ -z "$keyID" ] || [ $(echo "$keyID" | wc -l) -ne 1 ] ; then
  45. failure "There was not exactly one gpg key in the file."
  46. fi
  47. else
  48. # create a temporary directory for storing the downloaded key
  49. TMPLOC=$(mktemp -d ${MHTMPDIR}/tmp.XXXXXXXXXX) || failure "Could not create temporary directory!"
  50. # download the key from the keyserver as the monkeysphere user
  51. su_monkeysphere_user \
  52. "GNUPGHOME=$TMPLOC gpg --keyserver $KEYSERVER --recv-key 0x${keyID}!"
  53. # export the new key to the host keyring
  54. su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --export 0x${keyID}!" \
  55. | gpg_host --import
  56. fi
  57. export keyID
  58. # get the full fingerprint of the revoker key ID
  59. fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \
  60. | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
  61. if [ -z "$fingerprint" ] ; then
  62. failure "Key '$keyID' not found."
  63. fi
  64. log info -e "\nkey found:"
  65. gpg_host --fingerprint "0x${fingerprint}!"
  66. echo "Are you sure you want to add the above key as a"
  67. read -p "revoker of the host key? (y/N) " OK; OK=${OK:-N}
  68. if [ "${OK/y/Y}" != 'Y' ] ; then
  69. failure "Revoker not added."
  70. fi
  71. # edit-key script to add revoker
  72. # NOTE: *all* user IDs will be ltsigned
  73. addrevokerCommand=$(cat <<EOF
  74. addrevoker
  75. EOF
  76. )
  77. # FIXME: implement!
  78. failure "not implemented yet!"
  79. # core ltsigns the newly imported revoker key
  80. if echo "$addrevokerCommand" | \
  81. gpg_core_edit ; then
  82. log info -e "\nRevoker added."
  83. else
  84. failure "Problem adding revoker."
  85. fi
  86. }