X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere-host;h=da376185ed017192d314360dc9e13d894c455702;hb=ce693e829f05de90a4054bdd5d17480d9e6564ab;hp=b45b50ec60e38c9969426119c469e968751d5dbc;hpb=17315937bc0af145ef7dfb749096faad49f208aa;p=monkeysphere.git diff --git a/src/monkeysphere-host b/src/monkeysphere-host index b45b50e..da37618 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -101,7 +101,7 @@ update_gpg_pub_file() { } host_fingerprints() { - local fprs=($(cat "$HOST_KEY_FPR_FILE")) + local fprs=($(cat "$HOST_KEY_FPR_FILE" 2>/dev/null)) log debug "host key fingerprints:" printf '%s\n' "${fprs[@]}" | log debug @@ -138,12 +138,13 @@ Please run 'monkeysphere-host import-key' to import a key." ;; *) if [ -z "$keyID" ] ; then - failure "Keyring contains multiple keys. Please specify one to act on (see 'monkeysphere-host show-key')." + failure "Your host keyring contains multiple keys. +Please specify one to act on (see 'monkeysphere-host show-key')." fi ;; esac printf '%s\n' "${fprs[@]}" | grep "${keyID}$" \ - || failure "Key '$keyID' not found." + || failure "Host key '$keyID' not found." } # return 0 if user ID was found. @@ -174,11 +175,6 @@ multi_key() { if [[ -z "$1" || "$1" == '--all' ]] ; then keys="${fprs[@]}" - else - for key in $keys ; do - printf '%s\n' "${fprs[@]}" | grep "${key}$" \ - || failure "Key '$key' not found." - done fi for key in $keys ; do @@ -193,8 +189,8 @@ multi_key() { show_key() { local id="$1" local GNUPGHOME - local TMPSSH local fingerprint + local tmpssh local revokers # tmp gpghome dir @@ -206,24 +202,29 @@ show_key() { # import the host key into the tmp dir gpg --quiet --import <"$HOST_KEY_FILE" - # create the ssh key - TMPSSH="$GNUPGHOME"/ssh_host_key_rsa_pub - gpg --export "$id" | openpgp2ssh 2>/dev/null >"$TMPSSH" - # get the gpg fingerprint - fingerprint=$(gpg --quiet --list-keys \ + if gpg --quiet --list-keys \ --with-colons --with-fingerprint "$id" \ - | grep '^fpr:' | cut -d: -f10 ) + | grep '^fpr:' | cut -d: -f10 > "$GNUPGHOME"/fingerprint ; then + fingerprint=$(cat "$GNUPGHOME"/fingerprint) + else + failure "ID '$id' not found." + fi + + # create the ssh key + tmpssh="$GNUPGHOME"/ssh_host_key_rsa_pub + gpg --export "$fingerprint" 2>/dev/null \ + | openpgp2ssh 2>/dev/null >"$tmpssh" # list the host key info # FIXME: make no-show-keyring work so we don't have to do the grep'ing # FIXME: can we show uid validity somehow? - gpg --list-keys --list-options show-unusable-uids "$id" 2>/dev/null \ + gpg --list-keys --list-options show-unusable-uids "$fingerprint" 2>/dev/null \ | grep -v "^${GNUPGHOME}/pubring.gpg$" \ | egrep -v '^-+$' # list revokers, if there are any - revokers=$(gpg --list-keys --with-colons --fixed-list-mode "$id" \ + revokers=$(gpg --list-keys --with-colons --fixed-list-mode "$fingerprint" \ | awk -F: '/^rvk:/{ print $10 }' ) if [ "$revokers" ] ; then echo "The following keys are allowed to revoke this host key:" @@ -238,7 +239,7 @@ show_key() { # list the ssh fingerprint echo -n "ssh fingerprint: " - ssh-keygen -l -f "$TMPSSH" | awk '{ print $1, $2, $4 }' + ssh-keygen -l -f "$tmpssh" | awk '{ print $1, $2, $4 }' # remove the tmp file trap - EXIT