fixes to ask_usbkey

tested on debian 6
This commit is contained in:
Jaromil 2011-02-09 20:22:39 +01:00
parent 22a65c7193
commit 12f92e7aef

117
src/tomb
View File

@ -1,4 +1,4 @@
#!/bin/zsh #!/bin/zsh -x
# #
# Tomb, the Crypto Undertaker # Tomb, the Crypto Undertaker
# #
@ -71,9 +71,9 @@ ask_usbkey() {
dmesg | tail -n 12 | grep -q 'new.*USB device' dmesg | tail -n 12 | grep -q 'new.*USB device'
if [ $? = 0 ]; then plugged=true; fi if [ $? = 0 ]; then plugged=true; fi
echo -n "." echo -n "."
sleep 1 sleep .5
c=`expr $c + 1` c=`expr $c + 1`
if [ $c -gt 60 ]; then if [ $c -gt 15 ]; then
echo echo
error "timeout." error "timeout."
export usbkey_mount=none export usbkey_mount=none
@ -82,12 +82,12 @@ ask_usbkey() {
done done
echo echo
echo -n " . usb key inserted, opening " echo -n " . usb key inserted, attaching "
c=0 c=0
attached=false attached=false
while [ "$attached" != "true" ]; do while [ "$attached" != "true" ]; do
dmesg | tail -n 3| grep -q 'Attached.*removable disk' dmesg | tail -n 12| grep -q 'Attached.*removable disk'
if [ $? = 0 ]; then attached=true; fi if [ $? = 0 ]; then attached=true; fi
echo -n "." echo -n "."
sleep 1 sleep 1
@ -100,28 +100,44 @@ ask_usbkey() {
fi fi
done done
echo
echo -n " . usb attached, opening "
# get the first partition # get the first partition
usbpart=`dmesg |tail -n 8 | grep ' sd.:' |cut -d: -f2 |tr -d ' '` usbpart=`dmesg |tail -n 12 | grep ' sd.:' |cut -d: -f2 |tr -d ' '`
# wait that is mounted # # wait that is mounted (it automount is on)
c=0 # c=0
mounted=false # mounted=false
while [ "$mounted" != "true" ]; do # while [ "$mounted" != "true" ]; do
cat /proc/mounts | tail -n 2 | grep -q $usbpart # cat /proc/mounts | tail -n 2 | grep -q $usbpart
if [ $? = 0 ]; then mounted=true; fi # if [ $? = 0 ]; then mounted=true; fi
echo -n "." # echo -n "."
sleep .5 # sleep .5
c=`expr $c + 1` # c=`expr $c + 1`
if [ $c -gt 30 ]; then # if [ $c -gt 30 ]; then
echo # echo
error "timeout." # error "timeout."
export usbkey_mount=none # export usbkey_mount=none
return 1; # return 1;
fi # fi
done # done
# # check where it is mounted
# usbmount=`cat /proc/mounts | awk -v p=$usbpart '{ if( $1 == "/dev/" p) print $2 }'`
sleep 1
# mount the first partition on the usb key
mtmp=`tempfile -p tomb`
rm -f $mtmp
mkdir -p $mtmp
mount /dev/$usbpart $mtmp
if [ $? = 0 ]; then
usbmount=$mtmp
else
error "cannot mount usbkey partition $usbmount"
return 1
fi
# check where it is mounted
usbmount=`cat /proc/mounts | awk -v p=$usbpart '{ if( $1 == "/dev/" p) print $2 }'`
echo echo
act "usb key mounted on $usbmount" act "usb key mounted on $usbmount"
export usbkey_mount=$usbmount export usbkey_mount=$usbmount
@ -211,7 +227,7 @@ check_priv() {
which gksu > /dev/null which gksu > /dev/null
if [ $? = 0 ]; then if [ $? = 0 ]; then
func "Using gksu for root execution of 'tomb ${(f)ARGS}'" func "Using gksu for root execution of 'tomb ${(f)ARGS}'"
gksu "tomb ${ARGS[@]}" gksudo "tomb ${ARGS[@]}"
exit $? exit $?
fi fi
which sudo > /dev/null which sudo > /dev/null
@ -354,7 +370,7 @@ create_tomb() {
act "once done you will be asked to choose a password for your tomb." act "once done you will be asked to choose a password for your tomb."
touch ${keytmp}/tomb.tmp touch ${keytmp}/tomb.tmp
chmod 0600 ${keytmp}/tomb.tmp chmod 0600 ${keytmp}/tomb.tmp
$DD bs=1 count=256 if=/dev/random of=${keytmp}/tomb.tmp $DD bs=1 count=256 if=/dev/urandom of=${keytmp}/tomb.tmp
if ! [ -r ${keytmp}/tomb.tmp ]; then if ! [ -r ${keytmp}/tomb.tmp ]; then
error "cannot generate encryption key, operation aborted." error "cannot generate encryption key, operation aborted."
umount ${keytmp} umount ${keytmp}
@ -409,12 +425,31 @@ create_tomb() {
exit 0 exit 0
fi fi
cryptsetup --key-file ${keytmp}/tomb.tmp --cipher aes luksOpen ${nstloop} tomb.tmp cryptsetup --key-file ${keytmp}/tomb.tmp --cipher aes luksOpen ${nstloop} tomb.tmp
${WIPE[@]} ${keytmp}/tomb.tmp ${WIPE[@]} ${keytmp}/tomb.tmp
umount ${keytmp} umount ${keytmp}
rm -r ${keytmp} rm -r ${keytmp}
# cryptsetup luksDump ${nstloop}
act "formatting your Tomb with Ext4 filesystem"
mkfs.ext4 -q -F -j -L "${FILE%%.*}" /dev/mapper/tomb.tmp
if [ $? = 0 ]; then
act "OK, encrypted storage succesfully formatted"
else
act "error formatting Tomb"
fi
sync
cryptsetup luksClose tomb.tmp
losetup -d ${nstloop}
notice "done creating $FILE encrypted storage (using Luks dm-crypt AES/SHA256)"
tomb-notify "The Tomb is ready!" "We will now open your new Tomb for the first time."
notice "Your tomb is ready on ${FILE} and secured with key ${FILE}.gpg" notice "Your tomb is ready on ${FILE} and secured with key ${FILE}.gpg"
act "Would you like to save the key on an external usb device?" act "Would you like to save the key on an external usb device?"
act "This is recommended for safety:" act "This is recommended for safety:"
@ -431,28 +466,12 @@ create_tomb() {
mkdir -m 0700 -p ${usbkey_mount}/.tomb mkdir -m 0700 -p ${usbkey_mount}/.tomb
cp -v ${FILE}.gpg ${usbkey_mount}/.tomb/ cp -v ${FILE}.gpg ${usbkey_mount}/.tomb/
chmod -R go-rwx ${usbkey_mount}/.tomb chmod -R go-rwx ${usbkey_mount}/.tomb
umount ${usbkey_mount}
unset ${usbkey_mount}
${WIPE[@]} ${FILE}.gpg ${WIPE[@]} ${FILE}.gpg
fi fi
fi fi
# cryptsetup luksDump ${nstloop}
act "formatting your Tomb with Ext4 filesystem"
mkfs.ext4 -q -F -j -L "${FILE%\.*}-`hostname`" /dev/mapper/tomb.tmp
if [ $? = 0 ]; then
act "OK, encrypted storage succesfully formatted"
else
act "error formatting Tomb"
fi
sync
cryptsetup luksClose tomb.tmp
losetup -d ${nstloop}
notice "done creating $FILE encrypted storage (using Luks dm-crypt AES/SHA256)"
tomb-notify "The Tomb is ready!" "We will now open your new Tomb for the first time."
tomb mount $FILE tomb mount $FILE
} }
@ -568,6 +587,11 @@ mount_tomb() {
done done
if [ -r ${usbkey_mount}/.tomb/${tombkey} ]; then
umount ${usbkey_mount}
unset ${usbkey_mount}
fi
if ! [ -r /dev/mapper/${mapper} ]; then if ! [ -r /dev/mapper/${mapper} ]; then
error "failure mounting the encrypted file" error "failure mounting the encrypted file"
losetup -d ${nstloop} losetup -d ${nstloop}
@ -587,7 +611,6 @@ mount_tomb() {
notice "encrypted storage $tombfile succesfully mounted on $tombmount" notice "encrypted storage $tombfile succesfully mounted on $tombmount"
exec_bind_hooks ${tombmount} exec_bind_hooks ${tombmount}
exec_post_hooks ${tombmount} exec_post_hooks ${tombmount}
exec_as_user tomb-status ${mapper} ${tombfile} ${tombmount} &!
return 0 return 0
} }
@ -706,8 +729,6 @@ umount_tomb() {
notice "crypt storage ${mapper} unmounted" notice "crypt storage ${mapper} unmounted"
tomb-notify "Tomb closed: $tombname" "Your bones will Rest In Peace." tomb-notify "Tomb closed: $tombname" "Your bones will Rest In Peace."
return 0 return 0
} }