| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | PS4='$LINENO:' |
| 4 | [scip-shell system . . `[`. -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".." |
| 5 | CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup |
| 6 | CRYPTSETUP_RAW=$CRYPTSETUP |
| 7 | |
| 8 | if [scip-shell system . . `[`. -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_mappingscip-shell shell shell-project 0.0.0 remove_mapping().() |
| 27 | { |
| 28 | [scip-shell system . . `[`. -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME |
| 29 | rmscip-shell system . . rm. -f $IMG $IMG_HDR $IMG_HDR_BCP $IMG_JSON $KEY1 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 30 | } |
| 31 | |
| 32 | failscip-shell shell shell-project 0.0.0 fail().() |
| 33 | { |
| 34 | local frame=0 |
| 35 | [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "$1" |
| 36 | echoscip-shell system . . echo. "FAILED backtrace:" |
| 37 | while caller $frame; do ((frame++)); done |
| 38 | remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping(). |
| 39 | exit 2 |
| 40 | } |
| 41 | |
| 42 | _sigchldscip-shell shell shell-project 0.0.0 _sigchld().() { local c=$?; [scip-shell system . . `[`. $c -eq 139 ] && failscip-shell shell shell-project 0.0.0 fail(). "Segfault"; [scip-shell system . . `[`. $c -eq 134 ] && failscip-shell shell shell-project 0.0.0 fail(). "Aborted"; } |
| 43 | trap _sigchld CHLD |
| 44 | |
| 45 | skipscip-shell shell shell-project 0.0.0 skip().() |
| 46 | { |
| 47 | [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "$1" |
| 48 | remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping(). |
| 49 | exit 77 |
| 50 | } |
| 51 | |
| 52 | bin_checkscip-shell shell shell-project 0.0.0 bin_check().() |
| 53 | { |
| 54 | command -v $1 >/dev/nullscip-shell filesystem . . `/dev/null`. || skipscip-shell shell shell-project 0.0.0 skip(). "WARNING: test require $1 binary, test skipped." |
| 55 | } |
| 56 | |
| 57 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save().() |
| 58 | { |
| 59 | local _hdr=$IMG |
| 60 | [scip-shell system . . `[`. -z "$1" ] || _hdr="$1" |
| 61 | # FIXME: why --json-file cannot be used? |
| 62 | $CRYPTSETUP luksDump --dump-json-metadata $_hdr | jqscip-shell system . . jq. -c -M . | trscip-shell system . . tr. -d '\n' >$IMG_JSON |
| 63 | } |
| 64 | |
| 65 | img_json_dumpscip-shell shell shell-project 0.0.0 img_json_dump().() |
| 66 | { |
| 67 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). |
| 68 | jqscip-shell system . . jq. . $IMG_JSON |
| 69 | } |
| 70 | |
| 71 | img_hash_savescip-shell shell shell-project 0.0.0 img_hash_save().() |
| 72 | { |
| 73 | IMG_HASH=$(sha256sumscip-shell system . . sha256sum. $IMG | cutscip-shell system . . cut. -d' ' -f 1) |
| 74 | } |
| 75 | |
| 76 | img_hash_unchangedscip-shell shell shell-project 0.0.0 img_hash_unchanged().() |
| 77 | { |
| 78 | local IMG_HASH2=$(sha256sumscip-shell system . . sha256sum. $IMG | cutscip-shell system . . cut. -d' ' -f 1) |
| 79 | [scip-shell system . . `[`. "$IMG_HASH" != "$IMG_HASH2" ] && failscip-shell shell shell-project 0.0.0 fail(). "Image changed!" |
| 80 | } |
| 81 | |
| 82 | img_prepare_rawscip-shell shell shell-project 0.0.0 img_prepare_raw().() # $1 options |
| 83 | { |
| 84 | remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping(). |
| 85 | |
| 86 | if [scip-shell system . . `[`. ! -e $KEY1 ]; then |
| 87 | ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. of=$KEY1 count=1 bs=32 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 88 | fi |
| 89 | |
| 90 | truncatescip-shell system . . truncate. -s 32M $IMG || failscip-shell shell shell-project 0.0.0 fail(). |
| 91 | $CRYPTSETUP luksFormat $FAST_PBKDF2 $CS_PARAMS --luks2-metadata-size $JSON_MSIZE $IMG $1 || failscip-shell shell shell-project 0.0.0 fail(). |
| 92 | } |
| 93 | |
| 94 | img_preparescip-shell shell shell-project 0.0.0 img_prepare().() # $1 options |
| 95 | { |
| 96 | img_prepare_rawscip-shell shell shell-project 0.0.0 img_prepare_raw(). |
| 97 | $CRYPTSETUP reencrypt $IMG $CS_PARAMS -q --init-only --resilience none $1 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 98 | [scip-shell system . . `[`. $? -ne 0 ] && skipscip-shell shell shell-project 0.0.0 skip(). "Reencryption unsupported, test skipped." |
| 99 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). |
| 100 | img_hash_savescip-shell shell shell-project 0.0.0 img_hash_save(). |
| 101 | } |
| 102 | |
| 103 | _ddscip-shell shell shell-project 0.0.0 _dd().() |
| 104 | { |
| 105 | ddscip-shell system . . dd. $@ status=none conv=notrunc bs=1 |
| 106 | } |
| 107 | |
| 108 | # header mangle functions |
| 109 | img_update_jsonscip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -n "$1" ]; then |
| 118 | local JSON=$(catscip-shell system . . cat. $IMG_JSON) |
| 119 | echoscip-shell system . . echo. $JSON | jqscip-shell system . . jq. -M -c "$1" >$IMG_JSON || failscip-shell shell shell-project 0.0.0 fail(). |
| 120 | local JSON=$(catscip-shell system . . cat. $IMG_JSON) |
| 121 | echoscip-shell system . . echo. $JSON | trscip-shell system . . tr. -d '\n' >$IMG_JSON || failscip-shell shell shell-project 0.0.0 fail(). |
| 122 | fi |
| 123 | |
| 124 | [scip-shell system . . `[`. -z "$2" ] || _hdr="$2" |
| 125 | |
| 126 | # wipe JSON areas |
| 127 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$_hdr count=$LUKS2_JSON_SIZE seek=4096 |
| 128 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$_hdr count=$LUKS2_JSON_SIZE seek=$(($JSON_MSIZE + 4096)) |
| 129 | |
| 130 | # write JSON data |
| 131 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=$IMG_JSON of=$_hdr count=$LUKS2_JSON_SIZE seek=4096 |
| 132 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=$IMG_JSON of=$_hdr count=$LUKS2_JSON_SIZE seek=$(($JSON_MSIZE + 4096)) |
| 133 | |
| 134 | # erase sha256 checksums |
| 135 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$_hdr count=64 seek=$LUKS2_BIN1_OFFSET |
| 136 | _ddscip-shell shell shell-project 0.0.0 _dd(). if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$_hdr count=64 seek=$LUKS2_BIN2_OFFSET |
| 137 | |
| 138 | # calculate sha256 and write chexksums |
| 139 | local SUM1_HEX=$(_ddscip-shell shell shell-project 0.0.0 _dd(). if=$_hdr count=$JSON_MSIZE | sha256sumscip-shell system . . sha256sum. | cutscip-shell system . . cut. -d ' ' -f 1) |
| 140 | echoscip-shell system . . echo. $SUM1_HEX | xxd -r -p | _ddscip-shell shell shell-project 0.0.0 _dd(). of=$_hdr seek=$LUKS2_BIN1_OFFSET count=64 || failscip-shell shell shell-project 0.0.0 fail(). |
| 141 | |
| 142 | local SUM2_HEX=$(_ddscip-shell shell shell-project 0.0.0 _dd(). if=$_hdr skip=$JSON_MSIZE count=$JSON_MSIZE | sha256sumscip-shell system . . sha256sum. | cutscip-shell system . . cut. -d ' ' -f 1) |
| 143 | echoscip-shell system . . echo. $SUM2_HEX | xxd -r -p | _ddscip-shell shell shell-project 0.0.0 _dd(). of=$_hdr seek=$LUKS2_BIN2_OFFSET count=64 || failscip-shell shell shell-project 0.0.0 fail(). |
| 144 | |
| 145 | img_hash_savescip-shell shell shell-project 0.0.0 img_hash_save(). |
| 146 | } |
| 147 | |
| 148 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok().() |
| 149 | { |
| 150 | if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) == 0 ]; then |
| 151 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 152 | $CRYPTSETUP close $DEV_NAME || failscip-shell shell shell-project 0.0.0 fail(). |
| 153 | fi |
| 154 | |
| 155 | $CRYPTSETUP repair $IMG $CS_PARAMS || failscip-shell shell shell-project 0.0.0 fail(). |
| 156 | } |
| 157 | |
| 158 | img_check_dump_okscip-shell shell shell-project 0.0.0 img_check_dump_ok().() |
| 159 | { |
| 160 | $CRYPTSETUP luksDump $IMG >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). |
| 161 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 162 | } |
| 163 | |
| 164 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail().() |
| 165 | { |
| 166 | if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) == 0 ]; then |
| 167 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 168 | fi |
| 169 | |
| 170 | $CRYPTSETUP repair $IMG $CS_PARAMS 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 171 | img_hash_unchangedscip-shell shell shell-project 0.0.0 img_hash_unchanged(). |
| 172 | } |
| 173 | |
| 174 | img_run_reenc_okscip-shell shell shell-project 0.0.0 img_run_reenc_ok().() |
| 175 | { |
| 176 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS -q --disable-locks --force-offline-reencrypt --resilience none || failscip-shell shell shell-project 0.0.0 fail(). |
| 177 | } |
| 178 | |
| 179 | img_run_reenc_ok_data_shiftscip-shell shell shell-project 0.0.0 img_run_reenc_ok_data_shift().() |
| 180 | { |
| 181 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS -q --disable-locks --force-offline-reencrypt || failscip-shell shell shell-project 0.0.0 fail(). |
| 182 | } |
| 183 | |
| 184 | img_run_reenc_failscip-shell shell shell-project 0.0.0 img_run_reenc_fail().() |
| 185 | { |
| 186 | $CRYPTSETUP_RAW reencrypt $IMG $CS_PWPARAMS --force-offline-reencrypt --disable-locks -q 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). "Reencryption passed (should have failed)." |
| 187 | img_hash_unchangedscip-shell shell shell-project 0.0.0 img_hash_unchanged(). |
| 188 | } |
| 189 | |
| 190 | img_check_fail_repairscip-shell shell shell-project 0.0.0 img_check_fail_repair().() |
| 191 | { |
| 192 | if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) == 0 ]; then |
| 193 | $CRYPTSETUP open $CS_PWPARAMS $IMG $DEV_NAME 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 194 | fi |
| 195 | |
| 196 | img_run_reenc_failscip-shell shell shell-project 0.0.0 img_run_reenc_fail(). |
| 197 | |
| 198 | # repair metadata |
| 199 | $CRYPTSETUP repair $IMG $CS_PARAMS || failscip-shell shell shell-project 0.0.0 fail(). |
| 200 | |
| 201 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 202 | } |
| 203 | |
| 204 | img_check_fail_repair_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok().() |
| 205 | { |
| 206 | img_check_fail_repairscip-shell shell shell-project 0.0.0 img_check_fail_repair(). |
| 207 | img_run_reenc_okscip-shell shell shell-project 0.0.0 img_run_reenc_ok(). |
| 208 | } |
| 209 | |
| 210 | img_check_fail_repair_ok_data_shiftscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok_data_shift().() |
| 211 | { |
| 212 | img_check_fail_repairscip-shell shell shell-project 0.0.0 img_check_fail_repair(). |
| 213 | img_run_reenc_ok_data_shiftscip-shell shell shell-project 0.0.0 img_run_reenc_ok_data_shift(). |
| 214 | } |
| 215 | |
| 216 | valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup().() |
| 217 | { |
| 218 | bin_checkscip-shell shell shell-project 0.0.0 bin_check(). valgrind |
| 219 | [scip-shell system . . `[`. ! -f $CRYPTSETUP_VALGRIND ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of cryptsetup executable." |
| 220 | [scip-shell system . . `[`. ! -f valg.sh ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of valg runner script." |
| 221 | if [scip-shell system . . `[`. -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_runscip-shell shell shell-project 0.0.0 valgrind_run().() |
| 229 | { |
| 230 | export INFOSTRING="$(basenamescip-shell system . . basename. ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" |
| 231 | $CRYPTSETUP_RAW "$@" |
| 232 | } |
| 233 | |
| 234 | [scip-shell system . . `[`. ! -x "$CRYPTSETUP" ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot find $CRYPTSETUP, test skipped." |
| 235 | |
| 236 | bin_checkscip-shell shell shell-project 0.0.0 bin_check(). jq |
| 237 | bin_checkscip-shell shell shell-project 0.0.0 bin_check(). sha256sum |
| 238 | bin_checkscip-shell shell shell-project 0.0.0 bin_check(). xxd |
| 239 | |
| 240 | export LANG=C |
| 241 | |
| 242 | [scip-shell system . . `[`. -n "$VALG" ] && valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup(). && CRYPTSETUP=valgrind_run |
| 243 | |
| 244 | echoscip-shell system . . echo. "[1] Reencryption with old flag is rejected" |
| 245 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 246 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = ["online-reencryptx"]' |
| 247 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 248 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = ["online-reencrypt-v2"]' |
| 249 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 250 | img_run_reenc_okscip-shell shell shell-project 0.0.0 img_run_reenc_ok(). |
| 251 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 252 | |
| 253 | # Simulate old reencryption with no digest (repairable) |
| 254 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 255 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). 'del(.digests."2") | .config.requirements.mandatory = ["online-reencrypt"]' |
| 256 | img_check_fail_repair_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 257 | |
| 258 | # Simulate future version of reencrypt flag (should pass luksDump) |
| 259 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 260 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = ["online-reencrypt-v999"]' |
| 261 | img_check_dump_okscip-shell shell shell-project 0.0.0 img_check_dump_ok(). |
| 262 | |
| 263 | # Multiple reencrypt requirement flags makes LUKS2 invalid |
| 264 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 265 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt-v999"]' |
| 266 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 267 | |
| 268 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 269 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt"]' |
| 270 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 271 | |
| 272 | # just regular unknown requirement |
| 273 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 274 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = .config.requirements.mandatory + ["online-reencrypt-v3X"]' |
| 275 | img_check_dump_okscip-shell shell shell-project 0.0.0 img_check_dump_ok(). |
| 276 | |
| 277 | # This must fail for new releases |
| 278 | echoscip-shell system . . echo. "[2] Old reencryption in-progress (journal)" |
| 279 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 280 | img_update_jsonscip-shell shell shell-project 0.0.0 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_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 297 | |
| 298 | echoscip-shell system . . echo. "[3] Old reencryption in-progress (checksum)" |
| 299 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 300 | img_update_jsonscip-shell shell shell-project 0.0.0 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_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 319 | |
| 320 | # Note: older tools cannot create this from commandline |
| 321 | echoscip-shell system . . echo. "[4] Old decryption in-progress (journal)" |
| 322 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 323 | img_update_jsonscip-shell shell shell-project 0.0.0 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_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 350 | |
| 351 | echoscip-shell system . . echo. "[5] Old decryption in-progress (checksum)" |
| 352 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 353 | img_update_jsonscip-shell shell shell-project 0.0.0 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_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 382 | |
| 383 | # Note - offset is set to work with the old version (with a datashift bug) |
| 384 | echoscip-shell system . . echo. "[6] Old reencryption in-progress (datashift)" |
| 385 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 386 | img_update_jsonscip-shell shell shell-project 0.0.0 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_shiftscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok_data_shift(). |
| 405 | |
| 406 | # |
| 407 | # NEW metadata (with reenc digest) |
| 408 | # |
| 409 | echoscip-shell system . . echo. "[7] Reencryption with various mangled metadata" |
| 410 | |
| 411 | # Normal situation |
| 412 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 413 | img_run_reenc_okscip-shell shell shell-project 0.0.0 img_run_reenc_ok(). |
| 414 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 415 | |
| 416 | # The same in various steps. |
| 417 | # Repair must validate not only metadata, but also reencryption digest. |
| 418 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 419 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). 'del(.digests."2")' |
| 420 | img_check_fail_repair_okscip-shell shell shell-project 0.0.0 img_check_fail_repair_ok(). |
| 421 | |
| 422 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). '--reduce-device-size 2M' |
| 423 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."2".area.shift_size = ((.keyslots."2".area.shift_size|tonumber / 2)|tostring)' |
| 424 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 425 | |
| 426 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 427 | img_update_jsonscip-shell shell shell-project 0.0.0 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_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 432 | |
| 433 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 434 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."2".area.type = "journal"' |
| 435 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 436 | |
| 437 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 438 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."2".mode = "decrypt"' |
| 439 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 440 | |
| 441 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 442 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."2".direction = "backward"' |
| 443 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 444 | |
| 445 | # key_size must be 1 |
| 446 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 447 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."2".key_size = 16' |
| 448 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 449 | |
| 450 | # Mangling segments |
| 451 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 452 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). 'del(.segments."1")' |
| 453 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 454 | |
| 455 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 456 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.segments."0".encryption = "aes-cbc-null"' |
| 457 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 458 | |
| 459 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 460 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.segments."1".encryption = "aes-cbc-null"' |
| 461 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 462 | |
| 463 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 464 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.segments."2".encryption = "aes-cbc-null"' |
| 465 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 466 | |
| 467 | # Mangling digests |
| 468 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 469 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). ' |
| 470 | .digests."2" = .digests."0" | |
| 471 | .digests."2".keyslots = ["2"] | |
| 472 | .digests."2".segments = []' |
| 473 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 474 | |
| 475 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 476 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.digests."2".iterations = 1111' |
| 477 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 478 | |
| 479 | # Simulate correct progress |
| 480 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 481 | img_update_jsonscip-shell shell shell-project 0.0.0 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_okscip-shell shell shell-project 0.0.0 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_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 499 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). 'del(.keyslots."2".priority)' |
| 500 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 501 | |
| 502 | # Flags |
| 503 | |
| 504 | # Remove mandatory reenc flag, but keep reenc metadata |
| 505 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 506 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.config.requirements.mandatory = []' |
| 507 | img_check_failscip-shell shell shell-project 0.0.0 img_check_fail(). |
| 508 | |
| 509 | # Unknown segment flag, should be ignored |
| 510 | img_preparescip-shell shell shell-project 0.0.0 img_prepare(). |
| 511 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.segments."0".flags = ["dead-parrot"]' |
| 512 | img_check_okscip-shell shell shell-project 0.0.0 img_check_ok(). |
| 513 | |
| 514 | echoscip-shell system . . echo. "[8] Reencryption with AEAD is not supported" |
| 515 | img_prepare_rawscip-shell shell shell-project 0.0.0 img_prepare_raw(). |
| 516 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). |
| 517 | img_update_jsonscip-shell shell shell-project 0.0.0 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/nullscip-shell filesystem . . `/dev/null`. 2>&1 && failscip-shell shell shell-project 0.0.0 fail(). |
| 524 | |
| 525 | echoscip-shell system . . echo. "[9] Decryption with datashift" |
| 526 | img_prepare_rawscip-shell shell shell-project 0.0.0 img_prepare_raw(). |
| 527 | $CRYPTSETUP reencrypt $CS_PARAMS --decrypt --init-only --force-offline-reencrypt --resilience checksum --header $IMG_HDR $IMG || failscip-shell shell shell-project 0.0.0 fail(). |
| 528 | cpscip-shell system . . cp. $IMG_HDR $IMG_HDR_BCP |
| 529 | |
| 530 | # change hash |
| 531 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). $IMG_HDR_BCP |
| 532 | img_update_jsonscip-shell shell shell-project 0.0.0 img_update_json(). '.keyslots."1".area.hash = "sha12345"' $IMG_HDR |
| 533 | $CRYPTSETUP reencrypt --header $IMG_HDR $IMG $CS_PARAMS --force-offline-reencrypt 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 534 | |
| 535 | # change sector size |
| 536 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). $IMG_HDR_BCP |
| 537 | img_update_jsonscip-shell shell shell-project 0.0.0 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/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 539 | |
| 540 | # replace with new resilience mode |
| 541 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). $IMG_HDR_BCP |
| 542 | img_update_jsonscip-shell shell shell-project 0.0.0 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/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 546 | |
| 547 | # downgrade reencryption requirement |
| 548 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). $IMG_HDR_BCP |
| 549 | img_update_jsonscip-shell shell shell-project 0.0.0 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/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 551 | |
| 552 | # change datashift value |
| 553 | img_json_savescip-shell shell shell-project 0.0.0 img_json_save(). $IMG_HDR_BCP |
| 554 | img_update_jsonscip-shell shell shell-project 0.0.0 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/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail(). |
| 556 | |
| 557 | remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping(). |
| 558 | exit 0 |