Commit 2ef61b5c authored by Helen Koike's avatar Helen Koike

wip: crypt

parent abc7f3ff
......@@ -28,6 +28,48 @@ fill_rootfs()
sudo chmod +x dm-mount/bin/init.sh
}
create_crypt()
{
# Create disk
DISK=$1
PREFIX=$2
DM_DEV=dm-crypt
if [ -f $DISK -a -f ${DISK}.info ]; then
echo "$DISK already exist, not creating it"
return
else
echo "creating $DISK"
fi
dd if=/dev/zero of=$DISK bs=512M count=2
LOOP_DEV=$(sudo losetup -fP --show $DISK)
sectors=$(sudo blockdev --getsz "${LOOP_DEV}")
key=babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe
table="0 $sectors crypt aes-xts-plain64 $key 0 ${LOOP_DEV} 0 1 allow_discards"
echo "$table" | sudo dmsetup create $DM_DEV
bash -c "cat > ${DISK}.info" <<- EOF
${PREFIX}sectors=${sectors}
${PREFIX}key=${key}
EOF
echo "concise table (with loopback device)"
sudo dmsetup table --concise /dev/mapper/$DM_DEV
# Format
sudo mkfs.ext4 -L ROOT-CRYPT /dev/mapper/$DM_DEV
mkdir -p dm-mount
sudo mount /dev/mapper/$DM_DEV dm-mount
fill_rootfs "crypt disk $DISK"
# Umount disk/dm/loopback
sudo umount dm-mount
rm -r dm-mount
sudo dmsetup remove $DM_DEV
sudo losetup -d $LOOP_DEV
}
create_striped()
{
# Create disk
......@@ -236,26 +278,6 @@ launch_test()
fi
}
DS1=disk-strped-1.img
create_striped $DS1 DS1_
# Load disk info
source ${DS1}.info
DL1=disk-linear-1.img
create_linear $DL1 DL1_
# Load disk info
source ${DL1}.info
DL2=disk-linear-2.img
create_linear $DL2 DL2_
# Load disk info
source ${DL2}.info
DV1=disk-verity-1.img
create_verity $DV1 DV1_
# Load disk info
source ${DV1}.info
# -----------------------
# Linear and parser tests
# -----------------------
......@@ -397,7 +419,6 @@ launch_test \
"$name,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
124
}
linear_parser_tests
# --------------
# Verity
......@@ -418,7 +439,6 @@ launch_test \
/dev/dm-4 \
"dm-verity,${UUID},4,ro,0 $DV1_sectors verity $DV1_hash_type 8:1 8:2 $DV1_data_block_size $DV1_hash_block_size $DV1_data_blocks 1 $DV1_hash_algorithm $DV1_root_hash $DV1_salt"
}
verity_tests
# --------------
# Striped
......@@ -439,4 +459,60 @@ launch_test \
/dev/dm-4 \
"dm-striped,${UUID},4,ro,0 $DS1_sectors striped 4 $DS1_PAGESIZE 8:1 0 8:2 0 8:3 0 8:4 0"
}
# --------------
# Crypt
# --------------
crypt_tests()
{
launch_test \
"crypt: with minor" \
"-hda ${DC1}" \
/dev/dm-4 \
"dm-crypt,,4,ro,0 $DC1_sectors crypt aes-xts-plain64 $DC1_key 0 /dev/sda 0 1 allow_discards"
UUID=123123123
launch_test \
"crypt: with uuid" \
"-hda ${DC1}" \
/dev/dm-4 \
"dm-crypt,${UUID},4,ro,0 $DC1_sectors crypt aes-xts-plain64 $DC1_key 0 /dev/sda 0 1 allow_discards"
launch_test \
"crypt: wrong key" \
"-hda ${DC1}" \
/dev/dm-4 \
"dm-crypt,,4,ro,0 $DC1_sectors crypt aes-xts-plain64 123123123123 0 /dev/sda 0 1 allow_discards" \
124
}
DS1=disk-striped-1.img
create_striped $DS1 DS1_
# Load disk info
source ${DS1}.info
DL1=disk-linear-1.img
create_linear $DL1 DL1_
# Load disk info
source ${DL1}.info
DL2=disk-linear-2.img
create_linear $DL2 DL2_
# Load disk info
source ${DL2}.info
DV1=disk-verity-1.img
create_verity $DV1 DV1_
# Load disk info
source ${DV1}.info
DC1=disk-crypt-1.img
create_crypt $DC1 DC1_
# Load disk info
source ${DC1}.info
verity_tests
linear_parser_tests
striped_tests
crypt_tests
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