X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fmonkeysphere-host;h=4f536e2365a784addde542c4407d073c3c9d7a06;hb=638a70f020f4ccda3deb15e5c697d384e0f705d7;hp=c9b6a4c683a6410cf178b25fc5cd9c318af4bb0b;hpb=9b9b23c821e9309dd04cc3f193885ec5f32a0fdc;p=monkeysphere.git diff --git a/src/monkeysphere-host b/src/monkeysphere-host index c9b6a4c..4f536e2 100755 --- a/src/monkeysphere-host +++ b/src/monkeysphere-host @@ -79,9 +79,14 @@ gpg_host() { # list the info about the a key, in colon format, to stdout gpg_host_list_keys() { - gpg_host --list-keys --with-colons --fixed-list-mode \ - --with-fingerprint --with-fingerprint \ - "$1" + if [ "$1" ] ; then + gpg_host --list-keys --with-colons --fixed-list-mode \ + --with-fingerprint --with-fingerprint \ + "$1" + else + gpg_host --list-keys --with-colons --fixed-list-mode \ + --with-fingerprint --with-fingerprint + fi } # edit key scripts, takes scripts on stdin, and keyID as first input @@ -97,14 +102,6 @@ update_pgp_pub_file() { > "$HOST_KEY_FILE" } -host_fingerprints() { - local fprs=($(gpg_host --list-secret-keys --with-colons --fingerprint | grep ^fpr: | cut -f10 -d:)) - - log debug "host key fingerprints:" - printf '%s\n' "${fprs[@]}" | log debug - printf '%s\n' "${fprs[@]}" -} - # check that the service name is well formed check_service_name() { local name="$1" @@ -123,7 +120,7 @@ Please run 'monkeysphere-host import-key' import a key." check_key_input() { local keyID="$1" # array of fingerprints - local fprs=($(host_fingerprints)) + local fprs=($(list_primary_fingerprints <"$HOST_KEY_FILE")) case ${#fprs[@]} in 0) @@ -159,13 +156,32 @@ check_key_userid() { grep -q -x -F "$tmpuidMatch" 2>/dev/null } +prompt_userid_exists() { + local userID="$1" + local gpgOut + local fingerprint + + if gpgOut=$(gpg_host_list_keys "=${userID}" 2>/dev/null) ; then + fingerprint=$(echo "$gpgOut" | grep '^fpr:' | cut -d: -f10) + if [ "$PROMPT" = "true" ] ; then + printf "Service name '%s' is already being used by key '%s'.\nAre you sure you want to use it again? (y/N) " "$fingerprint" "$userID" >&2 + read OK; OK=${OK:=N} + if [ "${OK/y/Y}" != 'Y' ] ; then + failure "Service name not added." + fi + else + log info "Key '%s' is already using the service name '%s'." "$fingerprint" "$userID" >&2 + fi + fi +} + # run command looped over keys multi_key() { local cmd="$1" shift local keys=$@ local i=0 - local fprs=($(host_fingerprints)) + local fprs=($(list_primary_fingerprints <"$HOST_KEY_FILE")) local key check_no_keys