Commit a5aa30be authored by Milan Broz's avatar Milan Broz

Fix use of empty keyfile (Issue 120).

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@702 36d66b0a-2a48-0410-832c-cd162a569da5
parent eb2b0369
2012-01-12 Milan Broz <mbroz@redhat.com>
* Fix use of empty keyfile.
2011-11-13 Milan Broz <mbroz@redhat.com>
* Fix error message for luksClose and detached LUKS header.
* Allow --header for status command to get full info with detached header.
......
......@@ -306,7 +306,7 @@ int crypt_get_key(const char *prompt,
/* known keyfile size, alloc it in one step */
if ((size_t)st.st_size >= keyfile_size_max)
buflen = keyfile_size_max;
else
else if (st.st_size)
buflen = st.st_size;
}
}
......@@ -357,12 +357,6 @@ int crypt_get_key(const char *prompt,
goto out_err;
}
/* Well, for historical reasons reading empty keyfile is not fail. */
if(!i) {
crypt_safe_free(pass);
pass = NULL;
}
*key = pass;
*key_size = i;
r = 0;
......
......@@ -11,6 +11,7 @@ HEADER_IMG=luks-header
KEY1=key1
KEY2=key2
KEY5=key5
KEYE=keye
LUKS_HEADER="S0-5 S6-7 S8-39 S40-71 S72-103 S104-107 S108-111 R112-131 R132-163 S164-167 S168-207 A0-591"
KEY_SLOT0="S208-211 S212-215 R216-247 A248-251 A251-255"
......@@ -35,7 +36,7 @@ function remove_mapping()
[ -b /dev/mapper/$DEV_NAME2 ] && dmsetup remove $DEV_NAME2
[ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
losetup -d $LOOPDEV >/dev/null 2>&1
rm -f $ORIG_IMG $IMG $KEY1 $KEY2 $KEY5 $HEADER_IMG >/dev/null 2>&1
rm -f $ORIG_IMG $IMG $KEY1 $KEY2 $KEY5 $KEYE $HEADER_IMG >/dev/null 2>&1
}
function fail()
......@@ -88,6 +89,10 @@ function prepare()
dd if=/dev/urandom of=$KEY5 count=1 bs=16 >/dev/null 2>&1
fi
if [ ! -e $KEYE ]; then
touch $KEYE
fi
cp $IMG $ORIG_IMG
[ -n "$1" ] && echo "CASE: $1"
}
......@@ -237,6 +242,10 @@ echo "key0" | $CRYPTSETUP -q luksFormat --master-key-file /dev/urandom $LOOPDEV
$CRYPTSETUP -q luksFormat --master-key-file /dev/urandom -s 256 --uuid $TEST_UUID $LOOPDEV $KEY1 || fail
$CRYPTSETUP luksOpen -d $KEY1 $LOOPDEV $DEV_NAME || fail
$CRYPTSETUP -q luksClose $DEV_NAME || fail
# empty keyfile
$CRYPTSETUP -q luksFormat $LOOPDEV $KEYE || fail
$CRYPTSETUP luksOpen -d $KEYE $LOOPDEV $DEV_NAME || fail
$CRYPTSETUP -q luksClose $DEV_NAME || fail
prepare "[17] AddKey volume key, passphrase and keyfile" wipe
# masterkey
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment