aboutsummaryrefslogtreecommitdiffstats
path: root/jsaccess
diff options
context:
space:
mode:
Diffstat (limited to 'jsaccess')
-rwxr-xr-xjsaccess/store.sh48
1 files changed, 27 insertions, 21 deletions
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 <myfile>"
+ echo "usage: store.sh <file_to_share>"
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"