coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

commit 6220dc5a83eeff6355d94ce2b4243b8d932cd83c
parent 553b392eaf2505455427ce9c4d5bee583574261a
Author: parazyd <parazyd@dyne.org>
Date:   Mon,  7 Mar 2016 16:29:23 +0100

generate random password for new tombs

Diffstat:
MREADME.md | 2++
Mbin/sacrist | 117+++++++++++++++++++++++++++++++++++++++++---------------------------------------
2 files changed, 62 insertions(+), 57 deletions(-)

diff --git a/README.md b/README.md @@ -11,6 +11,8 @@ Once you plug in your key again, that same tomb will be closed and your files are once again unreadable. ## Notes +* `gmakehook` can be used to create tombox hooks in a more user-friendly + manner. It is a GUI (zenity) helper script. ## Installation diff --git a/bin/sacrist b/bin/sacrist @@ -8,9 +8,12 @@ device=$1 happenz=$2 keyuuid=$(blkid $device | awk -F\" '{print $2}') - typeset -H keypass +typeset -H keyuuid typeset -H undertaker +typeset -H graveyard +typeset -H tombs +typeset -H tombpasswd # Vars graveyard="/home/graveyard" # Our graveyard, with all the tombs @@ -23,21 +26,58 @@ hooks="$coffindot/hook" tomb="/usr/local/bin/tomb" tombpasswd="$graveyard/passwd" -# Hook syntax -# create:username:tombname:tombsize:passphrase - # Debugs print "Arg1: $1" print "Arg2: $2" print "Device path is: $device" print "Device UUID is: $keyuuid" -# {{{ Functions -_mountkey() { - mkdir -p $keymount - mount $device $keymount +# {{{ msg +_msg() { + if [[ $1 == "error" ]]; then + print "\e[1;31m[E] \e[0;31m$2 \e[0m" + elif [[ $1 == "warn" ]]; then + print "\e[1;33m[W] \e[0;33m$2 \e[0m" + elif [[ $1 == "info" ]]; then + print "\e[1;34m[i] \e[0;34m$2 \e[0m" + fi } +# }}} +_umountkey() { umount $keymount; rmdir $keymount } +_mountkey() { mkdir -p $keymount; mount $device $keymount } + +_hashkey() { cat $coffindot/$tombid.key | sha512sum | awk -F" " '{print $1}' } + +_comparekey() { + keyhash=$(_hashkey) + if [[ ( $(cat $tombs | grep $keyhash | grep $keyuuid) ) ]]; then + happenz=close + else + happenz=open + fi +} + +_hooks() { + for entry in $(cat $hooks); do + let hook=$hook+1 + _msg info "Found hook $hook..." + + # Check what's hook supposed to do + if [[ ${entry[(ws@:@)1]} == "create" ]]; then + _create_new_tomb + elif [[ ${entry[(ws@:@)1]} == "delete" ]]; then + #DELETE TOMB + elif [[ ${entry[(ws@:@)1]} == "backup" ]]; then + # do backup + else + _msg error "No valid hook syntax on hook $hook" + fi + rm $hooks && _msg info "Removed $hooks" + done +} + +# {{{ ttabmagic _ttabmagic() { # Loop entire ttab and do stuff for tombs that want to be opened _msg info "Doing ttab magic..." @@ -68,7 +108,7 @@ _ttabmagic() { keypass=$(cat $tombpasswd | grep $keyhash | awk -F: '{print $2}') print "Tomb passphrase: $keypass" sudo -u $undertaker $tomb open $graveyard/$tombid.tomb -k $coffindot/$tombid.key \ - --unsafe --tomb-pwd "$keypass" # Deal with this + --unsafe --tomb-pwd "$keypass" if [[ -d "/media/$tombid" ]]; then print "$undertaker:$keyhash:$keyuuid" >> $tombs && chmod 600 $tombs && _msg info "Added info to $tombs" @@ -80,45 +120,19 @@ _ttabmagic() { done umount $keymount && rmdir $keymount && _msg info "Unmounted and deleted $keymount" } +# }}} -_hashkey() { - cat $coffindot/$tombid.key | sha512sum | awk -F" " '{print $1}' -} - -_comparekey() { - keyhash=$(_hashkey) - if [[ ( $(cat $tombs | grep $keyhash | grep $keyuuid) ) ]]; then - happenz=close - else - happenz=open - fi -} - -_hooks() { - for entry in $(cat $hooks); do - let hook=$hook+1 - _msg info "Found hook $hook..." - - # Check what's hook supposed to do - if [[ ${entry[(ws@:@)1]} == "create" ]]; then - _create_new_tomb - elif [[ ${entry[(ws@:@)1]} == "delete" ]]; then - #DELETE TOMB - elif [[ ${entry[(ws@:@)1]} == "foo" ]]; then - # do foo - else - _msg error "No valid hook syntax on hook $hook" - fi - rm $hooks && _msg info "Removed $hooks" - done -} - +# {{{ _create_new_tomb _create_new_tomb() { + # TODO: options for webdav, sshfs, ipfs + # TODO: recognize custom post/bind hooks and implement them inside the new tomb + # TODO: delete/backup/foo hooks + _msg info "Creating new tomb!" undertaker=${entry[(ws@:@)2]} tombid=${entry[(ws@:@)3]} tombsize=${entry[(ws@:@)4]} - keypass=${entry[(ws@:@)5]} + keypass=$(pwgen 30 -1 1) if ! [[ ( $(id $undertaker) ) ]]; then _msg warn "No user called $undertaker found. Creating..." @@ -141,26 +155,14 @@ _create_new_tomb() { _msg info "Wrote to $ttab and $tombpasswd" # rm $createme && _msg info "Removed $createme" } +# }}} _endgame() { # Mr. Proper } -_msg() { - if [[ $1 == "error" ]]; then - print "\e[1;31m[E] \e[0;31m$2 \e[0m" - elif [[ $1 == "warn" ]]; then - print "\e[1;33m[W] \e[0;33m$2 \e[0m" - elif [[ $1 == "info" ]]; then - print "\e[1;34m[i] \e[0;34m$2 \e[0m" - fi -} -# }}} - -#--------------------------------------------------------------------------------------------------- -#------------------------------------------------------ Main --------------------------------------- -#--------------------------------------------------------------------------------------------------- +# {{{ MAIN if [[ $happenz == "CREATE" ]]; then _mountkey if [[ -d "$coffindot" ]]; then @@ -180,6 +182,7 @@ if [[ $happenz == "CREATE" ]]; then fi else _msg error "No valid .coffin directory! Exiting..." - umount $keymount && rmdir $keymount && _msg info "Umounted and removed $keymount" + _umountkey && _msg info "Unmounted and removed $keymount" fi fi +# }}}