aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-06-19 12:11:19 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-06-19 12:11:19 +0200
commit84f5de439d5308d717b2514789a967d5f8b6d32b (patch)
treece6b31ce0736ebe49ab485584527bbc7c0baf998
parentjsaccess: remove extra debug (diff)
downloadlaurent-tools-84f5de439d5308d717b2514789a967d5f8b6d32b.tar.xz
laurent-tools-84f5de439d5308d717b2514789a967d5f8b6d32b.zip
jsaccess: show file size
and record in index nicer metadata format / writing / reading
-rw-r--r--jsaccess/jsa/jsa.js32
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d31
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt6
-rw-r--r--jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt7
-rwxr-xr-xjsaccess/jstore.sh64
5 files changed, 90 insertions, 50 deletions
diff --git a/jsaccess/jsa/jsa.js b/jsaccess/jsa/jsa.js
index b94d4e2..9f1cb9e 100644
--- a/jsaccess/jsa/jsa.js
+++ b/jsaccess/jsa/jsa.js
@@ -100,6 +100,14 @@ function jsadl() {
/* ===== PRIVATE - called within this javascript file ===== */
+function _index_read(file) {
+ var name = file.substring(0, file.lastIndexOf(" "));
+ var meta = file.split(" ").pop().replace("(", "").replace(")", "");
+ var size = meta.split(",")[0];
+ var crypt = meta.split(",")[1];
+ return {name: name, size: size, crypt: crypt};
+}
+
function _showfiles(data, pass, hash) {
try {
var decrypted = GibberishAES.dec(data, pass);
@@ -113,11 +121,12 @@ function _showfiles(data, pass, hash) {
$.each(lines,
function( idx, obj ){
obj = obj.trim();
- var filename = obj.substring(0, obj.lastIndexOf(" "));
- var crypt = obj.split(" ").pop();
- if (crypt == '(nocrypt)')
- filename += ' (c)';
- var btn = $('<label><input type="radio" name="file" value="'+obj+'">'+filename+'</input></label><br/>');
+ var meta = _index_read(obj);
+ console.log(meta);
+ extra = "";
+ if (meta.crypt == 'nocrypt')
+ extra = " (c)";
+ var btn = $('<label><input type="radio" name="file" value="'+obj+'">'+meta.name+' ['+meta.size+']'+extra+'</input></label><br/>');
btn.appendTo('#files');
});
$("input:radio[name=file]:first").attr('checked', true);
@@ -127,20 +136,19 @@ function _dl(file, pass) {
var RMD160 = new Hashes.RMD160;
var dirhash = RMD160.hex(pass);
- var crypt = file.split(" ").pop();
- var filename = file.substring(0, file.lastIndexOf(" "));
- _status("Downloading \""+filename+"\" ...");
+ var meta = _index_read(file);
+ _status("Downloading \""+meta.name+"\" ...");
/* File is not encrypted */
- if (crypt == '(nocrypt)') {
- var path = 'store/' + dirhash + '/' + filename;
+ if (meta.crypt == 'nocrypt') {
+ var path = 'store/' + dirhash + '/' + meta.name;
_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);
+ var path = 'store/' + dirhash + '/' + RMD160.hex(dirhash + meta.name);
dlreq = $.ajax({
url: path,
beforeSend: function ( xhr ) {
@@ -148,7 +156,7 @@ function _dl(file, pass) {
},
success: function ( data ) {
_status("Download complete, decrypting ...",
- function() { _decrypt(data, pass, filename); });
+ function() { _decrypt(data, pass, meta.name); });
},
error: function (xhr, opts, err) {
_status("Dowload failed (status="+xhr.status+")");
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d
index 08e189f..bc864b8 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/caf3eefc85fc7c4ee06d38ea679318114b21d88d
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15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LJ
+gVqoUXbrh0XbhRb/+Kmt73eLmhgtUHbBYCG6SRxKfqEgAZdIwyF93Qfnzr16TIN0
+w9HUYkigssKrHX17YuQC2aKkqgCkLqj5z8/mWqWc3ckSORnjTtWKyGkwU4judUUk
+bCVgpVPs80JxUX37ellJ2CLrGAtzWole/bJTHht3Jtl6+r5jjSCXj9SNtgm8+fiy
+UHJdMImIg63p0GEZVjMb7aQMNdk+nEv7220sHSOd+hizSuU8d2z+Q7xxN+R0/REY
+1q0BUSPKxH23vcj4hDsVm7TWvk4dqHBZvjzbZwZqh2d0X6fBKEptzR93g2I2OgyP
+VbbO1oFFYiwQUZnA59vM6p04VBSCdh7p0A0wCk1muHQOmvmXa31Yttk1+0jMfEth
+4TvaPs09luPXH0lo+RWOG+g9T5OU+NZyB2xFWlzHPJz/tQkGar2qTgyRGm3aT+0P
+MZZkbDBdf385FOZczBYvx1f6CITCA8g37T4Ri1+ctCIlgwS7F/EN3daP/Wx9zoKi
+i/8bBe4yY5eCjS6CrBfB+jhFk3xd5+hiCL69zA9ZeYcRxEc/4fOAF0sU2nG0ld73
+1aEPYgIKq8ry4Wm7Awjg8frtkfuM2oHwMOTaF2gmWxmf8M6kCKxtKuVLHiepfaBy
+nB1uoL/B3COLBqEnLMfnxLYxAEXuDTEEvP3jJ36zi2B2qDxpoSyjkvqlhbsMQZkv
+ErJaXY56+leYlZqZrhn2gZwi2u+lIGe7gVvh6bkuWhXdFoZm8eaNjnzL/f6Xa0X7
+2iBHe3r4DKDmU4id8AgRRZxkwKOslRIu24JMp4KZGbQFwr1/k1+SEV8zUZ6iLVAl
+695rTVgEKF5sa/HnvjmOL8NxwehI7I0QdMooqvFVJmdyGZc0UrK/KGMZBXCjyVSS
+UHgxq29VGRhbrX5CwqUQRg==
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
index 54ef0bc..e0bc2ab 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
@@ -1,3 +1,3 @@
-U2FsdGVkX180j1V/ivNwX/s+ZkY+ZktkUYpxqULOrxBTbntiAwDQByTA3C/wz/5z
-FTZ6nZ16FZMtYMUMKzRGk8sZSWavllojRCwmNasm//zEHDrP8dllegKWIX4vsLbd
-jad0n9JqKwv9csyhKSE4tQ==
+U2FsdGVkX19Fh2kgxuosYekOdX+wkpveF6PgNJ2BgV8ecQHOyWcwS9qMjC8tVAZC
+DmSk8V29Brk8zdaXmz3JDLWNh+hO/yl2Cr2x8HddgYwpQzKY9NLtf6cTd8PqZUn/
+NURteBO3tTJwHi5Z1tsvufPbGaG2B2XQ/KbpobXm/Kk=
diff --git a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt
index 63a621d..066da48 100644
--- a/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt
+++ b/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/put_also_not_encrypted_files.txt
@@ -7,13 +7,14 @@ Sometimes you want to store files unencrypted
Unencrypted files will be shown in the web page file list with a
(c) after their name.
+
To a new unencrypted file to download:
-$ jstore add-nocrypt README.txt
-Using store "jsa/store"
+$ jstore add-nocrypt Makefile
+Using store "/home/user/code/laurent-tools/jsaccess/jsa/store"
Enter encryption passphrase
> jsa
-CREATED file /home/user/code/laurent-tools/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/065e18a7f246b800242a778a6e8dd07a3321dac6
+CREATED file /home/user/code/laurent-tools/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/Makefile
UPDATED file /home/user/code/laurent-tools/jsaccess/jsa/store/af022cd820fdad6cbcac8e15ac565c639a47dab0/index.txt
$ jstore rset user@_host:/var/www/htdocs/jsa/ # Only the first time
diff --git a/jsaccess/jstore.sh b/jsaccess/jstore.sh
index 6f270c4..a82780c 100755
--- a/jsaccess/jstore.sh
+++ b/jsaccess/jstore.sh
@@ -17,7 +17,7 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-VERSION=0.2
+VERSION=0.3
PROHIBITED_FILE_NAMES="index.html index.txt"
@@ -31,6 +31,7 @@ usage_exit() {
echo " add-nocrypt <file> [store]"
echo " rm <file_in_store> [store]"
echo " rmall [store]"
+ echo " edit [store]"
echo
echo "actions on local store for all passphrases:"
echo " init <store>"
@@ -121,6 +122,43 @@ _index_encrypt() {
echo "UPDATED file $enc_path/index.txt"
}
+_index_read() {
+ clear_name=$1
+ 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
+ meta=`echo $index_entry |awk '{ print $(NF) }' |sed s/"(\(.*\))"/\\\1/g`
+ size=`echo $meta |cut -d',' -f1`
+ crypt=`echo $meta |cut -d',' -f2`
+}
+
+_index_check() {
+ clear_name=$1
+ if [ `egrep -c "^$clear_name .*$" $tmp` -ne 0 ]; then
+ echo "File already present with this passphrase"
+ clean_exit 1
+ fi
+}
+
+_index_add() {
+ clear_name=$1
+ size=$2
+ do_crypt=$3
+ if [ $do_crypt -eq 0 ]; then
+ index_text="$clear_name ($size,nocrypt)"
+ else
+ index_text="$clear_name ($size,base64+aes256)"
+ fi
+ echo $index_text >> $tmp
+}
+
+_index_rm() {
+ clear_name=$1
+ sed -i /"^$clear_name .*$"/d $tmp
+}
+
__file_get_encname() {
clear_name=$1
enc_name=`echo -n ${enc_dir_hash}${clear_name} |openssl rmd160 |cut -d' ' -f2`
@@ -195,18 +233,15 @@ action_add() {
clean_exit 1
_pass_read
_index_decrypt
- if [ `egrep -c "^$clear_name .*$" $tmp` -ne 0 ]; then
- echo "File already present with this passphrase"
- clean_exit 1
- fi
+ _index_check $clear_name
_file_add $clear_path $clear_name $do_crypt
_index_decrypt
- if [ $do_crypt -eq 0 ]; then
- index_text="$clear_name (nocrypt)"
+ if [ $do_crypt -eq 1 ]; then
+ size=`ls -sh $enc_path/$enc_name |cut -d' ' -f1`
else
- index_text="$clear_name (base64+aes256)"
+ size=`ls -sh $clear_path |cut -d' ' -f1`
fi
- echo $index_text >> $tmp
+ _index_add $clear_name $size $do_crypt
_index_encrypt
}
@@ -214,16 +249,11 @@ action_rm() {
clear_name=$1
_pass_read
_index_decrypt
- 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
- crypt=`echo $index_entry |awk '{ print $(NF) }'`
- [ $crypt = "(nocrypt)" ] && do_crypt=0 || do_crypt=1
+ _index_read $clear_name
+ [ $crypt = "nocrypt" ] && do_crypt=0 || do_crypt=1
_file_rm $clear_name $do_crypt
_index_decrypt
- sed -i /"^$clear_name .*$"/d $tmp
+ _index_rm $clear_name
_index_encrypt
}