3 CRYPTSETUP=../src/cryptsetup
7 ORIG_IMG=luks-test-orig
12 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"
13 KEY_SLOT0="S208-211 S212-215 R216-247 S248-251 S251-255"
14 KEY_MATERIAL0="R4096-68096"
15 KEY_MATERIAL0_EXT="R4096-68096"
17 KEY_SLOT1="S256-259 S260-263 R264-295 S296-299 S300-303"
18 KEY_MATERIAL1="R69632-133632"
19 KEY_MATERIAL1_EXT="S69632-133632"
21 function remove_mapping()
23 [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
24 losetup -d $LOOPDEV >/dev/null 2>&1
25 rm -f $ORIG_IMG $IMG $IMG1 $KEY1 >/dev/null 2>&1
37 if [ $(id -u) != 0 ]; then
38 echo "WARNING: You must be root to run this test, test skipped."
42 [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove $DEV_NAME
44 if [ ! -e $KEY1 ]; then
45 dd if=/dev/urandom of=$KEY1 count=1 bs=32 >/dev/null 2>&1
48 if [ ! -e $IMG ]; then
49 bzip2 -cd compatimage.img.bz2 > $IMG
50 losetup -d $LOOPDEV >/dev/null 2>&1
56 [ -n "$1" ] && echo "CASE: $1"
62 ./fileDiffer.py $IMG $ORIG_IMG $1|| fail
65 function check_exists()
67 [ -b /dev/mapper/$DEV_NAME ] || fail
73 prepare "[1] open - compat image - acceptance check"
74 echo "compatkey" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME || fail
77 prepare "[2] open - compat image - denial check"
78 echo "wrongkey" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME && fail
81 # All headers items and first key material section must change
83 echo "key0" | $CRYPTSETUP -i 1000 -c aes-cbc-essiv:sha256 -s 128 luksFormat $LOOPDEV || fail
84 check "$LUKS_HEADER $KEY_SLOT0 $KEY_MATERIAL0"
86 prepare "[4] format using hash sha512"
87 echo "key0" | $CRYPTSETUP -i 1000 -h sha512 -c aes-cbc-essiv:sha256 -s 128 luksFormat $LOOPDEV || fail
88 check "$LUKS_HEADER $KEY_SLOT0 $KEY_MATERIAL0"
91 echo "key0" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME || fail
94 # Key Slot 1 and key material section 1 must change, the rest must not.
96 echo -e "key0\nkey1" | $CRYPTSETUP luksAddKey $LOOPDEV || fail
97 check "$KEY_SLOT1 $KEY_MATERIAL1"
98 echo "key1" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME || fail
100 # Unsuccessful Key Delete - nothing may change
101 prepare "[7] unsuccessful delete"
102 echo "invalid" | $CRYPTSETUP luksDelKey $LOOPDEV 1 && fail
106 # Key Slot 1 and key material section 1 must change, the rest must not
107 prepare "[8] successful delete"
108 $CRYPTSETUP -q luksDelKey $LOOPDEV 1 || fail
109 check "$KEY_SLOT1 $KEY_MATERIAL1_EXT"
110 echo "key1" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME && fail
111 echo "key0" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME || fail
113 # Key Slot 1 and key material section 1 must change, the rest must not
114 prepare "[9] add key test for key files"
115 echo "key0" | $CRYPTSETUP luksAddKey $LOOPDEV $KEY1 || fail
116 check "$KEY_SLOT1 $KEY_MATERIAL1"
117 $CRYPTSETUP -d $KEY1 luksOpen $LOOPDEV $DEV_NAME || fail
119 # Key Slot 1 and key material section 1 must change, the rest must not
120 prepare "[10] delete key test with key1 as remaining key"
121 $CRYPTSETUP -d $KEY1 luksDelKey $LOOPDEV 0 || fail
122 check "$KEY_SLOT0 $KEY_MATERIAL0_EXT"
123 echo "key0" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME && fail
124 $CRYPTSETUP luksOpen -d $KEY1 $LOOPDEV $DEV_NAME || fail
127 prepare "[11] delete last key"
128 echo "key0" | $CRYPTSETUP luksFormat $LOOPDEV || fail
129 echo "key0" | $CRYPTSETUP luksKillSlot $LOOPDEV 0 || fail
130 echo "key0" | $CRYPTSETUP luksOpen $LOOPDEV $DEV_NAME && fail
132 # Format test for ESSIV, and some other parameters.
133 prepare "[12] parameter variation test"
134 $CRYPTSETUP -q -i 1000 -c aes-cbc-essiv:sha256 -s 128 luksFormat $LOOPDEV $KEY1 || fail
135 check "$LUKS_HEADER $KEY_SLOT0 $KEY_MATERIAL0"
136 $CRYPTSETUP -d $KEY1 luksOpen $LOOPDEV $DEV_NAME || fail