diff options
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/_ak_config | 7 | ||||
| -rwxr-xr-x | lib/_ak_fs | 8 | ||||
| -rwxr-xr-x | lib/_ak_gpg | 25 | ||||
| -rwxr-xr-x | lib/_ak_ipfs | 16 | ||||
| -rwxr-xr-x | lib/_ak_log | 19 | ||||
| -rwxr-xr-x | lib/_ak_network_incoming | 92 | ||||
| -rwxr-xr-x | lib/_ak_network_yggdrasil | 14 | ||||
| -rwxr-xr-x | lib/_ak_node | 2 | ||||
| -rwxr-xr-x | lib/_ak_ns | 214 | ||||
| -rwxr-xr-x | lib/_ak_script | 22 | 
10 files changed, 333 insertions, 86 deletions
diff --git a/lib/_ak_config b/lib/_ak_config index 6c71e9c..085d79f 100755 --- a/lib/_ak_config +++ b/lib/_ak_config @@ -19,9 +19,12 @@  ###  source $AK_LIBDIR/_ak_lib_load  _ak_lib_load _ak_node +_ak_lib_load _ak_fs  function _ak_config_show(){      # We will be using our public key also to put it in the block later +    tempdir="$(_ak_make_temp_directory)" +    cd $tempdir      KEY="self.pub"      ak-gpg --export-key-self-to-file      _ak_log_debug "$KEY" @@ -32,6 +35,7 @@ function _ak_config_show(){  {      "profile":'$profile',      "genesis":"'$(cat $AK_WORKDIR/config/zgenesis)'", +    "keymaps":'$(ak gpg -l 2>/dev/null | while read line; do ak gpg --export-key $line $line && ak fs --add $line | sed -e 's/.*/{"fingerprint":"'$line'","map":"&"},/' ; done | tr -d '\n'|sed 's/^/[/;s/,$/],/')'      "gpg":{          "ipfs":"'$GPG_PUB_KEY'",          "fingerprint":"'$(ak gpg --get-key-fingerprint-from-ipfs $GPG_PUB_KEY)'" @@ -39,10 +43,13 @@ function _ak_config_show(){      "zchain":"'$(cat $AK_WORKDIR/config/zchain)'",      "zlatest":"'$(ak zchain --get-latest)'"  }'| jq; +    cd +    rm -rf $tempdir  }  function _ak_config_publish(){      _ak_config_show | jq -c -M > tmpfile +    akfs_map_v3="$(_ak_fs_import tmpfile)"      ipfs_hash="$(_ak_ipfs_add tmpfile)"      _ak_ipfs_config_publish $ipfs_hash      if [ $? != 0 ] @@ -112,6 +112,14 @@ function _ak_fs_import(){          #          _ak_log_info "Storing original hash of $1 along with its name"          sha512sum "$1" > $TEMPDIR/3rd_gen_map +        hashgrep="$(grep -rn $(cat $TEMPDIR/3rd_gen_map | cut -d ' ' -f 1) $AK_MAPSDIR)" +        if [ $? -eq 0 ] +        then +            map="$(basename $( echo $hashgrep | cut -d ':' -f 1 ))" +            _ak_log_error "File $1 found @ $map" +            echo $map +            exit 0 +        fi          _ak_log_info "Encoding to base64"          base64 $1 > file          FILE="file" diff --git a/lib/_ak_gpg b/lib/_ak_gpg index 7832ca1..8f014f8 100755 --- a/lib/_ak_gpg +++ b/lib/_ak_gpg @@ -206,10 +206,19 @@ function _ak_gpg_verify_signature(){      fi  } +function _ak_gpg_key_export(){ +    if [ ! -z $1 ] && [ -n "$1" ] && [ ! -z $2 ] && [ -n "$2" ] +    then +        _ak_gpg --armour --output $2 --export $1 +    else +        exit 1 +    fi +} +  function _ak_gpg_key_self_export(){      if [ ! -z $1 ] && [ -n "$1" ]      then -        _ak_gpg --armour --output $1 --export $AK_FINGERPRINT +        _ak_gpg_key_export $AK_FINGERPRINT $1      else          exit 1      fi @@ -253,6 +262,20 @@ function _ak_gpg_list_secret_keys_long(){          uniq  } +function _ak_gpg_select_key_to_export(){ +    select x in $(_ak_gpg_list_secret_keys | tr '\n' ' ') +    do +        if [ -n "$x" ] +        then +            _ak_log_info "$x was selected" +            _ak_gpg_key_export "$x" "$x.asc" +            break +        else +            _ak_log_warning "You didn't select a key" +        fi +    done +} +  function _ak_gpg_select_key(){      select x in $(_ak_gpg_list_secret_keys | tr '\n' ' ')      do diff --git a/lib/_ak_ipfs b/lib/_ak_ipfs index 07595ae..16397a7 100755 --- a/lib/_ak_ipfs +++ b/lib/_ak_ipfs @@ -22,10 +22,15 @@ _ak_lib_load _ak_log  AK_IPFS_REPO="$AK_WORKDIR/ipfsrepo"  AK_IPFS_ARTIFACTS="$AK_WORKDIR/ipfs_artifacts" +AK_IPNS_ARTIFACTS="$AK_WORKDIR/ipns_artifacts"  if [ ! -d $AK_IPFS_ARTIFACTS ]  then      mkdir -p $AK_IPFS_ARTIFACTS  fi +if [ ! -d $AK_IPNS_ARTIFACTS ] +then +    mkdir -p $AK_IPNS_ARTIFACTS +fi  function _ak_ipfs(){      export IPFS_PATH=$AK_IPFS_REPO; kubo $* @@ -316,12 +321,17 @@ function _ak_ipfs_name_publish(){          _ak_log_error "No argument given"          exit 1      fi -    _ak_ipfs name publish --key="$1" "$2" +    key="$(_ak_ipfs key list -l | grep $1 | cut -d ' ' -f 1)"      if [ $? -ne 0 ]      then          _ak_log_error "Failed to get $1"          exit 1      fi +    if [ -f "$AK_IPNS_ARTIFACTS/$key" ] +    then +        cat $AK_IPNS_ARTIFACTS/$key >> $AK_IPNS_ARTIFACTS/$key.history +    fi +    echo $2 > $AK_IPNS_ARTIFACTS/$key  }  function _ak_ipfs_config_publish(){ @@ -340,12 +350,12 @@ function _ak_ipfs_name_resolve(){          _ak_log_error "No argument given"          exit 1      fi -    _ak_ipfs name resolve "$1" -    if [ $? -ne 0 ] +    if [ ! -f $AK_IPNS_ARTIFACTS/$1 ]      then          _ak_log_error "Failed to resolve $1"          exit 1      fi +    cat $AK_IPNS_ARTIFACTS/$1  }  function _ak_ipfs_swarm_peers(){ diff --git a/lib/_ak_log b/lib/_ak_log index 51064e7..d28e663 100755 --- a/lib/_ak_log +++ b/lib/_ak_log @@ -75,6 +75,21 @@ function _ak_log_print_log_line(){      fi  } +function _ak_log_print_log_line_irc(){ +    if [ -n "$1" ] +    then +        timestamp="$(echo "$*" | awk '{print $1}')" +        program="$(echo "$*" | awk '{print $2}')" +        messagetype="$(echo "$*" | awk '{print $3}')" +        message="$(echo "$*" | cut -d ' ' -f4-)" +        printf '\x0300,01%s \x0303,01%s\x0300,01 \x0304,01%s\x0300,01 %s\x0301,00\n' \ +            "$(_ak_datetime_unix_to_human $timestamp)" \ +            "$program" \ +            "$messagetype" \ +            "$message" +    fi +} +  function _ak_log_follow(){      tail -f $AK_LOGSFILE | while read -r p || [ -n "$p" ]      do @@ -144,6 +159,10 @@ function _ak_log_message(){                  then                      _ak_log_print_log_line "$TS <$prg> [$tp] $msg" >&2                  fi +                if [ ! -z $AK_DEBUG_IRC ] && [ -n "$AK_DEBUG_IRC" ] && [ "$AK_DEBUG_IRC" == "yes" ] +                then +                    _ak_log_print_log_line_irc "$TS <$prg> [$tp] $msg" >&2 +                fi              else                      echo "$TS" "<$prg>" "[ERROR]" "No message" >> $AK_LOGSFILE                  if [ "$AK_DEBUG" == "yes" ] diff --git a/lib/_ak_network_incoming b/lib/_ak_network_incoming index 12384a3..cf8920d 100755 --- a/lib/_ak_network_incoming +++ b/lib/_ak_network_incoming @@ -41,54 +41,58 @@ function _ak_network_incoming_show_peers(){  function _ak_network_incoming_scan(){      if [ -f "${AK_ZPEERSINCOMING}" ]      then -    if [ $(cat ${AK_ZPEERSINCOMING}|wc -l) -gt 0 ] -    then -        counter=0 -        count=0 -        _ak_fm_sort_uniq_file ${AK_ZPEERSINCOMING} -        max="$(cat ${AK_ZPEERSINCOMING}|wc -l)" -        printf '[' > walk.aknet -        cat ${AK_ZPEERSINCOMING} \ -            | sort \ -            | uniq \ -            | while read -r uip || [ -n "$uip" ] -        do -            ip="$(_ak_network_utils_pad_ip $uip)" -            count="$(( $count + 1 ))" -            _ak_log_debug "Scanning [${count}/${max}] $ip..." -            node_fs_path="$AK_ZPEERSDIR/inc/$(echo -n $ip| sed 's/://g')" -            scan_ts="$(_ak_datetime_unix)" -            if [ ! -d ${node_fs_path} ] -            then -                mkdir -p ${node_fs_path} -            fi -            node_fs_pathname="${node_fs_path}/${scan_ts}" -            curl \ -                --connect-timeout 3 \ -                -A 'akd/0.1.0; https://github.com/arching-kaos' \ -                "http://[$ip]:8610/v0/node_info" 2>/dev/null | jq -c -M > ${node_fs_pathname} -            node_info="$(cat ${node_fs_pathname})" -            if [ $? -eq 0 ] && [ $(echo -n "$node_info" | wc -c) -gt 0 ] -            then -                if [ "$counter" -ne "0" ] +        if [ $(cat ${AK_ZPEERSINCOMING}|wc -l) -gt 0 ] +        then +            counter=0 +            count=0 +            _ak_fm_sort_uniq_file ${AK_ZPEERSINCOMING} +            max="$(cat ${AK_ZPEERSINCOMING}|grep -v '\.'|wc -l)" +            printf '[' > walk.aknet +            cat ${AK_ZPEERSINCOMING} \ +                | grep -v '\.' \ +                | sort \ +                | uniq \ +                | while read -r uip || [ -n "$uip" ] +            do +                ip="$(_ak_network_utils_pad_ip $uip)" +                count="$(( $count + 1 ))" +                _ak_log_debug "Scanning [${count}/${max}] $ip..." +                node_fs_path="$AK_ZPEERSDIR/inc/$(echo -n $ip| sed 's/://g')" +                scan_ts="$(_ak_datetime_unix)" +                if [ ! -d ${node_fs_path} ]                  then -                    printf ',' >> walk.aknet +                    _ak_log_info "New peer: $ip..." +                    mkdir -p ${node_fs_path}                  fi -                if [ ! -n "$node_info" ] +                node_fs_pathname="${node_fs_path}/${scan_ts}" +                _ak_log_info "Requesting peer's node info: $ip..." +                curl \ +                    --connect-timeout 3 \ +                    -A 'akd/0.1.0; https://github.com/arching-kaos' \ +                    "http://[$ip]:8610/v0/node_info" 2>/dev/null | jq -c -M > ${node_fs_pathname} +                node_info="$(cat ${node_fs_pathname})" +                if [ $? -eq 0 ] && [ $(echo -n "$node_info" | wc -c) -gt 0 ]                  then -                    node_info="null" +                    _ak_log_info "Appending: $ip..." +                    if [ "$counter" -ne "0" ] +                    then +                        printf ',' >> walk.aknet +                    fi +                    if [ ! -n "$node_info" ] +                    then +                        node_info="null" +                    fi +                    printf '{"incoming":{"ip":"%s"},"node_info":%s}' \ +                        "$ip" "$node_info" >> walk.aknet +                    counter="`expr $counter + 1`"                  fi -                printf '{"incoming":{"ip":"%s"},"node_info":%s}' \ -                    "$ip" "$node_info" >> walk.aknet -                counter="`expr $counter + 1`" -            fi -        done -        printf ']' >> walk.aknet -        mv walk.aknet $AK_ZPEERSFILE.incoming -        rm -rf $TEMPDIR -    else -        _ak_log_info "No incoming requests found." -    fi +            done +            printf ']' >> walk.aknet +            mv walk.aknet $AK_ZPEERSFILE.incoming +            rm -rf $TEMPDIR +        else +            _ak_log_info "No incoming requests found." +        fi      fi  } diff --git a/lib/_ak_network_yggdrasil b/lib/_ak_network_yggdrasil index afabe70..5620fae 100755 --- a/lib/_ak_network_yggdrasil +++ b/lib/_ak_network_yggdrasil @@ -71,8 +71,12 @@ function _ak_network_yggdrasil_scan_full(){          if [ ! -d ${node_fs_path} ]          then              mkdir -p ${node_fs_path} +            echo ${scan_ts} > ${node_fs_path}/first_seen +            echo ${scan_ts} > ${node_fs_path}/last_seen +        else +            echo ${scan_ts} > ${node_fs_path}/last_seen          fi -        node_fs_pathname="${node_fs_path}/${scan_ts}" +        node_fs_pathname="${node_fs_path}/${scan_ts}_node_info"          curl \              --connect-timeout 3 \              -A 'akd/0.1.0; https://github.com/arching-kaos' \ @@ -80,6 +84,12 @@ function _ak_network_yggdrasil_scan_full(){          node_info="$(cat ${node_fs_pathname})"          if [ $? -eq 0 ] && [ $(echo -n "$node_info" | wc -c) -gt 0 ]          then +            ni_hash="$(echo -n "${node_info}" | sha512sum | cut -d ' ' -f 1)" +            if [ ! -f "${node_fs_path}/${ni_hash}" ] +            then +                mv ${node_fs_pathname} ${node_fs_path}/${ni_hash} +                echo "${scan_ts} ${ni_hash}" >> ${node_fs_path}/db +            fi              if [ "$counter" -ne "0" ]              then                  printf ',' >> walk.aknet @@ -91,6 +101,8 @@ function _ak_network_yggdrasil_scan_full(){              printf '{"yggdrasil":{"public_key":"%s","ip":"%s"},"node_info":%s}' \                  "$pkey" "$ip" "$node_info" >> walk.aknet              counter="`expr $counter + 1`" +        else +            rm ${node_fs_pathname}          fi      done      printf ']' >> walk.aknet diff --git a/lib/_ak_node b/lib/_ak_node index 5ca8521..937ff84 100755 --- a/lib/_ak_node +++ b/lib/_ak_node @@ -24,7 +24,7 @@ _ak_lib_load _ak_ipfs  # Resolves the IPNS key "ak-config" to its current IPFS value  # Return IPFS CIDv0 without /ipfs/ prefix  function _ak_node_info_ipfs_hash(){ -    _ak_ipfs_name_resolve /ipns/$(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///' +    _ak_ipfs_name_resolve $(_ak_node_info_ipns_key) | sed -e 's/\/ipfs\///'  }  # Finds ak-config ipns key @@ -21,6 +21,7 @@ source $AK_LIBDIR/_ak_lib_load  _ak_lib_load _ak_log  _ak_lib_load _ak_script  _ak_lib_load _ak_gpg +_ak_lib_load _ak_fs  _ak_lib_load _ak_zchain  AK_NS_DIR="${AK_WORKDIR}/akns" @@ -56,33 +57,32 @@ function _ak_ns_list(){  }  function _ak_ns_list_long(){ -    _ak_gpg_list_secret_keys_long | grep '@keynames.kaos.kaos' +    _ak_gpg_list_secret_keys_long \ +        | grep '@keynames.kaos.kaos' \ +        | while read key name +    do +        printf '%s %s %s\n'  "${key}" "$(_ak_ns_encode_key ${key})" "${name}" +    done  } -function _ak_ns_resolve_from_name(){ +function _ak_ns_resolve_from_key(){      # $1; exit;;      if [ -z $1 ] || [ ! -n "$1" ]      then -        _ak_log_error "No name was given" +        _ak_log_error "No key was given"          exit 1      fi -    key_name="$1" -    _ak_log_info "${key_name} was given" -    if [ "${key_name}" == "zchain" ] || [ "${key_name}" == "zconfig" ] +    key="$1" +    _ak_log_info "${key} was given" +    if [ ! -f ${AK_NS_DIR}/${key} ]      then -        _ak_log_info "${key_name} search on local secret keychain" -        key="$(_ak_gpg_list_secret_keys_long | grep ${key_name}'@keynames.kaos.kaos' | cut -d ' ' -f 1)" -        if [ ! -n "${key}" ] -        then -            _ak_log_error "${key_name} was not found locally" -            exit 1 -        fi -        _ak_ns_resolve_from_key ${key} +        _ak_log_error "${key} was not found" +        exit 1      fi -    _ak_not_implemented "${FUNCNAME}" +    _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key}  } -function _ak_ns_resolve_from_key(){ +function _ak_ns_resolve_from_key_with_proof(){      # $1; exit;;      if [ -z $1 ] || [ ! -n "$1" ]      then @@ -91,17 +91,80 @@ function _ak_ns_resolve_from_key(){      fi      key="$1"      _ak_log_info "${key} was given" -    if [ ! -f ${AK_NS_DIR}/${key} ] +    if [ ! -f ${AK_NS_DIR}/${key}.map ]      then          _ak_log_error "${key} was not found"          exit 1      fi -    _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key} -    _ak_not_implemented "${FUNCNAME}" +    cat ${AK_NS_DIR}/${key}.map +} + +function _ak_ns_resolve_from_key_with_proof_json(){ +    # $1; exit;; +    if [ -z $1 ] || [ ! -n "$1" ] +    then +        _ak_log_error "No key was given" +        exit 1 +    fi +    key="$1" +    json=$(_ak_ns_resolve_from_key_with_proof $key | while read proof resolved; do printf '{"fingerprint":"%s","proof":"%s","resolved":"%s"}' "$1" "$proof" "$resolved";  done) +    if [ $? -ne 0 ] +    then +        _ak_log_error "Something happened" +        exit 1 +    fi +    echo $json +} + +function _ak_ns_encode_key(){ +    # $1; exit;; +    if [ -z $1 ] || [ ! -n "$1" ] +    then +        _ak_log_error "No key was given" +        exit 1 +    fi +    key="$1" +    _ak_log_info "${key} was given" +    printf '%s' "$(echo -n ${key}|xxd -r -p|base64)" +} + +function _ak_ns_decode_key(){ +    # $1; exit;; +    if [ -z $1 ] || [ ! -n "$1" ] +    then +        _ak_log_error "No key was given" +        exit 1 +    fi +    key="$1" +    _ak_log_info "${key} was given" +    printf '%s' "$(echo -n ${key}|base64 -d|xxd -p|tr '[:lower:]' '[:upper:]')" +} + +function _ak_ns_resolve_from_name(){ +    # $1; exit;; +    if [ -z $1 ] || [ ! -n "$1" ] +    then +        _ak_log_error "No name was given" +        exit 1 +    fi +    key_name="$1" +    _ak_log_info "${key_name} was given" +    if [ "${key_name}" == "zchain" ] || [ "${key_name}" == "zconfig" ] +    then +        _ak_log_info "${key_name} search on local secret keychain" +        key="$(_ak_gpg_list_secret_keys_long | grep ${key_name}'@keynames.kaos.kaos' | cut -d ' ' -f 1)" +        if [ ! -n "${key}" ] +        then +            _ak_log_error "${key_name} was not found locally" +            exit 1 +        fi +        _ak_ns_resolve_from_key ${key} +    fi  }  function _ak_ns_publish(){      # $1 $2; exit;; +    _ak_not_implemented "${FUNCNAME}"      if [ -z $1 ] || [ ! -n "$1" ]      then          _ak_log_error "No key was given" @@ -134,11 +197,11 @@ function _ak_ns_publish(){      then          _ak_gpg_sign_clear_with_key $key      fi -    _ak_not_implemented "${FUNCNAME}"  }  function _ak_ns_publish2name(){      # $1 $2; exit;; +    _ak_not_implemented "${FUNCNAME}"      if [ -z $1 ] || [ ! -n "$1" ]      then          _ak_log_error "No key name was given" @@ -156,7 +219,6 @@ function _ak_ns_publish2name(){          exit 1      fi      _ak_ns_publish ${key} $2 -    _ak_not_implemented "${FUNCNAME}"  }  function _ak_ns_publish_zchain(){ @@ -169,19 +231,25 @@ function _ak_ns_publish_zchain(){          _ak_ns_create zchain      fi      zchain_key="$(_ak_gpg_list_secret_keys_long | grep 'zchain@keynames.kaos.kaos' | cut -d ' ' -f 1)" -    # We need to prepare the file now to be signed -    # Put the zlatest into a file      zlatest_file="$(_ak_make_temp_file)"      echo -n ${zlatest} > ${zlatest_file}      zlatest_csigned_file="$(_ak_make_temp_file)" -    _ak_gpg_sign_clear_with_key ${zlatest_csigned_file} ${zlatest_file} ${zchain_key}  -    # What to do now with the clear signed file? +    _ak_gpg_sign_clear_with_key ${zlatest_csigned_file} ${zlatest_file} ${zchain_key}      if [ -f ${AK_NS_DIR}/${zchain_key} ]      then          _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zchain_key} >> ${AK_NS_DIR}/${zchain_key}.history      fi +    signed_akfs_map=$(_ak_fs_import ${zlatest_csigned_file}) +    if [ -f ${AK_NS_DIR}/${zchain_key}.map ] +    then +        printf '%s %s\n' "$(echo -n $signed_akfs_map)" \ +            "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zchain_key})" \ +            >> ${AK_NS_DIR}/${zchain_key}.history_map +    fi      mv ${zlatest_csigned_file} ${AK_NS_DIR}/${zchain_key} -    # _ak_not_implemented "${FUNCNAME}" +    printf '%s %s\n' "$(echo -n $signed_akfs_map)" \ +        "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zchain_key})" \ +        > ${AK_NS_DIR}/${zchain_key}.map  }  function _ak_ns_publish_config(){ @@ -194,19 +262,103 @@ function _ak_ns_publish_config(){          _ak_ns_create zconfig      fi      zconfig_key="$(_ak_gpg_list_secret_keys_long | grep 'zconfig@keynames.kaos.kaos' | cut -d ' ' -f 1)" -    # We need to prepare the file now to be signed -    # Put the zlatest into a file      zconfig_file="$(_ak_make_temp_file)"      echo -n ${zconfig} > ${zconfig_file}      zconfig_csigned_file="$(_ak_make_temp_file)" -    _ak_gpg_sign_clear_with_key ${zconfig_csigned_file} ${zconfig_file} ${zconfig_key}  -    # What to do now with the clear signed file? +    _ak_gpg_sign_clear_with_key ${zconfig_csigned_file} ${zconfig_file} ${zconfig_key}      if [ -f ${AK_NS_DIR}/${zconfig_key} ]      then          _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zconfig_key} >> ${AK_NS_DIR}/${zconfig_key}.history      fi +    signed_akfs_map=$(_ak_fs_import ${zconfig_csigned_file}) +    if [ -f ${AK_NS_DIR}/${zconfig_key}.map ] +    then +        printf '%s %s\n' "$(echo -n $signed_akfs_map)" \ +            "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zconfig_key})" \ +            >> ${AK_NS_DIR}/${zconfig_key}.history_map + +    fi      mv ${zconfig_csigned_file} ${AK_NS_DIR}/${zconfig_key} -    # _ak_not_implemented "${FUNCNAME}" +    printf '%s %s\n' "$(echo -n $signed_akfs_map)" \ +        "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${zconfig_key})" \ +        > ${AK_NS_DIR}/${zconfig_key}.map +} + +function _ak_ns_resolve_all_keys(){ +    tmpdir="$(_ak_make_temp_directory)" +    cd $tmpdir +    _ak_log_info "Looking at local IPs..." +    ip a | grep inet6 | sed 's/ *inet6 //g' | cut -d '/' -f 1 > ip_list +    ak network -p incoming 2>/dev/null| jq -r '.[].incoming.ip' | while read ip +    do +        if [ $ip != "null" ] +        then +            echo $ip +        fi +    done > peer_list +    _ak_log_info "Filtering IPs out of locals..." +    cat ip_list | while read ip +    do +        sed -i 's/^'$ip'$//g' peer_list +    done +    if [ $(cat peer_list | wc -l) -eq 0 ] +    then +        _ak_log_error "No IPs to scan from" +        exit 1 +    fi +    cat peer_list | while read ip +    do +        _ak_log_info "Extracing keys from $ip..." +        ak network -p incoming \ +            | jq --arg ip "$ip" '.[] | select(.incoming.ip == $ip )' \ +            | jq '.node_info.keymaps.[]'> keymaps_list.$ip +    done +    cat peer_list | while read ip +    do +        if [ "$ip" != "null" ] && [ ! -z "$ip" ] +        then +            _ak_log_info "Looking at peer $ip" +            if [ -f "keymaps_list.$ip" ] +            then +                cat keymaps_list.$ip | jq -r '.fingerprint' | while read key +                do +                    map="$(cat keymaps_list.$ip | jq -r 'select(.fingerprint == "'$key'")|.map')" +                    ak fs --net-cat-from-map $map > $key +                    ak fs --import $key +                    ak gpg -r --import $key +                    curl -s http://[$ip]:8610/v0/ns_get/$key > $key.reply +                    proof="$(cat $key.reply | jq -r '.proof')" +                    resolved="$(cat $key.reply | jq -r '.resolved')" +                    key="$(cat $key.reply | jq -r '.key')" +                    ak fs --net-cat-from-map $proof > $key.proof +                    _ak_gpg_verify_clear_signature $key.proof +                    if [ $? -ne 0 ] +                    then +                        _ak_log_error "Couldn't verify" +                        exit 1 +                    fi +                    if [ -f ${AK_NS_DIR}/${key} ] +                    then +                        _ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key} >> ${AK_NS_DIR}/${key}.history +                    fi +                    signed_akfs_map=$(_ak_fs_import ${key}.proof) +                    if [ -f ${AK_NS_DIR}/${key}.map ] +                    then +                        printf '%s %s\n' "$(echo -n $signed_akfs_map)" \ +                            "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key})" \ +                            >> ${AK_NS_DIR}/${key}.history_map + +                    fi +                    mv ${key}.proof ${AK_NS_DIR}/${key} +                    printf '%s %s\n' "$(echo -n $proof)" \ +                        "$(_ak_gpg_verify_clear_signature ${AK_NS_DIR}/${key})" \ +                        > ${AK_NS_DIR}/${key}.map +                done +                _ak_log_info "Finished peer $ip" +            fi +        fi +    done +    _ak_log_info "Finished resolving"  }  _ak_log_debug "_ak_ns loaded $(caller)" diff --git a/lib/_ak_script b/lib/_ak_script index 02741cb..241c182 100755 --- a/lib/_ak_script +++ b/lib/_ak_script @@ -86,11 +86,23 @@ function _ak_title_description(){  }  function _ak_usage(){ -    ( -        _ak_title_description 2>&1 -        _ak_license 2>&1 -        _ak_help 2>&1 -    ) | sed 's/^/# /g' | while read line; do _ak_log_info "${line}"; done +    if [ ! -z $1 ] && [ -n "$1" ] && [ "$1" == "err" ] +    then +        ( +            _ak_title_description 2>&1 +            _ak_license 2>&1 +            _ak_help 2>&1 +        # ) | sed 's/^/# /g' | while read line; do _ak_log_info "${line}"; done +        ) 1>&2 +        exit 1 +    else +        ( +            _ak_title_description 2>&1 +            _ak_license 2>&1 +            _ak_help 2>&1 +        # ) | sed 's/^/# /g' | while read line; do _ak_log_info "${line}" 2>&1; done +        ) +    fi  }  function _ak_print_version(){  | 
