X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fseckey2sshagent;h=a516256e29d92bf5671e3097a2a3af1ee9453a63;hb=4fc090419c3c87a6689ee2f42b94e1f40aa06e5c;hp=0e8d69526a360fa7710d753d3d93d8928e7b1175;hpb=9c94e937fbe8beb56956365cac07d6eff45215cd;p=monkeysphere.git diff --git a/src/seckey2sshagent b/src/seckey2sshagent index 0e8d695..a516256 100755 --- a/src/seckey2sshagent +++ b/src/seckey2sshagent @@ -1,25 +1,143 @@ -#!/bin/sh +#!/bin/bash + +# seckey2sshagent: this is a hack of a script to cope with the fact +# that openpgp2ssh currently cannot support encrypted secret keys. + +# the basic operating principal is: + +# export the secret key in encrypted format to a new keyring + +# remove the passphrase in that keyring + +# use that keyring with openpgp2ssh + +# Authors: Daniel Kahn Gillmor , +# Jameson Rollins + +explanation() { + + cat < + +followed by the empty string for the new password. GPG will ask you +if you're really sure. Answer yes, because this is only relevant to +the temporary keyring. Then, do: + + save + +At this point, your key will be added to your running ssh-agent with +the alias 'monkeysphere-key' and seckey2sshagent should terminate. +You can check on it with: + + ssh-add -l + +EOF +} cleanup() { - echo -n "removing temp gpg home... " - rm -rf $FOO - echo "done." + echo -n "removing temp gpg home... " 1>&2 + rm -rf "$TMPPRIVATE" + echo "done." 1>&2 } -trap cleanup EXIT +export_sec_key() { + gpg --export-secret-key "$GPGID" | GNUPGHOME="$TMPPRIVATE" gpg --import + + GNUPGHOME="$TMPPRIVATE" gpg --edit-key "$GPGID" -GPGID="$1" + # idea to script the password stuff. not working. + # read -s -p "enter gpg password: " PASSWD; echo + # cmd=$(cat < "$TMPPRIVATE/key" + # passprotect file + ssh-keygen -f "${TMPPRIVATE}/key" -p + # move into place + mv "${TMPPRIVATE}/key" "$FILE" + + # export public key + gpg --export "$GPGID" | openpgp2ssh "$GPGID" > "${FILE}.pub" + + # otherwise add to agent + else + KEYNAME='MonkeySphere Key '$(echo "$GPGID" | tr -c -d '0-9a-fA-F')'' -gpg --export-secret-key --export-options export-reset-subkey-passwd $GPGID | GNUPGHOME=$FOO gpg --import + # creating this alias so the key is named "monkeysphere-key" in the + # comment stored by the agent, while never being written to disk in + # SSH form: + ln -s /dev/stdin "${TMPPRIVATE}/${KEYNAME}" -GNUPGHOME=$FOO gpg --edit-key $GPGID + # export secret key to agent + export_sec_key | (cd "$TMPPRIVATE" && ssh-add -c "$KEYNAME") + fi -GNUPGHOME=$FOO gpg --export-secret-key $GPGID | openpgp2ssh $GPGID | ssh-add -c /dev/stdin +done