From 7eb5ae99f0ea193b32224048f493443f6505240f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 17 Jun 2013 10:48:06 +0200 Subject: jsaccess: store.sh readability no functional change --- jsaccess/store.sh | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'jsaccess') diff --git a/jsaccess/store.sh b/jsaccess/store.sh index 71a42c2..ec4d167 100755 --- a/jsaccess/store.sh +++ b/jsaccess/store.sh @@ -24,36 +24,42 @@ cleanup() { } if [ $# -ne 1 ]; then - echo "usage: store.sh " + echo "usage: store.sh " exit 1 fi -myfile=$1 -myfilename=`basename $myfile` +clear_path=$1 +clear_name=`basename $clear_path` +# Initialize temporary stuff sumask=$(umask) umask 077 tmp=`mktemp ./jsaXXXXXXXX` trap cleanup INT TERM EXIT -echo -n "Enter passphrase used to encrypt: " +# Read passphrase +echo -n "Enter encryption passphrase: " read pass -dirhash=`echo -n $pass |openssl rmd160 |cut -d' ' -f2` -dir="jsa/files/$dirhash" -file=`echo -n ${dirhash}${myfilename} |openssl rmd160 |cut -d' ' -f2` -echo $dir -mkdir -p $dir -touch $dir/index.html - -base64 -w0 $myfile > $tmp -echo -n $pass |openssl enc -e -a -aes-256-cbc -in $tmp -out $dir/$file -pass stdin ||exit $? -echo "CREATED $dir/$file" - -if [ -f $dir/index.txt ]; then - echo -n $pass |openssl enc -d -a -aes-256-cbc -in $dir/index.txt -out $tmp -pass stdin ||exit $? + +# Generate file/directory names +enc_dir_hash=`echo -n $pass |openssl rmd160 |cut -d' ' -f2` +enc_path="jsa/files/$enc_dir_hash" +enc_name=`echo -n ${enc_dir_hash}${clear_name} |openssl rmd160 |cut -d' ' -f2` +echo $enc_path +mkdir -p $enc_path +touch $enc_path/index.html + +# Encrypt file +base64 -w0 $clear_path > $tmp +echo -n $pass |openssl enc -e -a -aes-256-cbc -in $tmp -out $enc_path/$enc_name -pass stdin ||exit $? +echo "CREATED $enc_path/$enc_name" + +# Add to passphrase index +if [ -f $enc_path/index.txt ]; then + echo -n $pass |openssl enc -d -a -aes-256-cbc -in $enc_path/index.txt -out $tmp -pass stdin ||exit $? else echo > $tmp fi -echo $myfilename >> $tmp -rm -f $dir/index.txt -echo -n $pass |openssl enc -e -a -aes-256-cbc -in $tmp -out $dir/index.txt -pass stdin ||exit $? -echo "UPDATED $dir/index.txt" +echo $clear_name >> $tmp +rm -f $enc_path/index.txt +echo -n $pass |openssl enc -e -a -aes-256-cbc -in $tmp -out $enc_path/index.txt -pass stdin ||exit $? +echo "UPDATED $enc_path/index.txt" -- cgit v1.2.3-59-g8ed1b