2011-11-17 13:47:40 +00:00
|
|
|
#!/bin/zsh
|
|
|
|
#
|
|
|
|
# Undertaker, auxiliary command for Tomb
|
|
|
|
#
|
|
|
|
# Tomb is a tool to operate file encryption of private and secret data
|
|
|
|
#
|
|
|
|
# Undertaker is a tool to retrieve tomb keys from various sources
|
|
|
|
#
|
2011-12-01 20:39:10 +00:00
|
|
|
# {{{ Copyleft (C) 2011 Denis Roio <jaromil@dyne.org>
|
2011-11-17 13:47:40 +00:00
|
|
|
#
|
|
|
|
# This source code is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This source code is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# Please refer to the GNU Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Public License along with
|
|
|
|
# this source code; if not, write to:
|
|
|
|
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2011-12-01 20:39:10 +00:00
|
|
|
# }}}
|
2011-11-17 13:47:40 +00:00
|
|
|
|
|
|
|
# first of all source the tomb core functions
|
|
|
|
which tomb > /dev/null
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
print "$fg[red][!]$fg[white] Tomb command not found, operation aborted."; exit 1
|
|
|
|
fi
|
|
|
|
|
2011-11-15 14:50:09 +00:00
|
|
|
typeset -A opts
|
|
|
|
typeset -A args
|
|
|
|
function undertaker_scheme() {
|
|
|
|
zparseopts -D -print-path=print_path
|
2011-11-17 13:47:40 +00:00
|
|
|
|
2011-11-15 14:50:09 +00:00
|
|
|
scheme=$1
|
|
|
|
keypath=$2
|
|
|
|
case $scheme in
|
|
|
|
bluetooth)
|
|
|
|
#TODO: support --print-path
|
|
|
|
act "access to bluetooth protocol requested"
|
|
|
|
which obexftp &> /dev/null
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
error "obexftp not found, needed for bluetooth: operation aborted."
|
|
|
|
return 64
|
|
|
|
fi
|
|
|
|
keytmp=`safe_dir undertaker`
|
|
|
|
cd $keytmp
|
|
|
|
# fetch key from bluetooth, url format: bluetooth://55:33:44:55:66/file/path
|
|
|
|
obexdevpath=${keypath#*//}
|
|
|
|
obexdev=${obexdevpath%%/*}
|
|
|
|
obexpath=${obexdevpath#*/}
|
|
|
|
act "obex device: $obexdev"
|
|
|
|
act "obex path: $obexpath"
|
2011-11-17 13:47:40 +00:00
|
|
|
obexftp -b $obexdev -g $obexpath
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
rmdir ${keytmp}
|
2011-12-01 20:39:10 +00:00
|
|
|
die "a problem occurred retreiving the key via bluetooth."
|
2011-11-17 13:47:40 +00:00
|
|
|
fi
|
|
|
|
# print out the key on stdout
|
|
|
|
cat $obexpath >&1
|
2011-11-15 14:50:09 +00:00
|
|
|
# wipe out the key
|
|
|
|
${WIPE[@]} $obexpath
|
|
|
|
cd -
|
|
|
|
rmdir ${keytmp}
|
|
|
|
|
|
|
|
# tombkey="basename $obexpath"
|
|
|
|
;;
|
|
|
|
file)
|
|
|
|
if ! [[ -f $keypath ]]; then
|
|
|
|
error "Invalid path $keypath"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [[ -n $print_path ]]; then
|
|
|
|
echo $keypath;
|
|
|
|
else
|
|
|
|
< $keypath
|
|
|
|
r=$?
|
|
|
|
if [[ $r != 0 ]]; then return 1; fi
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
#TODO: support undertaker-$scheme
|
|
|
|
error "url protocol not recognized: $baseurl"
|
|
|
|
return 64
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
function main() {
|
2011-11-16 20:29:32 +00:00
|
|
|
typeset -A opts
|
|
|
|
zparseopts -M -E -D -Aopts -poll -print-path -machine-parseable
|
2011-11-15 14:50:09 +00:00
|
|
|
if ! [ $1 ] ; then
|
|
|
|
error "an argument is missing, the undertaker is confused"
|
|
|
|
act "usage: undertaker [options] url://host:path/to/tomb.key"
|
|
|
|
exit 1;
|
|
|
|
fi
|
2011-11-16 20:29:32 +00:00
|
|
|
local -a tomb_opts
|
|
|
|
if [[ -n ${(k)opts[--machine-parseable]} ]]; then
|
|
|
|
tomb_opts+='--machine-parseable'
|
|
|
|
fi
|
|
|
|
local -A backupopts
|
|
|
|
backupopts=${(kv)opts}
|
|
|
|
source tomb ${tomb_opts[@]} source
|
|
|
|
opts=${(kv)backupopts}
|
2011-11-15 14:50:09 +00:00
|
|
|
check_bin
|
2011-11-17 13:47:40 +00:00
|
|
|
|
2011-11-16 20:29:32 +00:00
|
|
|
|
|
|
|
notice "Undertaker will look for $1"
|
2011-11-17 13:47:40 +00:00
|
|
|
|
2011-11-15 14:50:09 +00:00
|
|
|
ARG1=${1}
|
|
|
|
scheme=${ARG1%://*}
|
|
|
|
keypath=${ARG1#*//}
|
|
|
|
|
|
|
|
if [[ -n ${(k)opts[--poll]} ]]; then
|
|
|
|
while true; do
|
2011-11-16 20:29:32 +00:00
|
|
|
progress poll 0 search
|
2011-11-15 14:50:09 +00:00
|
|
|
undertaker_scheme $scheme $keypath
|
|
|
|
r=$?
|
|
|
|
if [[ $r == 64 ]]; then
|
|
|
|
exit 64
|
|
|
|
fi
|
2011-11-16 20:29:32 +00:00
|
|
|
progress poll 100 done
|
2011-11-15 14:50:09 +00:00
|
|
|
sleep 3
|
|
|
|
done
|
|
|
|
else
|
|
|
|
undertaker_scheme $scheme $keypath
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
main $*
|
|
|
|
|
|
|
|
### Conventions and other comments:
|
|
|
|
#
|
|
|
|
# EXIT CODES FOR SCHEME HANDLERS
|
|
|
|
# 0 is for everything went fine
|
|
|
|
# 64 is for "not supported/the problem won't be solved by polling". This is for things like: unmet dependencies, not supported at all, etc
|
|
|
|
# everything else means just "error". Use 1, please. So other codes can be used if needed
|
|
|
|
#
|