summaryrefslogtreecommitdiff
path: root/src/share/m/import_subkey
blob: 8b044568848c2ab6ca22a8717e6ed2b678b1e87c (plain)
  1. # -*-shell-script-*-
  2. # This should be sourced by bash (though we welcome changes to make it POSIX sh compliant)
  3. # Monkeysphere import-subkey 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. # import an existing ssh key as a gpg subkey
  13. import_subkey() {
  14. local keyFile="~/.ssh/id_rsa"
  15. local keyExpire
  16. local keyID
  17. local gpgOut
  18. local userID
  19. # get options
  20. while true ; do
  21. case "$1" in
  22. -f|--keyfile)
  23. keyFile="$2"
  24. shift 2
  25. ;;
  26. -e|--expire)
  27. keyExpire="$2"
  28. shift 2
  29. ;;
  30. *)
  31. if [ "$(echo "$1" | cut -c 1)" = '-' ] ; then
  32. failure "Unknown option '$1'.
  33. Type '$PGRM help' for usage."
  34. fi
  35. break
  36. ;;
  37. esac
  38. done
  39. log verbose "importing ssh key..."
  40. fifoDir=$(msmktempdir)
  41. (umask 077 && mkfifo "$fifoDir/pass")
  42. ssh2openpgp | gpg --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
  43. passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
  44. rm -rf "$fifoDir"
  45. wait
  46. log verbose "done."
  47. }