summaryrefslogtreecommitdiff
path: root/src/share/mh/add_revoker
blob: 2275f6119688bbaf199f32086111b4f080e72942 (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. # check that key ID or file is specified
  24. if [ -z "$keyID" ] ; then
  25. failure "You must specify the key ID of a revoker key, or specify a file to read the key from."
  26. fi
  27. # if file is specified
  28. if [ -f "$keyID" -o "$keyID" = '-' ] ; then
  29. # load the key from stdin
  30. if [ "$keyID" = '-' ] ; then
  31. local keyID=$(msmktempfile)
  32. trap "rm -f $keyID" EXIT
  33. log verbose "reading key from stdin..."
  34. cat > "$keyID"
  35. # load the key from the file
  36. elif [ -f "$keyID" ] ; then
  37. log verbose "reading key from file '$keyID'..."
  38. fi
  39. # check the key is ok as monkeysphere user before loading
  40. log debug "checking keys in file..."
  41. fingerprint=$(su_monkeysphere_user \
  42. ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID")
  43. if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then
  44. failure "There was not exactly one gpg key in the file."
  45. fi
  46. # load the key
  47. gpg_host --import <"$keyID" \
  48. || failure "could not read key from '$keyID'"
  49. keyID="$fingerprint"
  50. # else, get the key from the keyserver
  51. else
  52. # create a temporary directory for storing the downloaded key
  53. local TMPLOC=$(msmktempdir)
  54. chmod 0700 "$GNUPGHOME"
  55. chown "$MONKEYSPHERE_USER":"$MONKEYSPHERE_USER" "$GNUPGHOME"
  56. # download the key from the keyserver as the monkeysphere user
  57. log verbose "searching keyserver $KEYSERVER for keyID $keyID..."
  58. su_monkeysphere_user \
  59. "GNUPGHOME=$TMPLOC gpg --quiet --keyserver $KEYSERVER --recv-key 0x${keyID}!" \
  60. || failure "Could not receive a key with this ID from the '$KEYSERVER' keyserver."
  61. # export the new key to the host keyring
  62. log verbose "loading key $keyID..."
  63. su_monkeysphere_user "GNUPGHOME=$TMPLOC gpg --quiet --export 0x${keyID}!" \
  64. | gpg_host --import
  65. fi
  66. # get the full fingerprint of new revoker key
  67. log debug "getting fingerprint of revoker key..."
  68. fingerprint=$(gpg_host --list-key --with-colons --with-fingerprint "0x${keyID}!" \
  69. | grep '^fpr:' | grep "$keyID" | cut -d: -f10)
  70. if [ -z "$fingerprint" ] ; then
  71. failure "Key '$keyID' not found."
  72. fi
  73. log info "key found:"
  74. gpg_host --fingerprint "0x${fingerprint}!"
  75. if [ "$PROMPT" = "true" ] ; then
  76. echo "Are you sure you want to add the above key as a"
  77. read -p "revoker of the host key? (Y/n) " OK; OK=${OK:-Y}
  78. if [ "${OK/y/Y}" != 'Y' ] ; then
  79. failure "revoker not added."
  80. fi
  81. else
  82. log debug "adding revoker without prompting."
  83. fi
  84. # edit-key script to add revoker
  85. addrevokerCommand=$(cat <<EOF
  86. addrevoker
  87. EOF
  88. )
  89. # FIXME: implement!
  90. failure "not implemented yet!"
  91. # core ltsigns the newly imported revoker key
  92. if echo "$addrevokerCommand" | \
  93. gpg_core_edit ; then
  94. update_gpg_pub_file
  95. log info "Revoker added."
  96. else
  97. failure "Problem adding revoker."
  98. fi
  99. }