Add simple checksum test.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@402 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2010-12-19 21:17:36 +00:00
parent 058976ff08
commit e8e805dfd3

View File

@@ -1,11 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# Test mode compatibility, check input + kernel and cryptsetup cipher status # Test mode compatibility, check input + kernel and cryptsetup cipher status
# #
# FIXME: add checkum test of data
#
CRYPTSETUP=../src/cryptsetup CRYPTSETUP=../src/cryptsetup
DEV_NAME=dmc_test DEV_NAME=dmc_test
LOOPDEV=/dev/loop5 LOOPDEV=/dev/loop5
@@ -46,46 +42,74 @@ dmcrypt_check() # device outstring
{ {
X=$(dmsetup table $1 2>/dev/null | cut -d' ' -f 4) X=$(dmsetup table $1 2>/dev/null | cut -d' ' -f 4)
if [ $X = $2 ] ; then if [ $X = $2 ] ; then
echo -n "OK]" echo -n "[table OK]"
else else
echo -n "FAIL]" echo "[table FAIL]"
echo " Expecting $2 got $X." echo " Expecting $2 got $X."
fail fail
fi fi
X=$($CRYPTSETUP status $1 | grep cipher | sed s/\.\*cipher:\\s*//) X=$($CRYPTSETUP status $1 | grep cipher | sed s/\.\*cipher:\\s*//)
if [ $X = $2 ] ; then if [ $X = $2 ] ; then
echo " [OK]" echo -n "[status OK]"
else else
echo " [FAIL]" echo "[status FAIL]"
echo " Expecting $2 got $X." echo " Expecting $2 got $X."
fail fail
fi fi
dmsetup remove $1 >/dev/null 2>&1
}
dmcrypt_check_sum() # cipher device outstring
{
EXPSUM="c036cbb7553a909f8b8877d4461924307f27ecb66cff928eeeafd569c3887e29"
# Fill device with zeroes and reopen it
dd if=/dev/zero of=/dev/mapper/$2 bs=1M count=6 >/dev/null 2>&1
sync
dmsetup remove $2
echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 $2 /dev/mapper/$DEV_NAME >/dev/null 2>&1
ret=$?
VSUM=$(sha256sum /dev/mapper/$2 | cut -d' ' -f 1)
if [ $ret -eq 0 -a "$VSUM" = "$EXPSUM" ] ; then
echo -n "[OK]"
else
echo "[FAIL]"
echo " Expecting $EXPSUM got $VSUM."
fail
fi
dmsetup remove $2 >/dev/null 2>&1
} }
dmcrypt() dmcrypt()
{ {
OUT=$2 OUT=$2
[ -z "$OUT" ] && OUT=$1 [ -z "$OUT" ] && OUT=$1
printf "%-25s" "$1"
echo -n -e "TESTING(PLAIN): $1 ["
echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1 echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
echo -n -e "PLAIN:"
dmcrypt_check "$DEV_NAME"_"$1" $OUT dmcrypt_check "$DEV_NAME"_"$1" $OUT
dmsetup remove "$DEV_NAME"_"$1" >/dev/null 2>&1
else else
echo "SKIPPED]" echo -n "[n/a]"
fi fi
echo -n -e "TESTING(LUKS): $1 ["
echo $PASSWORD | $CRYPTSETUP luksFormat -i 1 -c $1 -s 256 /dev/mapper/$DEV_NAME >/dev/null 2>&1 echo $PASSWORD | $CRYPTSETUP luksFormat -i 1 -c $1 -s 256 /dev/mapper/$DEV_NAME >/dev/null 2>&1
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
echo -n -e " LUKS:"
echo $PASSWORD | $CRYPTSETUP luksOpen /dev/mapper/$DEV_NAME "$DEV_NAME"_"$1" >/dev/null 2>&1 echo $PASSWORD | $CRYPTSETUP luksOpen /dev/mapper/$DEV_NAME "$DEV_NAME"_"$1" >/dev/null 2>&1
dmcrypt_check "$DEV_NAME"_"$1" $OUT dmcrypt_check "$DEV_NAME"_"$1" $OUT
dmsetup remove "$DEV_NAME"_"$1" >/dev/null 2>&1
else
echo "SKIPPED]"
fi fi
# repeated device creation must return the same checksum
echo $PASSWORD | $CRYPTSETUP create -c $1 -s 256 "$DEV_NAME"_"$1" /dev/mapper/$DEV_NAME >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo -n -e " CHECKSUM:"
dmcrypt_check_sum "$1" "$DEV_NAME"_"$1"
fi
echo
} }
if [ $(id -u) != 0 ]; then if [ $(id -u) != 0 ]; then