X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=src%2Fcommon;h=44bdb670f515384646bd6d92a5f11ad6e6b5329a;hb=39f3516d7f57397cb61c5a28d3d199ad9bb1a719;hp=cbfa95693c307782081b4c728206186f645601b7;hpb=70674cae8b3d69d0e750125387b26c0d5857c5ba;p=monkeysphere.git diff --git a/src/common b/src/common index cbfa956..44bdb67 100644 --- a/src/common +++ b/src/common @@ -69,11 +69,101 @@ file_hash() { md5sum "$1" 2> /dev/null } -# convert escaped characters from gpg output back into original -# character -# FIXME: undo all escape character translation in with-colons gpg output -unescape() { - echo "$1" | sed 's/\\x3a/:/' +# convert escaped characters in pipeline from gpg output back into +# original character +# FIXME: undo all escape character translation in with-colons gpg +# output +gpg_unescape() { + sed 's/\\x3a/:/g' +} + +# convert nasty chars into gpg-friendly form in pipeline +# FIXME: escape everything, not just colons! +gpg_escape() { + sed 's/:/\\x3a/g' +} + +# prompt for GPG-formatted expiration, and emit result on stdout +get_gpg_expiration() { + local keyExpire= + + cat >&2 < = key expires in n days + w = key expires in n weeks + m = key expires in n months + y = key expires in n years +EOF + while [ -z "$keyExpire" ] ; do + read -p "Key is valid for? (0) " keyExpire + if ! test_gpg_expire ${keyExpire:=0} ; then + echo "invalid value" >&2 + unset keyExpire + fi + done + echo "$keyExpire" +} + +passphrase_prompt() { + local prompt="$1" + local fifo="$2" + local PASS + + if [ "$DISPLAY" ] && which "${SSH_ASKPASS:-ssh-askpass}" >/dev/null; then + "${SSH_ASKPASS:-ssh-askpass}" "$prompt" > "$fifo" + else + read -s -p "$prompt" PASS + # Uses the builtin echo, so should not put the passphrase into + # the process table. I think. --dkg + echo "$PASS" > "$fifo" + fi +} + +test_gnu_dummy_s2k_extension() { + +# this block contains a demonstration private key that has had the +# primary key stripped out using the GNU S2K extension known as +# "gnu-dummy" (see /usr/share/doc/gnupg/DETAILS.gz). The subkey is +# present in cleartext, however. + +# openpgp2ssh will be able to deal with this based on whether the +# local copy of GnuTLS contains read_s2k support that can handle it. + +# read up on that here: + +# http://lists.gnu.org/archive/html/gnutls-devel/2008-08/msg00005.html + +echo " +-----BEGIN PGP PRIVATE KEY BLOCK----- +Version: GnuPG v1.4.9 (GNU/Linux) + +lQCVBEO3YdABBACRqqEnucag4+vyZny2M67Pai5+5suIRRvY+Ly8Ms5MvgCi3EVV +xT05O/+0ShiRaf+QicCOFrhbU9PZzzU+seEvkeW2UCu4dQfILkmj+HBEIltGnHr3 +G0yegHj5pnqrcezERURf2e17gGFWX91cXB9Cm721FPXczuKraphKwCA9PwARAQAB +/gNlAkdOVQG0OURlbW9uc3RyYXRpb24gS2V5IGZvciBTMksgR05VIGV4dGVuc2lv +biAxMDAxIC0tIGdudS1kdW1teYi8BBMBAgAmBQJDt2HQAhsDBQkB4TOABgsJCAcD +AgQVAggDBBYCAwECHgECF4AACgkQQZUwSa4UDezTOQP/TMQXUVrWzHYZGopoPZ2+ +ZS3qddiznBHsgb7MGYg1KlTiVJSroDUBCHIUJvdQKZV9zrzrFl47D07x6hGyUPHV +aZXvuITW8t1o5MMHkCy3pmJ2KgfDvdUxrBvLfgPMICA4c6zA0mWquee43syEW9NY +g3q61iPlQwD1J1kX1wlimLCdAdgEQ7dh0AEEANAwa63zlQbuy1Meliy8otwiOa+a +mH6pxxUgUNggjyjO5qx+rl25mMjvGIRX4/L1QwIBXJBVi3SgvJW1COZxZqBYqj9U +8HVT07mWKFEDf0rZLeUE2jTm16cF9fcW4DQhW+sfYm+hi2sY3HeMuwlUBK9KHfW2 ++bGeDzVZ4pqfUEudABEBAAEAA/0bemib+wxub9IyVFUp7nPobjQC83qxLSNzrGI/ +RHzgu/5CQi4tfLOnwbcQsLELfker2hYnjsLrT9PURqK4F7udrWEoZ1I1LymOtLG/ +4tNZ7Mnul3wRC2tCn7FKx8sGJwGh/3li8vZ6ALVJAyOia5TZ/buX0+QZzt6+hPKk +7MU1WQIA4bUBjtrsqDwro94DvPj3/jBnMZbXr6WZIItLNeVDUcM8oHL807Am97K1 +ueO/f6v1sGAHG6lVPTmtekqPSTWBfwIA7CGFvEyvSALfB8NUa6jtk27NCiw0csql +kuhCmwXGMVOiryKEfegkIahf2bAd/gnWHPrpWp7bUE20v8YoW22I4wIAhnm5Wr5Q +Sy7EHDUxmJm5TzadFp9gq08qNzHBpXSYXXJ3JuWcL1/awUqp3tE1I6zZ0hZ38Ia6 +SdBMN88idnhDPqPoiKUEGAECAA8FAkO3YdACGyAFCQHhM4AACgkQQZUwSa4UDezm +vQP/ZhK+2ly9oI2z7ZcNC/BJRch0/ybQ3haahII8pXXmOThpZohr/LUgoWgCZdXg +vP6yiszNk2tIs8KphCAw7Lw/qzDC2hEORjWO4f46qk73RAgSqG/GyzI4ltWiDhqn +vnQCFl3+QFSe4zinqykHnLwGPMXv428d/ZjkIc2ju8dRsn4= +=CR5w +-----END PGP PRIVATE KEY BLOCK----- +" | openpgp2ssh 4129E89D17C1D591 >/dev/null 2>/dev/null + } # remove all lines with specified string from specified file @@ -386,29 +476,24 @@ process_user_id() { ;; 'uid') # user ids if [ "$lastKey" != pub ] ; then - log " - got a user ID after a sub key! user IDs should only follow primary keys!" - continue - fi - # don't bother with a uid if there is no valid or reasonable primary key. - if [ "$keyOK" != true ] ; then + log " - got a user ID after a sub key?! user IDs should only follow primary keys!" continue fi # if an acceptable user ID was already found, skip - if [ "$uidOK" ] ; then + if [ "$uidOK" = 'true' ] ; then continue fi - # if the user ID does not match, skip - if [ "$(unescape "$uidfpr")" != "$userID" ] ; then - continue - fi - # if the user ID validity is not ok, skip - if [ "$validity" != 'u' -a "$validity" != 'f' ] ; then + # if the user ID does matches... + if [ "$(echo "$uidfpr" | gpg_unescape)" = "$userID" ] ; then + # and the user ID validity is ok + if [ "$validity" = 'u' -o "$validity" = 'f' ] ; then + # mark user ID acceptable + uidOK=true + fi + else continue fi - # mark user ID acceptable - uidOK=true - # output a line for the primary key # 0 = ok, 1 = bad if [ "$keyOK" -a "$uidOK" -a "$lastKeyOK" ] ; then @@ -484,7 +569,10 @@ process_user_id() { fi ;; esac - done + done | sort -t: -k1 -n -r + # NOTE: this last sort is important so that the "good" keys (key + # flag '0') come last. This is so that they take precedence when + # being processed in the key files over "bad" keys (key flag '1') } # process a single host in the known_host file @@ -498,16 +586,15 @@ process_host_known_hosts() { local tmpfile host="$1" + userID="ssh://${host}" log "processing: $host" - userID="ssh://${host}" - nKeys=0 nKeysOK=0 IFS=$'\n' - for line in $(process_user_id "ssh://${host}") ; do + for line in $(process_user_id "${userID}") ; do # note that key was found nKeys=$((nKeys+1))