From bd179055cd591fa47f4be21cc08f71195656f789 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Wed, 7 Sep 2022 13:29:51 +0300 Subject: Added some checks to make sure zblocks are zblocks and blocks are blocks --- bin/enter | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/bin/enter b/bin/enter index 74d1bcc..4bb7ede 100755 --- a/bin/enter +++ b/bin/enter @@ -137,7 +137,33 @@ do # We concatenate the zblock's contents, pipe them through filter # json2bash and output them to tmp-file ipfs cat $zblock | json2bash > $TEMPASSIN/tmp-zblock - logthis "[INFO]" "ZBLOCK $zblock READ" + if [ "$?" == 0 ] + then + logthis "[INFO]" "ZBLOCK $zblock READ" + else + logthis "[ERROR]" "ZBLOCK $zblock READ failed" + exit 1 + fi + + # Be sure that there are the expected values + # We need 'block' and 'block_signature' inside a 'zblock' + # Exit if any is missing + grep -e 'block_signature' $TEMPASSIN/tmp-zblock > /dev/null 2>&1 + if [ "$?" == 0 ] + then + logthis "[INFO]" "ZBLOCK $zblock has block_signature" + else + logthis "[ERROR]" "ZBLOCK $zblock has no block_signature" + exit 1 + fi + grep -e 'block=' $TEMPASSIN/tmp-zblock > /dev/null 2>&1 + if [ "$?" == 0 ] + then + logthis "[INFO]" "ZBLOCK $zblock has block" + else + logthis "[ERROR]" "ZBLOCK $zblock has no block" + exit 1 + fi # Supposingly you are on a safe environment and you only have # access to your chain, I would consider mild secure to source @@ -150,6 +176,23 @@ do # BLOCKS echo '"block":"'$block'",' ipfs cat $block | json2bash > $TEMPASSIN/tmp-block + if [ "$?" == 0 ] + then + logthis "[INFO]" "BLOCK $block READ" + else + logthis "[ERROR]" "BLOCK $block READ failed" + exit 1 + fi + + grep -e 'timestamp' -e 'gpg' -e 'data' -e 'action' -e 'detach' -e 'previous' $TEMPASSIN/tmp-block > /dev/null 2>&1 + if [ "$?" == 0 ] + then + logthis "[INFO]" "BLOCK $block is a block" + else + logthis "[ERROR]" "BLOCK $block is NOT a valid block" + exit 1 + fi + source $TEMPASSIN/tmp-block logthis "[INFO]" "BLOCK $block SOURCED" touch $BLOCKDIR/$block @@ -184,7 +227,7 @@ do logthis "[ERROR]" "Could not get GPG key: $gpg ." exit 1 fi - ipfs get $block_signature > /dev/null 2>&1 + ipfs get $block_signature > /dev/null 2>&1 if [ "$?" == 0 ] then mv $block_signature $block.asc -- cgit v1.2.3