summaryrefslogtreecommitdiff
path: root/src/subcommands/mh/add-hostname
blob: fc1ae9665ec76745ffed24900e72bea31e8e12fb (plain)
  1. #!/usr/bin/env bash
  2. # Monkeysphere host add-hostname subcommand
  3. #
  4. # The monkeysphere scripts are written by:
  5. # Jameson Rollins <jrollins@fifthhorseman.net>
  6. # Jamie McClelland <jm@mayfirst.org>
  7. # Daniel Kahn Gillmor <dkg@fifthhorseman.net>
  8. #
  9. # They are Copyright 2008, and are all released under the GPL, version 3
  10. # or later.
  11. # add hostname user ID to server key
  12. local userID
  13. local fingerprint
  14. local tmpuidMatch
  15. local line
  16. local adduidCommand
  17. if [ -z "$1" ] ; then
  18. failure "You must specify a hostname to add."
  19. fi
  20. userID="ssh://${1}"
  21. fingerprint=$(fingerprint_server_key)
  22. # match to only ultimately trusted user IDs
  23. tmpuidMatch="u:$(echo $userID | gpg_escape)"
  24. # find the index of the requsted user ID
  25. # NOTE: this is based on circumstantial evidence that the order of
  26. # this output is the appropriate index
  27. if line=$(gpg_host --list-keys --with-colons --fixed-list-mode "0x${fingerprint}!" \
  28. | egrep '^(uid|uat):' | cut -f2,10 -d: | grep -n -x -F "$tmpuidMatch") ; then
  29. failure "Host userID '$userID' already exists."
  30. fi
  31. echo "The following user ID will be added to the host key:"
  32. echo " $userID"
  33. read -p "Are you sure you would like to add this user ID? (y/N) " OK; OK=${OK:=N}
  34. if [ ${OK/y/Y} != 'Y' ] ; then
  35. failure "User ID not added."
  36. fi
  37. # edit-key script command to add user ID
  38. adduidCommand=$(cat <<EOF
  39. adduid
  40. $userID
  41. save
  42. EOF
  43. )
  44. # execute edit-key script
  45. if echo "$adduidCommand" | \
  46. gpg_host --quiet --command-fd 0 --edit-key "0x${fingerprint}!" ; then
  47. # update the trustdb for the authentication keyring
  48. gpg_authentication "--check-trustdb"
  49. show_server_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