8 # generate primary header with well-formed json but missing
11 # secondary header is corrupted on purpose as well
15 # $2 full source luks2 image
17 PATTERN="\"config\":{"
18 KEY="\"config_key\":\""
22 read -r json_str < $TMPDIR/json0
24 pindex=$(strindex $json_str $PATTERN)
25 test $pindex -gt 0 || exit 2
28 offset=$((offset+pindex))
30 remain=$((LUKS2_JSON_SIZE*512-key_len-json_len-1)) # -1: closing '"'
31 if [ ${json_str:offset:1} = "}" ]; then
35 remain=$((remain-1)) # also count with separating ','
37 test $remain -gt 0 || exit 2
39 fill=$(repeat_str "X" $remain)
40 fill=$(repeat_str "X" $remain)"\""
42 printf $format_str $KEY $fill ${json_str:$offset} | _dd of=$TMPDIR/json0 bs=1 seek=$offset conv=notrunc
44 lib_mangle_json_hdr0_kill_hdr1
49 lib_hdr1_killed || exit 2
50 lib_hdr0_checksum || exit 2
52 read_luks2_json0 $TGT_IMG $TMPDIR/json_res0
53 read -r json_str_res0 < $TMPDIR/json_res0
54 test ${#json_str_res0} -eq $((LUKS2_JSON_SIZE*512)) || exit 2