summaryrefslogtreecommitdiff
path: root/src/share/mh/add_hostname
blob: 267f109e811b662597e5cd97c4a9f6a1285b30ad (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-hostname 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-2009, and are all released under the GPL,
  11. # version 3 or later.
  12. # add hostname user ID to server key
  13. add_hostname() {
  14. local userID
  15. local fingerprint
  16. local tmpuidMatch
  17. local line
  18. local adduidCommand
  19. if [ -z "$1" ] ; then
  20. failure "You must specify a hostname to add."
  21. fi
  22. userID="ssh://${1}"
  23. fingerprint=$(fingerprint_host_key)
  24. # match to only ultimately trusted user IDs
  25. tmpuidMatch="u:$(echo $userID | gpg_escape)"
  26. # find the index of the requsted user ID
  27. # NOTE: this is based on circumstantial evidence that the order of
  28. # this output is the appropriate index
  29. if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
  30. | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
  31. failure "Host userID '$userID' already exists."
  32. fi
  33. echo "The following user ID will be added to the host key:"
  34. echo " $userID"
  35. read -p "Are you sure you would like to add this user ID? (y/N) " OK; OK=${OK:=N}
  36. if [ ${OK/y/Y} != 'Y' ] ; then
  37. failure "User ID not added."
  38. fi
  39. # edit-key script command to add user ID
  40. adduidCommand=$(cat <<EOF
  41. adduid
  42. $userID
  43. save
  44. EOF
  45. )
  46. # execute edit-key script
  47. if echo "$adduidCommand" | \
  48. gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
  49. show_key
  50. echo
  51. echo "NOTE: User ID added to key, but key not published."
  52. echo "Run '$PGRM publish-key' to publish the new user ID."
  53. else
  54. failure "Problem adding user ID."
  55. fi
  56. }