mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-15 21:00:05 +01:00
The non compact json area may contiain whitespace characters
in between json object key and value (e.g.: {"key": "the_value"}).
For LUKS2 write optimization we need to check and do regression testing
for the case where LUKS2 metadata would contain valid LUKS2 json area in
non compact format. The test is meant to verify if the write optimization
does not leave invalid characters beyond valid and properly terminated
LUKS2 json area.
53 lines
1.2 KiB
Bash
Executable File
53 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
. lib.sh
|
|
|
|
#
|
|
# *** Description ***
|
|
#
|
|
# generate LUKS2 header with non compact (valid!)
|
|
# json and additional token with id 0.
|
|
#
|
|
# The image is tested for correct LUKS2 write optimization
|
|
# where non compact json trailing bytes must not remain in LUKS2 json
|
|
# area after write of shorter (e.g. compact) json.
|
|
|
|
# $1 full target dir
|
|
# $2 full source luks2 image
|
|
|
|
generate()
|
|
{
|
|
# add empty token
|
|
json_str=$(jq -c '.tokens."0" = {"type":"a", "keyslots":[]}' $TMPDIR/json0)
|
|
json_len_orig=${#json_str}
|
|
test $json_len_orig -lt $((LUKS2_JSON_SIZE*512)) || exit 2
|
|
|
|
json_str_new=$(echo -n $json_str | sed -e 's/\(\"type\":\)\(\"luks2\"\)/\1 \2/')
|
|
json_len_new=${#json_str_new}
|
|
|
|
test $json_len_new -lt $((LUKS2_JSON_SIZE*512)) || exit 2
|
|
test $json_len_new -gt $json_len_orig || exit 2
|
|
|
|
printf '%s' "$json_str_new" | _dd of=$TMPDIR/json0 bs=1 conv=notrunc
|
|
printf '%s' "$json_str_new" | _dd of=$TMPDIR/json1 bs=1 conv=notrunc
|
|
|
|
lib_mangle_json_hdr0
|
|
lib_mangle_json_hdr1
|
|
}
|
|
|
|
check()
|
|
{
|
|
lib_hdr0_checksum || exit 2
|
|
lib_hdr1_checksum || exit 2
|
|
|
|
read_luks2_json0 $TGT_IMG $TMPDIR/json_res0
|
|
|
|
read -r json_str_res < $TMPDIR/json_res0
|
|
test ${#json_str_res} -gt $json_len_orig || exit 2
|
|
}
|
|
|
|
lib_prepare $@
|
|
generate
|
|
check
|
|
lib_cleanup
|