X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere;h=94279f4092abe234536b19abad44be68a7b0158a;hb=189781e00c89227612942ff7dc30eaa756cb78ae;hp=147c179403d993aa80d6ea6f1acf9c0e7bf389be;hpb=dfd67a14003fbfb4b1ba2269e7d47f4d0c44fcf8;p=monkeysphere.git diff --git a/src/monkeysphere b/src/monkeysphere index 147c179..94279f4 100755 --- a/src/monkeysphere +++ b/src/monkeysphere @@ -50,6 +50,7 @@ subcommands: ssh-proxycommand HOST [PORT] monkeysphere ssh ProxyCommand --no-connect do not make TCP connection to host subkey-to-ssh-agent (s) store authentication subkey in ssh-agent + sshfpr (f) KEYID output ssh fingerprint of gpg key version (v) show version number help (h,?) this help @@ -61,6 +62,23 @@ gpg_user() { gpg --no-greeting --quiet --no-tty "$@" } +# output the ssh fingerprint of a gpg key +gpg_ssh_fingerprint() { + keyid="$1" + local tmpfile=$(mktemp) + + # trap to remove tmp file if break + trap "rm -f $tmpfile" EXIT + + # use temporary file, since ssh-keygen won't accept keys on stdin + gpg_user --export "$keyid" | openpgp2ssh "$keyid" >"$tmpfile" + ssh-keygen -l -f "$tmpfile" | awk '{ print $1, $2, $4 }' + + # remove the tmp file + trap - EXIT + rm -rf "$tmpfile" +} + # take a secret key ID and check that only zero or one ID is provided, # and that it corresponds to only a single secret key ID check_gpg_sec_key_id() { @@ -126,7 +144,8 @@ check_gpg_authentication_subkey() { if [ "$validity" = 'u' ] ; then echo "A valid authentication key already exists for primary key '$keyID'." 1>&2 if [ "$PROMPT" = "true" ] ; then - read -p "Are you sure you would like to generate another one? (y/N) " OK; OK=${OK:N} + printf "Are you sure you would like to generate another one? (y/N) " >&2 + read OK; OK=${OK:N} if [ "${OK/y/Y}" != 'Y' ] ; then failure "aborting." fi @@ -175,7 +194,18 @@ if [ -z "$KEYSERVER" ] ; then fi fi PROMPT=${MONKEYSPHERE_PROMPT:=$PROMPT} -KNOWN_HOSTS=${MONKEYSPHERE_KNOWN_HOSTS:=$KNOWN_HOSTS} +# check the known_hosts file +if [ "$MONKEYSPHERE_KNOWN_HOSTS" ] ; then + if [ -f "$MONKEYSPHERE_KNOWN_HOSTS" ] ; then + KNOWN_HOSTS="$MONKEYSPHERE_KNOWN_HOSTS" + else + failure "specified monkeysphere known_hosts file '$MONKEYSPHERE_KNOWN_HOSTS' does not exist." + fi +fi +[ -d $(dirname "$KNOWN_HOSTS") ] \ + || mkdir -m 0700 $(dirname "$KNOWN_HOSTS") +[ -f "$KNOWN_HOSTS" ] \ + || touch "$KNOWN_HOSTS" HASH_KNOWN_HOSTS=${MONKEYSPHERE_HASH_KNOWN_HOSTS:=$HASH_KNOWN_HOSTS} AUTHORIZED_KEYS=${MONKEYSPHERE_AUTHORIZED_KEYS:=$AUTHORIZED_KEYS} @@ -243,6 +273,10 @@ case $COMMAND in subkey_to_ssh_agent "$@" ;; + 'sshfpr'|'f') + gpg_ssh_fingerprint "$@" + ;; + 'version'|'v') version ;;