summaryrefslogtreecommitdiff
path: root/src/share/m/import_subkey
blob: 1823f71d69ae84b57973aa359f2ed5e587919e3f (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 sshKeyFile
  15. local keyID
  16. local gpgSecOut
  17. local fifoDir
  18. sshKeyFile="$1"
  19. shift
  20. # check that key file specified
  21. if [ -z "$sshKeyFile" ] ; then
  22. failure "Must specify ssh key file to import, or specify '-' for stdin."
  23. fi
  24. # check that the keyID is unique
  25. keyID=$(check_gpg_sec_key_id "$@")
  26. # check that an authentication subkey does not already exist
  27. check_gpg_authentication_subkey "$keyID"
  28. # FIXME: implement!
  29. failure "implement me!"
  30. # setup the temp fifo dir for retrieving the key password
  31. log debug "creating password fifo..."
  32. fifoDir=$(msmktempdir)
  33. trap "rm -rf $fifoDir" EXIT
  34. (umask 077 && mkfifo "$fifoDir/pass")
  35. # import ssh key to as authentication subkey
  36. if [ "$sshKeyFile" = '-' ] ; then
  37. log verbose "importing ssh key from stdin..."
  38. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" \
  39. | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
  40. else
  41. log verbose "importing ssh key from file '$sshKeyFile'..."
  42. PEM2OPENPGP_USAGE_FLAGS=authenticate pem2openpgp "$userID" <"$sshKeyFile" \
  43. | gpg_user --passphrase-fd 3 3< "$fifoDir/pass" --expert --command-fd 0 --import &
  44. fi
  45. # get the password if needed
  46. passphrase_prompt "Please enter your passphrase for $keyID: " "$fifoDir/pass"
  47. trap - EXIT
  48. rm -rf "$fifoDir"
  49. wait
  50. log verbose "done."
  51. }