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