From 3b14cd914f3b2acf93a686ab089ea60fe8a0c82c Mon Sep 17 00:00:00 2001 From: Hubert Kario Date: Sat, 11 Oct 2014 13:42:48 +0200 Subject: [PATCH] no need to grep the input when we're using awk (v2) awk has an inbuilt version of grep, also truncate processing as soon as we find what we're looking for This version uses slightly different syntax that is compatible with old awk --- cipherscan | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cipherscan b/cipherscan index 3990ea6..c2c1a5b 100755 --- a/cipherscan +++ b/cipherscan @@ -129,20 +129,21 @@ test_cipher_on_target() { tmp=$(awk 'BEGIN { pr="yes" } /^======================================/ { if ( pr=="yes" ) pr="no"; else pr="yes" } { if ( pr == "yes" ) print }' <<<"$tmp") # session metadata - current_cipher=$(grep "New, " <<<"$tmp"|awk '{print $5}') - current_pfs=$(grep 'Server Temp Key' <<<"$tmp"|awk '{print $4$5$6$7}') - current_protocol=$(egrep "^\s+Protocol\s+:" <<<"$tmp"|awk '{print $3}') - current_tickethint=$(grep 'ticket lifetime hint' <<<"$tmp"|awk '{print $6 }') + current_cipher=$(awk '/New, / {print $5; exit}' <<<"$tmp") + current_pfs=$(awk '/Server Temp Key/ {print $4$5$6$7; exit}' <<<"$tmp") + current_protocol=$(awk '/^ +Protocol +:/ {print $3; exit}' <<<"$tmp") + current_tickethint=$(awk '/ticket lifetime hint/ {print $6; exit}' <<<"$tmp") if [ -z $current_tickethint ]; then current_tickethint=None fi # certificate metadata - current_pubkey=$(grep 'Server public key is ' <<<"$tmp"|awk '{print $5}') + current_pubkey=$(awk '/Server public key is / {print $5;exit}' <<<"$tmp") if [ -z $current_pubkey ]; then current_pubkey=0 fi - current_sigalg=$(${OPENSSLBIN} x509 -noout -text 2>/dev/null <<<"$tmp"|grep Signature\ Algorithm | head -n 1 | awk '{print $3}') || current_sigalg="None" + current_sigalg=$(${OPENSSLBIN} x509 -noout -text 2>/dev/null <<<"$tmp"|\ + awk '/Signature Algorithm/ {print $3; exit}') || current_sigalg="None" grep 'Verify return code: 0 ' <<<"$tmp" >/dev/null if [ $? -eq 0 ]; then current_trusted="True"