| 1 | #!/bin/bash |
| 2 | |
| 3 | PS4='$LINENO:' |
| 4 | [ -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".." |
| 5 | CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup |
| 6 | CRYPTSETUP_RAW=$CRYPTSETUP |
| 7 | |
| 8 | if [ -n "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 9 | CRYPTSETUP_VALGRIND=$CRYPTSETUP |
| 10 | else |
| 11 | CRYPTSETUP_VALGRIND=../.libs/cryptsetup |
| 12 | CRYPTSETUP_LIB_VALGRIND=../.libs |
| 13 | fi |
| 14 | IMG=reenc-mangle-data |
| 15 | IMG_HDR=$IMG.hdr |
| 16 | IMG_HDR_BCP=$IMG_HDR.bcp |
| 17 | IMG_JSON=$IMG.json |
| 18 | KEY1=key1 |
| 19 | DEV_NAME=reenc3492834 |
| 20 | |
| 21 | FAST_PBKDF2="--pbkdf pbkdf2 --pbkdf-force-iterations 1000" |
| 22 | CS_PWPARAMS="--disable-keyring --key-file $KEY1" |
| 23 | CS_PARAMS="-q --disable-locks $CS_PWPARAMS" |
| 24 | JSON_MSIZE=16384 |
| 25 | |
| 26 | remove_mapping() |
| 27 | { |
| 28 | [ -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME |
| 29 | rm -f $IMG $IMG_HDR $IMG_HDR_BCP $IMG_JSON $KEY1 >/dev/null 2>&1 |
| 30 | } |
| 31 | |
| 32 | fail() |
| 33 | { |
| 34 | local frame=0 |
| 35 | [ -n "$1" ] && echo "$1" |
| 36 | echo "FAILED backtrace:" |
| 37 | while caller $frame; do ((frame++)); done |
| 38 | remove_mapping |
| 39 | exit 2 |
| 40 | } |
| 41 | |
| 42 | _sigchld() { local c=$?; [ $c -eq 139 ] && fail "Segfault"; [ $c -eq 134 ] && fail "Aborted"; } |
| 43 | trap _sigchld CHLD |
| 44 | |
| 45 | skip() |
| 46 | { |
| 47 | [ -n "$1" ] && echo "$1" |
| 48 | remove_mapping |
| 49 | exit 77 |
| 50 | } |
| 51 | |
| 52 | bin_check() |
| 53 | { |
| 54 | command -v $1 >/dev/null || skip "WARNING: test require $1 binary, test skipped." |
| 55 | } |
| 56 | |
| 57 | img_json_save() |
| 58 | { |
| 59 | local _hdr=$IMG |
| 60 | [ -z "$1" ] || _hdr="$1" |
| 61 | # FIXME: why --json-file cannot be used? |
| 62 | $CRYPTSETUP luksDump --dump-json-metadata $_hdr | jq -c -M . | tr -d '\n' >$IMG_JSON |
| 63 | } |
| 64 | |
| 65 | img_json_dump() |
| 66 | { |
| 67 | img_json_save |
| 68 | jq . $IMG_JSON |
| 69 | } |
| 70 | |
| 71 | img_hash_save() |
| 72 | { |
| 73 | IMG_HASH=$(sha256sum $IMG | cut -d' ' -f 1) |
| 74 | } |
| 75 | |
| 76 | img_hash_unchanged() |
| 77 | { |
| 78 | local IMG_HASH2=$(sha256sum $IMG | cut -d' ' -f 1) |
| 79 | [ "$IMG_HASH" != "$IMG_HASH2" ] && fail "Image changed!" |
| 80 | } |
| 81 | |
| 82 | img_prepare_raw() # $1 options |
| 83 | { |
| 84 | remove_mapping |
| 85 | |
| 86 | if [ ! -e $KEY1 ]; then |
| 87 | dd if=/dev/urandom of=$KEY1 count=1 bs=32 >/dev/null 2>&1 |
| 88 | fi |
| 89 | |
| 90 | truncate -s 32M $IMG || fail |
| 91 | $CRYPTSETUP luksFormat $FAST_PBKDF2 $CS_PARAMS --luks2-metadata-size $JSON_MSIZE $IMG $1 || fail |
| 92 | } |
| 93 | |
| 94 | img_prepare() # $1 options |
| 95 | { |
| 96 | img_prepare_raw |
| 97 | $CRYPTSETUP reencrypt $IMG $CS_PARAMS -q --init-only --resilience none $1 >/dev/null 2>&1 |
| 98 | [ $? -ne 0 ] && skip "Reencryption unsupported, test skipped." |
| 99 | img_json_save |
| 100 | img_hash_save |
| 101 | } |
| 102 | |
| 103 | _dd() |
| 104 | { |
| 105 | dd $@ status=none conv=notrunc bs=1 |
| 106 | } |
| 107 | |
| 108 | # header mangle functions |
| 109 | img_update_json() |
| 110 | { |
| 111 | local _hdr="$IMG" |
| 112 | local LUKS2_BIN1_OFFSET=448 |
| 113 | local LUKS2_BIN2_OFFSET=$((LUKS2_BIN1_OFFSET + $JSON_MSIZE)) |
| 114 | local LUKS2_JSON_SIZE=$(($JSON_MSIZE - 4096)) |
| 115 | |
| 116 | # if present jq script, mangle JSON |
| 117 | if [ -n "$1" ]; then |
| 118 | local JSON=$(cat $IMG_JSON) |
| 119 | echo $JSON | jq -M -c "$1" >$IMG_JSON || fail |
| 120 | local JSON=$(cat $IMG_JSON) |
| 121 | echo $JSON | tr -d '\n' >$IMG_JSON || fail |
| 122 | fi |
| 123 | |
| 124 | [ -z "$2" ] || _hdr="$2" |
| 125 | |
| 126 | # wipe JSON areas |
| 127 | _dd if=/dev/zero of=$_hdr count=$LUKS2_JSON_SIZE seek=4096 |
| 128 | _dd if=/dev/zero of=$_hdr count=$LUKS2_JSON_SIZE seek=$(($JSON_MSIZE + 4096)) |
| 129 | |
| 130 | # write JSON data |
| 131 | _dd if=$IMG_JSON of=$_hdr count=$LUKS2_JSON_SIZE seek=4096 |
| 132 | _dd if=$IMG_JSON of=$_hdr count=$LUKS2_JSON_SIZE seek=$(($JSON_MSIZE + 4096)) |
| 133 | |
| 134 | # erase sha256 checksums |
| 135 | _dd if=/dev/zero of=$_hdr count=64 seek=$LUKS2_BIN1_OFFSET |
| 136 | _dd if=/dev/zero of=$_hdr count=64 seek=$LUKS2_BIN2_OFFSET |
| 137 | |
| 138 | # calculate sha256 and write chexksums |
| 139 | local SUM1_HEX=$(_dd if=$_hdr count=$JSON_MSIZE | sha256sum | cut -d ' ' -f 1) |
| 140 | echo $SUM1_HEX | xxd -r -p | _dd of=$_hdr seek=$LUKS2_BIN1_OFFSET count=64 || fail |
| 141 | |
| 142 | local SUM2_HEX=$(_dd if=$_hdr skip=$JSON_MSIZE count=$JSON_MSIZE | sha256sum | cut -d ' ' -f 1) |
| 143 | echo $SUM2_HEX | xxd -r -p | _dd of=$_hdr seek=$LUKS2_BIN2_OFFSET count=64 || fail |
| 144 | |
| 145 | img_hash_save |
| 146 | } |
| 147 | |
| 148 | img_check_ok() |
| 149 | { |
| 150 | if [ $(id -u) == 0 ]; then |
| 151 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME || fail |
| 152 | $CRYPTSETUP close $DEV_NAME || fail |
| 153 | fi |
| 154 | |
| 155 | $CRYPTSETUP repair $IMG $CS_PARAMS || fail |
| 156 | } |
| 157 | |
| 158 | img_check_dump_ok() |
| 159 | { |
| 160 | $CRYPTSETUP luksDump $IMG >/dev/null || fail |
| 161 | img_check_fail |
| 162 | } |
| 163 | |
| 164 | img_check_fail() |
| 165 | { |
| 166 | if [ $(id -u) == 0 ]; then |
| 167 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME 2>/dev/null && fail |
| 168 | fi |
| 169 | |
| 170 | $CRYPTSETUP repair $IMG $CS_PARAMS 2>/dev/null && fail |
| 171 | img_hash_unchanged |
| 172 | } |
| 173 | |
| 174 | img_run_reenc_ok() |
| 175 | { |
| 176 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS -q --disable-locks --force-offline-reencrypt --resilience none || fail |
| 177 | } |
| 178 | |
| 179 | img_run_reenc_ok_data_shift() |
| 180 | { |
| 181 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS -q --disable-locks --force-offline-reencrypt || fail |
| 182 | } |
| 183 | |
| 184 | img_run_reenc_fail() |
| 185 | { |
| 186 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS --force-offline-reencrypt --disable-locks -q 2>/dev/null && fail "Reencryption passed (should have failed)." |
| 187 | img_hash_unchanged |
| 188 | } |
| 189 | |
| 190 | img_check_fail_repair() |
| 191 | { |
| 192 | if [ $(id -u) == 0 ]; then |
| 193 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME 2>/dev/null && fail |
| 194 | fi |
| 195 | |
| 196 | img_run_reenc_fail |
| 197 | |
| 198 | # repair metadata |
| 199 | $CRYPTSETUP repair $IMG $CS_PARAMS || fail |
| 200 | |
| 201 | img_check_ok |
| 202 | } |
| 203 | |
| 204 | img_check_fail_repair_ok() |
| 205 | { |
| 206 | img_check_fail_repair |
| 207 | img_run_reenc_ok |
| 208 | } |
| 209 | |
| 210 | img_check_fail_repair_ok_data_shift() |
| 211 | { |
| 212 | img_check_fail_repair |
| 213 | img_run_reenc_ok_data_shift |
| 214 | } |
| 215 | |
| 216 | valgrind_setup() |
| 217 | { |
| 218 | bin_check valgrind |
| 219 | [ ! -f $CRYPTSETUP_VALGRIND ] && fail "Unable to get location of cryptsetup executable." |
| 220 | [ ! -f valg.sh ] && fail "Unable to get location of valg runner script." |
| 221 | if [ -z "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then |
| 222 | export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH" |
| 223 | fi |
| 224 | CRYPTSETUP=valgrind_run |
| 225 | CRYPTSETUP_RAW="./valg.sh ${CRYPTSETUP_VALGRIND}" |
| 226 | } |
| 227 | |
| 228 | valgrind_run() |
| 229 | { |
| 230 | export INFOSTRING="$(basename ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" |
| 231 | $CRYPTSETUP_RAW "$@" |
| 232 | } |
| 233 | |
| 234 | [ ! -x "$CRYPTSETUP" ] && skip "Cannot find $CRYPTSETUP, test skipped." |
| 235 | |
| 236 | bin_check jq |
| 237 | bin_check sha256sum |
| 238 | bin_check xxd |
| 239 | |
| 240 | export LANG=C |
| 241 | |
| 242 | [ -n "$VALG" ] && valgrind_setup && CRYPTSETUP=valgrind_run |
| 243 | |
| 244 | echo "[1] Reencryption with old flag is rejected" |
| 245 | img_prepare |
| 246 | img_update_json '.config.requirements.mandatory = ["online-reencryptx"]' |
| 247 | img_check_fail |
| 248 | img_update_json '.config.requirements.mandatory = ["online-reencrypt-v2"]' |
| 249 | img_check_ok |
| 250 | img_run_reenc_ok |
| 251 | img_check_ok |
| 252 | |
| 253 | # Simulate old reencryption with no digest (repairable) |
| 254 | img_prepare |
| 255 | img_update_json 'del(.digests."2") | .config.requirements.mandatory = ["online-reencrypt"]' |
| 256 | img_check_fail_repair_ok |
| 257 | |
| 258 | # Simulate future version of reencrypt flag (should pass luksDump) |
| 259 | img_prepare |
| 260 | img_update_json '.config.requirements.mandatory = ["online-reencrypt-v999"]' |
| 261 | img_check_dump_ok |
| 262 | |
| 263 | # Multiple reencrypt requirement flags makes LUKS2 invalid |
| 264 | img_prepare |
| 265 | img_update_json '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt-v999"]' |
| 266 | img_check_fail |
| 267 | |
| 268 | img_prepare |
| 269 | img_update_json '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt"]' |
| 270 | img_check_fail |
| 271 | |
| 272 | # just regular unknown requirement |
| 273 | img_prepare |
| 274 | img_update_json '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt-v3X"]' |
| 275 | img_check_dump_ok |
| 276 | |
| 277 | # This must fail for new releases |
| 278 | echo "[2] Old reencryption in-progress (journal)" |
| 279 | img_prepare |
| 280 | img_update_json ' |
| 281 | del(.digests."2") | |
| 282 | .keyslots."2".area.type = "journal" | |
| 283 | .segments = { |
| 284 | "0" : (.segments."0" + |
| 285 | {"size" : .keyslots."2".area.size} + |
| 286 | {"flags" : ["in-reencryption"]}), |
| 287 | "1" : (.segments."0" + |
| 288 | {"offset" : ((.segments."0".offset|tonumber) + |
| 289 | (.keyslots."2".area.size|tonumber))|tostring}), |
| 290 | "2" : .segments."1", |
| 291 | "3" : .segments."2" |
| 292 | } | |
| 293 | .digests."0".segments = ["1","2"] | |
| 294 | .digests."1".segments = ["0","3"] | |
| 295 | .config.requirements.mandatory = ["online-reencrypt"]' |
| 296 | img_check_fail_repair_ok |
| 297 | |
| 298 | echo "[3] Old reencryption in-progress (checksum)" |
| 299 | img_prepare |
| 300 | img_update_json ' |
| 301 | del(.digests."2") | |
| 302 | .keyslots."2".area.type = "checksum" | |
| 303 | .keyslots."2".area.hash = "sha256" | |
| 304 | .keyslots."2".area.sector_size = 4096 | |
| 305 | .segments = { |
| 306 | "0" : (.segments."0" + |
| 307 | {"size" : .keyslots."2".area.size} + |
| 308 | {"flags" : ["in-reencryption"]}), |
| 309 | "1" : (.segments."0" + |
| 310 | {"offset": ((.segments."0".offset|tonumber) + |
| 311 | (.keyslots."2".area.size|tonumber))|tostring}), |
| 312 | "2" : .segments."1", |
| 313 | "3" : .segments."2" |
| 314 | } | |
| 315 | .digests."0".segments = ["1","2"] | |
| 316 | .digests."1".segments = ["0","3"] | |
| 317 | .config.requirements.mandatory = ["online-reencrypt"]' |
| 318 | img_check_fail_repair_ok |
| 319 | |
| 320 | # Note: older tools cannot create this from commandline |
| 321 | echo "[4] Old decryption in-progress (journal)" |
| 322 | img_prepare |
| 323 | img_update_json ' |
| 324 | del(.digests."1") | |
| 325 | del(.digests."2") | |
| 326 | del(.keyslots."1") | |
| 327 | .keyslots."2".mode = "decrypt" | |
| 328 | .keyslots."2".area.type = "journal" | |
| 329 | .segments = { |
| 330 | "0" : { |
| 331 | "type" : "linear", |
| 332 | "offset" : .segments."0".offset, |
| 333 | "size" : .keyslots."2".area.size, |
| 334 | "flags" : ["in-reencryption"] |
| 335 | }, |
| 336 | "1" : (.segments."0" + |
| 337 | {"offset" : ((.segments."0".offset|tonumber) + |
| 338 | (.keyslots."2".area.size|tonumber))|tostring}), |
| 339 | "2" : .segments."1", |
| 340 | "3" : { |
| 341 | "type" : "linear", |
| 342 | "offset" : .segments."0".offset, |
| 343 | "size" : "dynamic", |
| 344 | "flags" : ["backup-final"] |
| 345 | } |
| 346 | } | |
| 347 | .digests."0".segments = ["1","2"] | |
| 348 | .config.requirements.mandatory = ["online-reencrypt"]' |
| 349 | img_check_fail_repair_ok |
| 350 | |
| 351 | echo "[5] Old decryption in-progress (checksum)" |
| 352 | img_prepare |
| 353 | img_update_json ' |
| 354 | del(.digests."1") | |
| 355 | del(.digests."2") | |
| 356 | del(.keyslots."1") | |
| 357 | .keyslots."2".mode = "decrypt" | |
| 358 | .keyslots."2".area.type = "checksum" | |
| 359 | .keyslots."2".area.hash = "sha256" | |
| 360 | .keyslots."2".area.sector_size = 4096 | |
| 361 | .segments = { |
| 362 | "0" : { |
| 363 | "type" : "linear", |
| 364 | "offset" : .segments."0".offset, |
| 365 | "size" : .keyslots."2".area.size, |
| 366 | "flags" : ["in-reencryption"] |
| 367 | }, |
| 368 | "1" : (.segments."0" + |
| 369 | {"offset" : ((.segments."0".offset|tonumber) + |
| 370 | (.keyslots."2".area.size|tonumber))|tostring}), |
| 371 | "2" : .segments."1", |
| 372 | "3" : { |
| 373 | "type" : "linear", |
| 374 | "offset" : .segments."0".offset, |
| 375 | "size" : "dynamic", |
| 376 | "flags" : ["backup-final"] |
| 377 | } |
| 378 | } | |
| 379 | .digests."0".segments = ["1","2"] | |
| 380 | .config.requirements.mandatory = ["online-reencrypt"]' |
| 381 | img_check_fail_repair_ok |
| 382 | |
| 383 | # Note - offset is set to work with the old version (with a datashift bug) |
| 384 | echo "[6] Old reencryption in-progress (datashift)" |
| 385 | img_prepare |
| 386 | img_update_json ' |
| 387 | del(.digests."2") | |
| 388 | .keyslots."2".direction = "backward" | |
| 389 | .keyslots."2".area.type = "datashift" | |
| 390 | .keyslots."2".area.size = "4096" | |
| 391 | .keyslots."2".area.shift_size = ((1 * 1024 * 1024)|tostring) | |
| 392 | .segments = { |
| 393 | "0" : (.segments."0" + |
| 394 | {"size" : ((13 * 1024 * 1024)|tostring)}), |
| 395 | "1" : (.segments."0" + |
| 396 | {"offset" : ((30 * 1024 * 1024)|tostring)}), |
| 397 | "2" : .segments."1", |
| 398 | "3" : (.segments."2" + |
| 399 | {"offset" : ((17 * 1024 * 1024)|tostring)}), |
| 400 | } | |
| 401 | .digests."0".segments = ["0","2"] | |
| 402 | .digests."1".segments = ["1","3"] | |
| 403 | .config.requirements.mandatory = ["online-reencrypt"]' |
| 404 | img_check_fail_repair_ok_data_shift |
| 405 | |
| 406 | # |
| 407 | # NEW metadata (with reenc digest) |
| 408 | # |
| 409 | echo "[7] Reencryption with various mangled metadata" |
| 410 | |
| 411 | # Normal situation |
| 412 | img_prepare |
| 413 | img_run_reenc_ok |
| 414 | img_check_ok |
| 415 | |
| 416 | # The same in various steps. |
| 417 | # Repair must validate not only metadata, but also reencryption digest. |
| 418 | img_prepare |
| 419 | img_update_json 'del(.digests."2")' |
| 420 | img_check_fail_repair_ok |
| 421 | |
| 422 | img_prepare '--reduce-device-size 2M' |
| 423 | img_update_json '.keyslots."2".area.shift_size = ((.keyslots."2".area.shift_size|tonumber / 2)|tostring)' |
| 424 | img_check_fail |
| 425 | |
| 426 | img_prepare |
| 427 | img_update_json ' |
| 428 | .keyslots."2".area.type = "checksum" | |
| 429 | .keyslots."2".area.hash = "sha256" | |
| 430 | .keyslots."2".area.sector_size = 4096' |
| 431 | img_check_fail |
| 432 | |
| 433 | img_prepare |
| 434 | img_update_json '.keyslots."2".area.type = "journal"' |
| 435 | img_check_fail |
| 436 | |
| 437 | img_prepare |
| 438 | img_update_json '.keyslots."2".mode = "decrypt"' |
| 439 | img_check_fail |
| 440 | |
| 441 | img_prepare |
| 442 | img_update_json '.keyslots."2".direction = "backward"' |
| 443 | img_check_fail |
| 444 | |
| 445 | # key_size must be 1 |
| 446 | img_prepare |
| 447 | img_update_json '.keyslots."2".key_size = 16' |
| 448 | img_check_fail |
| 449 | |
| 450 | # Mangling segments |
| 451 | img_prepare |
| 452 | img_update_json 'del(.segments."1")' |
| 453 | img_check_fail |
| 454 | |
| 455 | img_prepare |
| 456 | img_update_json '.segments."0".encryption = "aes-cbc-null"' |
| 457 | img_check_fail |
| 458 | |
| 459 | img_prepare |
| 460 | img_update_json '.segments."1".encryption = "aes-cbc-null"' |
| 461 | img_check_fail |
| 462 | |
| 463 | img_prepare |
| 464 | img_update_json '.segments."2".encryption = "aes-cbc-null"' |
| 465 | img_check_fail |
| 466 | |
| 467 | # Mangling digests |
| 468 | img_prepare |
| 469 | img_update_json ' |
| 470 | .digests."2" = .digests."0" | |
| 471 | .digests."2".keyslots = ["2"] | |
| 472 | .digests."2".segments = []' |
| 473 | img_check_fail |
| 474 | |
| 475 | img_prepare |
| 476 | img_update_json '.digests."2".iterations = 1111' |
| 477 | img_check_fail |
| 478 | |
| 479 | # Simulate correct progress |
| 480 | img_prepare |
| 481 | img_update_json ' |
| 482 | .segments = { |
| 483 | "0" : (.segments."0" + |
| 484 | {"size" : ((1 * 1024 * 1024)|tostring)}), |
| 485 | "1" : (.segments."0" + |
| 486 | {"offset" : ((17 * 1024 * 1024)|tostring)}), |
| 487 | "2" : .segments."1", |
| 488 | "3" : .segments."2" |
| 489 | } | |
| 490 | .digests."0".segments = ["1","2"] | |
| 491 | .digests."1".segments = ["0","3"]' |
| 492 | img_check_ok |
| 493 | |
| 494 | # Mangling keyslots |
| 495 | |
| 496 | # Set reencrypt slot to non-ignore priority |
| 497 | # This should be benign, just avoid noisy messages |
| 498 | img_prepare |
| 499 | img_update_json 'del(.keyslots."2".priority)' |
| 500 | img_check_ok |
| 501 | |
| 502 | # Flags |
| 503 | |
| 504 | # Remove mandatory reenc flag, but keep reenc metadata |
| 505 | img_prepare |
| 506 | img_update_json '.config.requirements.mandatory = []' |
| 507 | img_check_fail |
| 508 | |
| 509 | # Unknown segment flag, should be ignored |
| 510 | img_prepare |
| 511 | img_update_json '.segments."0".flags = ["dead-parrot"]' |
| 512 | img_check_ok |
| 513 | |
| 514 | echo "[8] Reencryption with AEAD is not supported" |
| 515 | img_prepare_raw |
| 516 | img_json_save |
| 517 | img_update_json ' |
| 518 | .segments."0".integrity = { |
| 519 | "type" : "hmac(sha256)", |
| 520 | "journal_encryption": "none", |
| 521 | "journal_integrity": "none" |
| 522 | }' |
| 523 | $CRYPTSETUP reencrypt $IMG $CS_PARAMS >/dev/null 2>&1 && fail |
| 524 | |
| 525 | echo "[9] Decryption with datashift" |
| 526 | img_prepare_raw |
| 527 | $CRYPTSETUP reencrypt $CS_PARAMS --decrypt --init-only --force-offline-reencrypt --resilience checksum --header $IMG_HDR $IMG || fail |
| 528 | cp $IMG_HDR $IMG_HDR_BCP |
| 529 | |
| 530 | # change hash |
| 531 | img_json_save $IMG_HDR_BCP |
| 532 | img_update_json '.keyslots."1".area.hash = "sha12345"' $IMG_HDR |
| 533 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/null && fail |
| 534 | |
| 535 | # change sector size |
| 536 | img_json_save $IMG_HDR_BCP |
| 537 | img_update_json '.keyslots."1".area.sector_size = 1024' $IMG_HDR |
| 538 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/null && fail |
| 539 | |
| 540 | # replace with new resilience mode |
| 541 | img_json_save $IMG_HDR_BCP |
| 542 | img_update_json 'del(.keyslots."1".area.hash) | |
| 543 | del(.keyslots."1".sector_size) | |
| 544 | .keyslots."1".area.type = "datashift-journal"' $IMG_HDR |
| 545 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/null && fail |
| 546 | |
| 547 | # downgrade reencryption requirement |
| 548 | img_json_save $IMG_HDR_BCP |
| 549 | img_update_json '.config.requirements.mandatory = ["online-reencrypt-v2"]' $IMG_HDR |
| 550 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/null && fail |
| 551 | |
| 552 | # change datashift value |
| 553 | img_json_save $IMG_HDR_BCP |
| 554 | img_update_json '.keyslots."1".area.shift_size = (((.keyslots."1".area.shift_size | tonumber) - 4096) | tostring)' $IMG_HDR |
| 555 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/null && fail |
| 556 | |
| 557 | remove_mapping |
| 558 | exit 0 |