From: Scott Worley Date: Tue, 24 Oct 2017 13:49:52 +0000 (-0700) Subject: keyline() and keyfield() operations X-Git-Url: http://git.scottworley.com/overonion/commitdiff_plain/HEAD?ds=sidebyside keyline() and keyfield() operations Rather than messy sed invocations --- diff --git a/overonion b/overonion index e7634e2..50d1958 100755 --- a/overonion +++ b/overonion @@ -47,25 +47,33 @@ else fi fi +function keyline() { + awk -vline="$1" 'NR == line' "$keyfile" +} + +function keyfield() { + awk -vline="$1" -vfield="$2" 'NR == line { print $field }' "$keyfile" +} + function go() { layer=$1 if (( layer == 0 || layer > num_layers ));then cat else - operation=$(sed -n "${layer}{;s/ .*//;p;}" "$keyfile") + operation=$(keyfield "$layer" 1) if [[ "$operation" == openssl-enc ]];then - openssl enc $openssl_decrypt "-$(sed -rn "${layer}s/[^ ]+ ([^ ]+) .*/\\1/p" "$keyfile")" \ - -nosalt -pass fd:37 37< <(sed -rn "${layer}s/^[^ ]+ [^ ]+ //p" "$keyfile") + openssl enc $openssl_decrypt "-$(keyfield "$layer" 2)" \ + -nosalt -pass fd:37 37< <(keyfield "$layer" 3) elif [[ "$operation" == reverse ]];then - reverse + "$(dirname "$0")/reverse" elif [[ "$operation" == openssl-dgst ]];then - tee >(echo "$(sed -n "${layer}p" "$keyfile") $( + tee >(echo "$(keyline "$layer") $( { - awk -vlayer="$layer" 'NR == layer { print $3 }' "$keyfile" | base64 -d + keyfield "$layer" 3 | base64 -d cat - awk -vlayer="$layer" 'NR == layer { print $4 }' "$keyfile" | base64 -d + keyfield "$layer" 4 | base64 -d } | - openssl dgst -binary "-$(sed -rn "${layer}s/^[^ ]+ ([^ ]+).*/\\1/p" "$keyfile")" | + openssl dgst -binary "-$(keyfield "$layer" 2)" | base64 --wrap=0)" > "$hash_dir/$layer") else die "Unknown operation"