summaryrefslogtreecommitdiff
path: root/src/share/mh/add_revoker
blob: 21dc0bb11a7191674d9b48986c0a289fe61014cf (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=$(msmktempdir) || 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 --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!"
  53. # export the new key to the host keyring
  54. su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --quiet --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 "key found:"
  65. gpg_host --fingerprint "0x${fingerprint}!"
  66. if [ "$PROMPT" = "true" ] ; then
  67. echo "Are you sure you want to add the above key as a"
  68. read -p "revoker of the host key? (Y/n) " OK; OK=${OK:-Y}
  69. if [ "${OK/y/Y}" != 'Y' ] ; then
  70. failure "revoker not added."
  71. fi
  72. else
  73. log debug "adding revoker without prompting."
  74. fi
  75. # edit-key script to add revoker
  76. addrevokerCommand=$(cat <<EOF
  77. addrevoker
  78. EOF
  79. )
  80. # FIXME: implement!
  81. failure "not implemented yet!"
  82. # core ltsigns the newly imported revoker key
  83. if echo "$addrevokerCommand" | \
  84. gpg_core_edit ; then
  85. update_gpg_pub_file
  86. log info "Revoker added."
  87. else
  88. failure "Problem adding revoker."
  89. fi
  90. }