aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-06-19 03:58:06 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-06-19 03:58:06 +0200
commit1f49f514ce5b2d3ec3a90950327495ff347bb8d6 (patch)
tree1a94601d34a94b96f03e68926b9b9815ff01997d
parentjsaccess: add some precisions on unencrypted files (diff)
downloadlaurent-tools-1f49f514ce5b2d3ec3a90950327495ff347bb8d6.tar.xz
laurent-tools-1f49f514ce5b2d3ec3a90950327495ff347bb8d6.zip
jsaccess: non-encrypted files are now stored with real name
also improve unittest coverage
-rw-r--r--jsaccess/jsa/jsa.js5
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d30
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt6
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt (renamed from jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/73ea4d1019b8f50af4ba29b65d8b9dd2b0129152)0
-rwxr-xr-xjsaccess/jstore.sh31
-rw-r--r--jsaccess/tests/Makefile3
-rwxr-xr-xjsaccess/tests/test_store.sh30
7 files changed, 66 insertions, 39 deletions
diff --git a/jsaccess/jsa/jsa.js b/jsaccess/jsa/jsa.js
index f423533..b94d4e2 100644
--- a/jsaccess/jsa/jsa.js
+++ b/jsaccess/jsa/jsa.js
@@ -129,15 +129,18 @@ function _dl(file, pass) {
var dirhash = RMD160.hex(pass);
var crypt = file.split(" ").pop();
var filename = file.substring(0, file.lastIndexOf(" "));
- var path = 'store/' + dirhash + '/' + RMD160.hex(dirhash + filename);
_status("Downloading \""+filename+"\" ...");
+ /* File is not encrypted */
if (crypt == '(nocrypt)') {
+ var path = 'store/' + dirhash + '/' + filename;
_status("File is in your hands,<br/>Have a good day.<br/>");
window.location = path;
return;
}
+ /* File is encrypted */
+ var path = 'store/' + dirhash + '/' + RMD160.hex(dirhash + filename);
dlreq = $.ajax({
url: path,
beforeSend: function ( xhr ) {
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d
index f7d0ab5..08e189f 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d
@@ -1,15 +1,15 @@
-U2FsdGVkX1+IILGA9muHwJcJAF1DEOSbqp+nv+Ek3ELUzfNWE8Hyv2Ca9byYYvsF
-tXskVJkjF5geU63fZhhEpTFjlLoSSjA2itPb3M+i8GFdi1B/P/zjWdeaY3zNGLEG
-bIRYFjjcTfaMRcDOX1qnPYt7PlrUKFDr8MRWMaUNeW80T3guzQAO4LQmywQaxN9q
-OeLdbC+xfrEzOEjnXBJB2pAycdKwIu5bj4+A1L1Ue1HS1yWQEkmyy39Bx+kF+kuo
-kDKlWwW50rJ7pMn5qMJ1q21zqFz+RWncBGQ++aGA26GRiCVWgkKg1qfnW8bwppcH
-NEYs5+z9FQ9UvMaj0xWeMMTYDi/7b4FuxlBDHS/RoOXqebGA1bRNQuyTmyQMCXh7
-zkGD28Yu0wlf8y02ZEDU/HIWsZ6kUvCKrIYb9sQeuOn8Q+4VNFtyrZgvDDdYsXqJ
-1dHt+T29a0/ngJZDxEgkX+fWckZgXhhdpK9g6sP9rIHlN5/hfjTOl1TYcy7nmA1E
-NBwxHzB9jEeSLZMKVqokhK+AiFEh2lFTnnL/KJFTGqD7uwFIY0pMlAUK/ehU11O3
-qEUn7260sl9OQt7OXCVDCLqC9o1bl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g3TVs7j3akGkdCkMJP9vd/OIwryTp4AMxLQcH3+eLNqYQHnAZj
+ItywZV/YHoHFqwauLp3gd7LtpGWpQxzlTR/DRJ5w0FyT/YjCHSNjpA0Z8x3Gc7sj
+r0YKf9P+aiVkMPWyzeO7zy2H3nq1BdK68UFrZsvabxmik29Fbr5eoxQxWAuiV9fZ
+jq0pMP/BqCTADf0/OtS8yA==
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
index 937c5b8..54ef0bc 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
@@ -1,3 +1,3 @@
-U2FsdGVkX19MjpOkiPV7d4UQ7LZAH0u8xje4cMWT81soFDxm9qu3hoGSS+Or9jcw
-bZ0Gr0etELJlh+PJkRXt5YRuhIaU3j9/H2wx7PhI1uOlOpJM43W/kZvgRqsg1N54
-/6MF8yFrLs6xPh+vs3s/Uw==
+U2FsdGVkX180j1V/ivNwX/s+ZkY+ZktkUYpxqULOrxBTbntiAwDQByTA3C/wz/5z
+FTZ6nZ16FZMtYMUMKzRGk8sZSWavllojRCwmNasm//zEHDrP8dllegKWIX4vsLbd
+jad0n9JqKwv9csyhKSE4tQ==
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/73ea4d1019b8f50af4ba29b65d8b9dd2b0129152 b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt
index 63a621d..63a621d 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/73ea4d1019b8f50af4ba29b65d8b9dd2b0129152
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt
diff --git a/jsaccess/jstore.sh b/jsaccess/jstore.sh
index c7f0c04..2492748 100755
--- a/jsaccess/jstore.sh
+++ b/jsaccess/jstore.sh
@@ -19,6 +19,8 @@
VERSION=0.2
+PROHIBITED_FILE_NAMES="index.html index.txt"
+
usage_exit() {
echo "jsaccess jstore.sh v$VERSION"
echo "usage: jstore.sh [-v] [action] [action arguments...] [store]"
@@ -137,17 +139,24 @@ _file_add() {
if [ $do_crypt -eq 1 ]; then
base64 -w0 $clear_path > $tmp ||clean_exit 2
echo -n $pass |openssl enc -e -a -aes-256-cbc -in $tmp -out $enc_path/$enc_name -pass stdin ||clean_exit 2
+ echo "CREATED file $enc_path/$enc_name"
else
- cp $clear_path $enc_path/$enc_name
+ cp $clear_path $enc_path/$clear_name
+ echo "CREATED file $enc_path/$clear_name"
fi
- echo "CREATED file $enc_path/$enc_name"
}
_file_rm() {
clear_name=$1
- __file_get_encname $clear_name
- rm $enc_path/$enc_name ||clean_exit 1
- echo "DELETED file $enc_path/$enc_name"
+ do_crypt=$2
+ if [ $do_crypt -eq 1 ]; then
+ __file_get_encname $clear_name
+ rm $enc_path/$enc_name ||clean_exit 1
+ echo "DELETED file $enc_path/$enc_name"
+ else
+ rm $enc_path/$clear_name ||clean_exit 1
+ echo "DELETED file $enc_path/$clear_name"
+ fi
}
_rset() {
@@ -180,6 +189,10 @@ action_add() {
clear_path=$1
do_crypt=$2
clear_name=`basename $clear_path`
+ [ `echo $PROHIBITED_FILE_NAMES |grep -c "\<$clear_name\>"` -ne 0 ] && \
+ echo "ERROR: file name $clear_name is prohibited, sorry" && \
+ echo -e "Prohibited names list : $PROHIBITED_FILE_NAMES" && \
+ clean_exit 1
_pass_read
_index_decrypt
if [ `egrep -c "^$clear_name .*$" $tmp` -ne 0 ]; then
@@ -201,11 +214,15 @@ action_rm() {
clear_name=$1
_pass_read
_index_decrypt
- if [ `egrep -c "^$clear_name .*$" $tmp` -eq 0 ]; then
+ index_entry=`egrep "^$clear_name .*$" $tmp 2>/dev/null`
+ if [ X"$index_entry" = X"" ]; then
echo "File does not exist for this passphrase"
clean_exit 1
fi
- _file_rm $clear_name
+ crypt=`echo $index_entry |awk '{ print $(NF) }'`
+ [ $crypt = "(nocrypt)" ] && do_crypt=0 || do_crypt=1
+ echo "XXX do_crypt=$do_crypt ($crypt)"
+ _file_rm $clear_name $do_crypt
_index_decrypt
sed -i /"^$clear_name .*$"/d $tmp
_index_encrypt
diff --git a/jsaccess/tests/Makefile b/jsaccess/tests/Makefile
index b282017..836929c 100644
--- a/jsaccess/tests/Makefile
+++ b/jsaccess/tests/Makefile
@@ -1,6 +1,5 @@
all:
- rm -rf store/
- rm -rf clone_store/
+ rm -rf store/ store_clone/ store_push/
./test_store.sh
@echo
@echo "ALL TESTS OK"
diff --git a/jsaccess/tests/test_store.sh b/jsaccess/tests/test_store.sh
index 70e44f5..653c6e8 100755
--- a/jsaccess/tests/test_store.sh
+++ b/jsaccess/tests/test_store.sh
@@ -19,14 +19,11 @@ echo "=== LOCAL ==="
$jstoresh add example.txt ||exit 10
[ -d ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/ ] ||exit 11
[ -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 12
-
$jstoresh ls > $TMP ||exit 20
[ `grep -c "example.txt" $TMP` -eq 1 ] || exit 21
rm $TMP
-
$jstoresh rm example.txt ||exit 30
[ ! -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 31
-
$jstoresh ls > $TMP ||exit 40
[ `grep -c "example.txt" $TMP` -eq 0 ] || exit 41
rm $TMP
@@ -34,25 +31,36 @@ rm $TMP
$jstoresh add example.txt ||exit 50
[ -d ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/ ] ||exit 51
[ -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 52
-
$jstoresh rmall ||exit 60
[ ! -d ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/ ] ||exit 61
-$jstoresh add example.txt ||exit 70
+$jstoresh add-nocrypt example.txt ||exit 70
[ -d ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/ ] ||exit 71
-[ -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 72
+[ -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/example.txt ] ||exit 72
+$jstoresh rm example.txt ||exit 80
+[ ! -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/example.txt ] ||exit 81
+$jstoresh ls > $TMP ||exit 90
+[ `grep -c "example.txt" $TMP` -eq 0 ] || exit 91
+rm $TMP
+
+$jstoresh add example.txt ||exit 95
+[ -d ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/ ] ||exit 96
+[ -f ./store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 97
echo
echo "=== DEPLOY ==="
-$jstoresh rset clone_store ||exit 100
-echo clone_store |diff -u - ./store/.rsync_uri ||exit 101
+$jstoresh rset store_push ||exit 100
+echo store_push |diff -u - ./store/.rsync_uri ||exit 101
$jstoresh rget > $TMP ||exit 110
-[ `grep -c "rsync_uri: clone_store" $TMP` -eq 1 ] || exit 21
+[ `grep -c "rsync_uri: store_push" $TMP` -eq 1 ] || exit 21
$jstoresh push ||exit 120
-[ -f ./clone_store/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 121
+[ -f ./store_push/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 121
+
+$jstoresh clone store/ store_clone ||exit 130
+[ -f ./store_clone/ad2c5eb7c4fca722235f5df80e11fa619adbd533/8e895f3f4317fb442747a40b9025d6ad8c9c8cf3 ] ||exit 131
echo
echo "=== WIPE ==="
@@ -60,7 +68,7 @@ echo "=== WIPE ==="
$jstoresh wipe store ||exit 200
[ ! -d store ] ||exit 201
-rm -rf ./clone_store/
+rm -rf ./store_clone/ ./store_push/
rm $TMP
echo