3 # seckey2sshagent: this is a hack of a script to cope with the fact
4 # that openpgp2ssh currently cannot support encrypted secret keys.
6 # the basic operating principal is:
8 # export the secret key in encrypted format to a new keyring
10 # remove the passphrase in that keyring
12 # use that keyring with openpgp2ssh
14 # Authors: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,
15 # Jameson Rollins <jrollins@fifthhorseman.net>
19 echo -n "removing temp gpg home... " 1>&2
26 echo -n "The basic strategy of seckey2sshagent is to dump your
27 OpenPGP authentication key(s) into your agent.
29 This script is a gross hack at the moment. It is done by creating a
30 new, temporary private keyring, letting the user remove the
31 passphrases from the keys, and then exporting them. The temporary
32 private keyring is purged from the system.
34 When you use this command, you'll find yourself dropped into a GPG
35 'edit-key' dialog relevant *only* to the temporary private keyring.
37 At that point, you should clear the password from your key, with:
40 <enter your current password>
42 followed by the empty string for the new password. GPG will ask you
43 if you're really sure. Answer yes, because this is only relevant to
44 the temporary keyring. Then, do:
48 At this point, your key will be added to your running ssh-agent with
49 the alias 'monkeysphere-key' and seckey2sshagent should terminate.
50 You can check on it with:
58 # if no hex string is supplied, just print an explanation.
59 # this covers seckey2sshagent --help, --usage, -h, etc...
60 if [ "$(echo "$1" | tr -d '0-9a-fA-F')" ]; then
69 if [ -z "$GPGIDS" ]; then
70 # hack: we need to get the list of secret keys, because if you
71 # --list-secret-keys with no arguments, GPG fails to print the
72 # capability flags (i've just filed this as
73 # https://bugs.g10code.com/gnupg/issue945)
74 KEYIDS=$(gpg2 --with-colons --list-secret-keys | grep ^sec | cut -f5 -d:)
75 # default to using all fingerprints of authentication-enabled keys
76 GPGIDS=$(gpg --with-colons --fingerprint --fingerprint --list-secret-keys $KEYIDS | egrep -A1 '^(ssb|sec):.*:[^:]*a[^:]*:$' | grep ^fpr: | cut -d: -f10)
79 for GPGID in $GPGIDS; do
81 TMPPRIVATE=$(mktemp -d)
83 gpg --export-secret-key "$GPGID" | GNUPGHOME="$TMPPRIVATE" gpg --import
85 # idea to script the password stuff. not working.
86 # read -s -p "enter gpg password: " PASSWD; echo
97 # echo -e "$cmd" | GNUPGHOME="$TMPPRIVATE" gpg --command-fd 0 --edit-key $GPGID
99 GNUPGHOME="$TMPPRIVATE" gpg --edit-key "$GPGID"
101 KEYNAME='MonkeySphere Key '$(echo "$GPGID" | tr -c -d '0-9a-fA-F')''
102 # creating this alias so the key is named "monkeysphere-key" in the
103 # comment stored by the agent, while never being written to disk in
105 ln -s /dev/stdin "$TMPPRIVATE/$KEYNAME"
107 GNUPGHOME="$TMPPRIVATE" gpg --export-secret-keys "$GPGID" | \
108 openpgp2ssh $GPGID | (cd "$TMPPRIVATE" && ssh-add -c "$KEYNAME")