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