#4 - Adding ignore hash

This commit is contained in:
Frank Bischof 2024-04-17 12:17:09 +02:00
parent 9ba397e477
commit d66ca83f95
2 changed files with 20 additions and 13 deletions

View File

@ -1,7 +1,7 @@
# Crypter # Crypter
Script to encrypt and decrypt files easily using openssl. Script to encrypt and decrypt files easily using openssl.
## Howto ## Howto
./crypter.sh -[e/d] [inputfile] --no-verify ./crypter.sh -[e/d] inputfile [--no-verify]
### Options ### Options
-e for encrypt - Encrypts the filename and adds a hash file. -e for encrypt - Encrypts the filename and adds a hash file.
-d for decrypt - Decrypts the file and removes crypt files after hash check. -d for decrypt - Decrypts the file and removes crypt files after hash check.

View File

@ -12,7 +12,7 @@ then
exit 2 exit 2
fi fi
else else
echo "Usage: ./crypter.sh -[e/d] [inputfile]"; echo "Usage: ./crypter.sh -[e/d] inputfile [--no-verify]";
exit 1 exit 1
fi fi
@ -42,7 +42,7 @@ case "$1" in
else else
# NOK - remove empty output file # NOK - remove empty output file
echo "CRITICAL - Output file ${OUTPUT} is 0 bytes! Not removing the source file ${INPUT}" echo "CRITICAL - Output file ${OUTPUT} is 0 bytes! Not removing the source file ${INPUT}"
rm -f ${OUTPUT} ${INPUT}.hash rm -f ${OUTPUT} ${OUTPUT}.hash
exit 2 exit 2
fi fi
;; ;;
@ -53,6 +53,8 @@ case "$1" in
openssl enc -d ${ALGOS} -in ${INPUT}.temp -out ${OUTPUT} > /dev/null 2>&1 openssl enc -d ${ALGOS} -in ${INPUT}.temp -out ${OUTPUT} > /dev/null 2>&1
rm -f ${INPUT}.temp rm -f ${INPUT}.temp
if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ] if [ "`stat ${OUTPUT} | grep Size | awk '{ print $2}'`" != 0 ]
then
if [ "$3" != '--no-verify' ]
then then
# SHA256SUM CHECK # SHA256SUM CHECK
CUR_HASH=$(sha256sum --quiet --check ${OUTPUT}.crypt.hash) CUR_HASH=$(sha256sum --quiet --check ${OUTPUT}.crypt.hash)
@ -68,6 +70,11 @@ case "$1" in
rm -f ${INPUT} ${INPUT}.hash rm -f ${INPUT} ${INPUT}.hash
exit 0 exit 0
fi fi
else
echo "Ignoring hash verify"
rm -f ${INPUT} ${INPUT}.hash
fi
else else
# NOK - remove empty output file # NOK - remove empty output file
echo "CRITICAL - Output file is 0 bytes! Not removing the input file" echo "CRITICAL - Output file is 0 bytes! Not removing the input file"