8 # generate header with correct json of maximal size in primary slot.
9 # Secondary header is broken on purpose.
13 # $2 full source luks2 image
15 PATTERN="\"config\":{"
16 KEY="\"config_key\":\""
21 test -d $TMPDIR || mkdir $TMPDIR
22 read_luks2_json0 $TGT_IMG $TMPDIR/json0
23 read_luks2_bin_hdr0 $TGT_IMG $TMPDIR/hdr0
24 read_luks2_bin_hdr1 $TGT_IMG $TMPDIR/hdr1
29 read -r json_str < $TMPDIR/json0
31 pindex=$(strindex $json_str $PATTERN)
32 test $pindex -gt 0 || exit 2
35 offset=$((offset+pindex))
37 remain=$((LUKS2_JSON_SIZE*512-json_len-key_len-2)) # -2: closing '"' and terminating '\0'
38 if [ ${json_str:offset:1} = "}" ]; then
42 remain=$((remain-1)) # also count with separating ','
44 test $remain -gt 0 || exit 2
46 fill=$(repeat_str "X" $remain)"\""
48 printf $format_str $KEY $fill ${json_str:$offset} | _dd of=$TMPDIR/json0 bs=1 seek=$offset conv=notrunc
50 merge_bin_hdr_with_json $TMPDIR/hdr0 $TMPDIR/json0 $TMPDIR/area0
51 erase_checksum $TMPDIR/area0
52 chks0=$(calc_sha256_checksum_file $TMPDIR/area0)
53 write_checksum $chks0 $TMPDIR/area0
54 write_luks2_hdr0 $TMPDIR/area0 $TGT_IMG
55 kill_bin_hdr $TMPDIR/hdr1
56 write_luks2_hdr1 $TMPDIR/hdr1 $TGT_IMG
61 read_luks2_bin_hdr1 $TGT_IMG $TMPDIR/hdr_res1
62 local str_res1=$(head -c 6 $TMPDIR/hdr_res1)
63 test "$str_res1" = "VACUUM" || exit 2
65 read_luks2_json0 $TGT_IMG $TMPDIR/json_res0
66 chks_res0=$(read_sha256_checksum $TGT_IMG)
67 test "$chks0" = "$chks_res0" || exit 2
68 #json_str_res0=$(< $TMPDIR/json_res0)
69 read -r json_str_res0 < $TMPDIR/json_res0
70 test ${#json_str_res0} -eq $((LUKS2_JSON_SIZE*512-1)) || exit 2
79 test $# -eq 2 || exit 1
81 TGT_IMG=$1/$(test_img_name $0)