omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / aienux / boot / boot_test.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/boot/boot_test.om: Pure-Omega behavioral self-test suite for Aienux Boot |
| 3 | note (CHANDOF3 Handoff, MODEL.MAP, A/B Native Image Slots, and ANB1 Netboot Protocol). |
| 4 | note Compose with: si/directives/om2.om aienux/boot/handoff.om aienux/boot/model_map.om aienux/boot/slot.om aienux/boot/netboot.om aienux/boot/boot_test.om om/tls/sha2.om |
| 5 | |
| 6 | text b_pass "PASS " |
| 7 | text b_fail "FAIL " |
| 8 | text b_nl "\n" |
| 9 | text b_t01 "handoff_valid_and_version_refusals" |
| 10 | text b_t02 "handoff_model_and_fb_validation" |
| 11 | text b_t03 "handoff_mmap_and_reserved_refusals" |
| 12 | text b_t04 "model_map_valid_and_negative_controls" |
| 13 | text b_t05 "slot_manifest_and_control_checks" |
| 14 | text b_t06 "slot_select_candidate_try_and_exhaust" |
| 15 | text b_t07 "slot_select_fallback_floor_and_recovery" |
| 16 | text b_t08 "slot_transitions_stage_promote_abandon" |
| 17 | text b_t09 "slot_boot_record_seal_verify_and_kernel_action" |
| 18 | text b_t10 "slot_verify_image_sha512_roundtrip" |
| 19 | text b_t11 "netboot_build_parse_all_types" |
| 20 | text b_t12 "netboot_negative_controls_and_chunks" |
| 21 | text b_sum "BOOT_TEST_PASS total=12 failed=0\n" |
| 22 | text b_fsum "BOOT_TEST_FAIL\n" |
| 23 | text b_commit "0123456789abcdef0123456789abcdef01234567" |
| 24 | text b_prov "aienux-om2-test" |
| 25 | text b_nb_done "verified ok" |
| 26 | |
| 27 | fn bwrite_all fd int buf view uchar * to bool |
| 28 | total = len buf |
| 29 | off = ulong 0 |
| 30 | while lt off total bound 4096 |
| 31 | n = write fd buf off sub total off |
| 32 | if le n 0 |
| 33 | ret false |
| 34 | end |
| 35 | off = add off ulong n |
| 36 | end |
| 37 | ret true |
| 38 | end |
| 39 | |
| 40 | fn breport name view uchar * ok bool to uint |
| 41 | if ok |
| 42 | w1 = bwrite_all 1 b_pass |
| 43 | w2 = bwrite_all 1 name |
| 44 | w3 = bwrite_all 1 b_nl |
| 45 | if and w1 and w2 w3 |
| 46 | ret 0 |
| 47 | end |
| 48 | ret 1 |
| 49 | end |
| 50 | w1 = bwrite_all 1 b_fail |
| 51 | w2 = bwrite_all 1 name |
| 52 | w3 = bwrite_all 1 b_nl |
| 53 | if and w1 and w2 w3 |
| 54 | ret 1 |
| 55 | end |
| 56 | ret 1 |
| 57 | end |
| 58 | |
| 59 | fn mk_valid_handoff dst edit uchar * to void |
| 60 | slot_zero_bytes dst HO_BYTES |
| 61 | boot_wr64_le dst HO_OFF_MAGIC HO_MAGIC_V3 |
| 62 | boot_wr32_le dst HO_OFF_FW_EL 2 |
| 63 | boot_wr32_le dst HO_OFF_DESC_VER HO_DESC_VERSION |
| 64 | boot_wr64_le dst HO_OFF_MAP_SIZE 480 |
| 65 | boot_wr64_le dst HO_OFF_DESC_SIZE 48 |
| 66 | end |
| 67 | |
| 68 | fn test_01_handoff_magic to bool |
| 69 | h = new uchar 232 0 |
| 70 | mk_valid_handoff h |
| 71 | if ne handoff_check h HO_OK |
| 72 | ret false |
| 73 | end |
| 74 | note CHANDOF1 and CHANDOF2 must fail with HO_ERR_UNSUP_VER |
| 75 | boot_wr64_le h HO_OFF_MAGIC HO_MAGIC_V1 |
| 76 | if ne handoff_check h HO_ERR_UNSUP_VER |
| 77 | ret false |
| 78 | end |
| 79 | boot_wr64_le h HO_OFF_MAGIC HO_MAGIC_V2 |
| 80 | if ne handoff_check h HO_ERR_UNSUP_VER |
| 81 | ret false |
| 82 | end |
| 83 | note Arbitrary garbage magic fails with HO_ERR_BAD_MAGIC |
| 84 | boot_wr64_le h HO_OFF_MAGIC 0xdeadbeefcafebabe |
| 85 | if ne handoff_check h HO_ERR_BAD_MAGIC |
| 86 | ret false |
| 87 | end |
| 88 | note Short buffer refused |
| 89 | short_h = new uchar 128 0 |
| 90 | if ne handoff_check short_h HO_ERR_SHORT |
| 91 | ret false |
| 92 | end |
| 93 | ret true |
| 94 | end |
| 95 | |
| 96 | fn test_02_handoff_model_fb to bool |
| 97 | h = new uchar 232 0 |
| 98 | mk_valid_handoff h |
| 99 | note Valid model present |
| 100 | boot_wr32_le h HO_OFF_MODEL_FLAGS or HO_MODEL_PRESENT HO_MODEL_BLOCKIO |
| 101 | boot_wr64_le h HO_OFF_MODEL_BASE 0x40000000 |
| 102 | boot_wr64_le h HO_OFF_MODEL_LEN 8192 |
| 103 | boot_wr32_le h HO_OFF_MODEL_BLK_SZ 4096 |
| 104 | boot_wr32_le h HO_OFF_MODEL_EXTENTS 2 |
| 105 | if ne handoff_check h HO_OK |
| 106 | ret false |
| 107 | end |
| 108 | note Unaligned model base refused |
| 109 | boot_wr64_le h HO_OFF_MODEL_BASE 0x40000100 |
| 110 | if ne handoff_check h HO_ERR_MODEL_ALIGN |
| 111 | ret false |
| 112 | end |
| 113 | note Spurious model field without PRESENT refused |
| 114 | mk_valid_handoff h |
| 115 | put h HO_OFF_MODEL_SHA256 1 |
| 116 | if ne handoff_check h HO_ERR_MODEL_SPURIOUS |
| 117 | ret false |
| 118 | end |
| 119 | note Valid linear GOP framebuffer |
| 120 | mk_valid_handoff h |
| 121 | boot_wr32_le h HO_OFF_FB_STATUS HO_FB_PRESENT |
| 122 | boot_wr32_le h HO_OFF_FB_FORMAT HO_FB_BGRX |
| 123 | boot_wr32_le h HO_OFF_FB_WIDTH 1920 |
| 124 | boot_wr32_le h HO_OFF_FB_HEIGHT 1080 |
| 125 | boot_wr32_le h HO_OFF_FB_PITCH 1920 |
| 126 | boot_wr64_le h HO_OFF_FB_BASE 0x80000000 |
| 127 | boot_wr64_le h HO_OFF_FB_SIZE mul mul ulong 1920 1080 4 |
| 128 | boot_wr32_le h HO_OFF_FB_GOP_HANDLES 1 |
| 129 | if ne handoff_check h HO_OK |
| 130 | ret false |
| 131 | end |
| 132 | note FB size too small refused |
| 133 | boot_wr64_le h HO_OFF_FB_SIZE 4096 |
| 134 | if ne handoff_check h HO_ERR_FB_SIZE |
| 135 | ret false |
| 136 | end |
| 137 | note FB pitch < width refused |
| 138 | boot_wr64_le h HO_OFF_FB_SIZE mul mul ulong 1920 1080 4 |
| 139 | boot_wr32_le h HO_OFF_FB_PITCH 1000 |
| 140 | if ne handoff_check h HO_ERR_FB_DIM |
| 141 | ret false |
| 142 | end |
| 143 | ret true |
| 144 | end |
| 145 | |
| 146 | fn test_03_handoff_mmap_rsvd to bool |
| 147 | h = new uchar 232 0 |
| 148 | mk_valid_handoff h |
| 149 | boot_wr32_le h HO_OFF_RESERVED0 1 |
| 150 | if ne handoff_check h HO_ERR_RESERVED0 |
| 151 | ret false |
| 152 | end |
| 153 | mk_valid_handoff h |
| 154 | boot_wr32_le h HO_OFF_RESERVED1 1 |
| 155 | if ne handoff_check h HO_ERR_RESERVED1 |
| 156 | ret false |
| 157 | end |
| 158 | mk_valid_handoff h |
| 159 | boot_wr64_le h HO_OFF_DESC_SIZE 32 |
| 160 | if ne handoff_check h HO_ERR_DESC_SIZE |
| 161 | ret false |
| 162 | end |
| 163 | mk_valid_handoff h |
| 164 | boot_wr32_le h HO_OFF_DESC_VER 2 |
| 165 | if ne handoff_check h HO_ERR_DESC_VER |
| 166 | ret false |
| 167 | end |
| 168 | mk_valid_handoff h |
| 169 | boot_wr64_le h HO_OFF_MAP_SIZE 500 |
| 170 | if ne handoff_check h HO_ERR_MAP_SIZE |
| 171 | ret false |
| 172 | end |
| 173 | ret true |
| 174 | end |
| 175 | |
| 176 | fn test_04_model_map to bool |
| 177 | m = new uchar 4096 0 |
| 178 | for i ulong 8 |
| 179 | put m i get mmap_magic i |
| 180 | end |
| 181 | boot_wr32_le m MMAP_OFF_VERSION MMAP_VERSION |
| 182 | boot_wr32_le m MMAP_OFF_SECTOR_SZ 4096 |
| 183 | boot_wr64_le m MMAP_OFF_MODEL_LEN 10000 |
| 184 | boot_wr32_le m MMAP_OFF_N_EXTENTS 2 |
| 185 | note Need ceil(10000/4096) = 3 sectors -> extent 0: lba=10, cnt=2; extent 1: lba=50, cnt=1 |
| 186 | boot_wr64_le m MMAP_OFF_EXTENTS 10 |
| 187 | boot_wr64_le m add MMAP_OFF_EXTENTS 8 2 |
| 188 | boot_wr64_le m add MMAP_OFF_EXTENTS 16 50 |
| 189 | boot_wr64_le m add MMAP_OFF_EXTENTS 24 1 |
| 190 | if ne model_map_check m 4096 100 MMAP_OK |
| 191 | ret false |
| 192 | end |
| 193 | note Disk block size mismatch refused |
| 194 | if ne model_map_check m 512 100 MMAP_ERR_BLK_MISMATCH |
| 195 | ret false |
| 196 | end |
| 197 | note Extent past last_block refused |
| 198 | if ne model_map_check m 4096 49 MMAP_ERR_EXT_PAST_DISK |
| 199 | ret false |
| 200 | end |
| 201 | note Wrong sector coverage refused |
| 202 | boot_wr64_le m add MMAP_OFF_EXTENTS 24 2 |
| 203 | if ne model_map_check m 4096 100 MMAP_ERR_COVERAGE |
| 204 | ret false |
| 205 | end |
| 206 | note Extent inside GPT header (lba < 2) refused |
| 207 | boot_wr64_le m add MMAP_OFF_EXTENTS 24 1 |
| 208 | boot_wr64_le m MMAP_OFF_EXTENTS 1 |
| 209 | if ne model_map_check m 4096 100 MMAP_ERR_EXT_BAD |
| 210 | ret false |
| 211 | end |
| 212 | ret true |
| 213 | end |
| 214 | |
| 215 | fn mk_valid_manifest dst edit uchar * gen ulong pgen ulong imglen ulong to void |
| 216 | slot_zero_bytes dst SLOT_UNIT |
| 217 | for i ulong 8 |
| 218 | put dst i get slot_m_magic i |
| 219 | end |
| 220 | boot_wr32_le dst SLOT_M_OFF_VER SLOT_M_VERSION |
| 221 | boot_wr32_le dst SLOT_M_OFF_PAYLOAD SLOT_M_PAYLOAD_BOOTAA64 |
| 222 | boot_wr32_le dst SLOT_M_OFF_LABI SLOT_M_LOADER_ABI |
| 223 | boot_wr32_le dst SLOT_M_OFF_KABI SLOT_M_KERNEL_ABI |
| 224 | boot_wr64_le dst SLOT_M_OFF_GEN gen |
| 225 | boot_wr64_le dst SLOT_M_OFF_PGEN pgen |
| 226 | boot_wr64_le dst SLOT_M_OFF_MINRB pgen |
| 227 | boot_wr64_le dst SLOT_M_OFF_IMGLEN imglen |
| 228 | for i ulong 64 |
| 229 | put dst add SLOT_M_OFF_IMGSHA i uchar add 0x10 and i 0x3f |
| 230 | put dst add SLOT_M_OFF_KSHA i uchar add 0x10 and i 0x3f |
| 231 | end |
| 232 | for i ulong 40 |
| 233 | put dst add SLOT_M_OFF_COMMIT i get b_commit i |
| 234 | end |
| 235 | for i ulong 15 |
| 236 | put dst add SLOT_M_OFF_PROV i get b_prov i |
| 237 | end |
| 238 | boot_wr64_le dst SLOT_M_OFF_TS 1700000000 |
| 239 | end |
| 240 | |
| 241 | fn test_05_slot_struct_checks to bool |
| 242 | if ne slot_cap_units 104 50 |
| 243 | ret false |
| 244 | end |
| 245 | if ne slot_manifest_unit 1 50 54 |
| 246 | ret false |
| 247 | end |
| 248 | m = new uchar 4096 0 |
| 249 | mk_valid_manifest m 5 3 4096 |
| 250 | if ne slot_manifest_check m SLOT_OK |
| 251 | ret false |
| 252 | end |
| 253 | note policy_generation > generation refused |
| 254 | boot_wr64_le m SLOT_M_OFF_PGEN 6 |
| 255 | if ne slot_manifest_check m SLOT_ERR_GEN |
| 256 | ret false |
| 257 | end |
| 258 | note kernel_sha512 != image_sha512 refused |
| 259 | mk_valid_manifest m 5 3 4096 |
| 260 | put m SLOT_M_OFF_KSHA 0xff |
| 261 | if ne slot_manifest_check m SLOT_ERR_SHA_MISMATCH |
| 262 | ret false |
| 263 | end |
| 264 | note Non-zero pad refused |
| 265 | mk_valid_manifest m 5 3 4096 |
| 266 | put m 4095 1 |
| 267 | if ne slot_manifest_check m SLOT_ERR_RSVD |
| 268 | ret false |
| 269 | end |
| 270 | note Control check positive and negative |
| 271 | c = new uchar 4096 0 |
| 272 | slot_control_init c 0 |
| 273 | if ne slot_control_check c SLOT_OK |
| 274 | ret false |
| 275 | end |
| 276 | put c SLOT_C_OFF_CAND 0 |
| 277 | if ne slot_control_check c SLOT_ERR_STATE |
| 278 | ret false |
| 279 | end |
| 280 | ret true |
| 281 | end |
| 282 | |
| 283 | fn test_06_slot_select_cand to bool |
| 284 | ctl = new uchar 4096 0 |
| 285 | ctl_out = new uchar 4096 0 |
| 286 | slot_control_init ctl 0 |
| 287 | if ne slot_stage_candidate ctl 1 2 SLOT_OK |
| 288 | ret false |
| 289 | end |
| 290 | ev0 = new SlotEval 1 1 1 0 |
| 291 | ev1 = new SlotEval 1 2 1 0 |
| 292 | dec = new SlotDecision -1 0 0 |
| 293 | note First try boots candidate slot 1 and decrements tries 3 -> 2 |
| 294 | slot_select true ctl ev0 ev1 dec ctl_out |
| 295 | if or ne get dec boot_slot 1 or ne get dec reason SLOT_R_CANDIDATE_TRY ne get dec loader_write 1 |
| 296 | ret false |
| 297 | end |
| 298 | if ne get ctl_out SLOT_C_OFF_TRIES 2 |
| 299 | ret false |
| 300 | end |
| 301 | note Exhausted candidate (tries=0) falls back to active slot 0 with no loader write |
| 302 | put ctl SLOT_C_OFF_TRIES 0 |
| 303 | slot_select true ctl ev0 ev1 dec ctl_out |
| 304 | if or ne get dec boot_slot 0 or ne get dec reason SLOT_R_CANDIDATE_EXHAUSTED ne get dec loader_write 0 |
| 305 | ret false |
| 306 | end |
| 307 | ret true |
| 308 | end |
| 309 | |
| 310 | fn test_07_slot_select_fallback to bool |
| 311 | ctl = new uchar 4096 0 |
| 312 | ctl_out = new uchar 4096 0 |
| 313 | slot_control_init ctl 0 |
| 314 | boot_wr64_le ctl SLOT_C_OFF_FLOOR 5 |
| 315 | ev0 = new SlotEval 1 4 4 0 |
| 316 | ev1 = new SlotEval 1 6 5 0 |
| 317 | dec = new SlotDecision -1 0 0 |
| 318 | note Active slot 0 is below floor 5 -> fallback to slot 1 |
| 319 | slot_select true ctl ev0 ev1 dec ctl_out |
| 320 | if or ne get dec boot_slot 1 ne get dec reason SLOT_R_ACTIVE_INVALID_FALLBACK |
| 321 | ret false |
| 322 | end |
| 323 | note Missing control record ALWAYS requires recovery |
| 324 | slot_select false ctl ev0 ev1 dec ctl_out |
| 325 | if or ne get dec boot_slot -1 ne get dec reason SLOT_R_RECOVERY_REQUIRED |
| 326 | ret false |
| 327 | end |
| 328 | note Both slots below floor -> recovery required |
| 329 | ev1_lo = new SlotEval 1 3 3 0 |
| 330 | slot_select true ctl ev0 ev1_lo dec ctl_out |
| 331 | if or ne get dec boot_slot -1 ne get dec reason SLOT_R_RECOVERY_REQUIRED |
| 332 | ret false |
| 333 | end |
| 334 | ret true |
| 335 | end |
| 336 | |
| 337 | fn test_08_slot_transitions to bool |
| 338 | ctl = new uchar 4096 0 |
| 339 | slot_control_init ctl 0 |
| 340 | note Stage candidate slot 1 at gen 10 |
| 341 | if ne slot_stage_candidate ctl 1 10 SLOT_OK |
| 342 | ret false |
| 343 | end |
| 344 | note Cannot stage active slot 0 |
| 345 | if ne slot_stage_candidate ctl 0 11 SLOT_ERR_STATE |
| 346 | ret false |
| 347 | end |
| 348 | note Promote slot 1 with policy_gen 8 -> active=1, floor=8, last_good=10 |
| 349 | if ne slot_promote ctl 1 10 8 SLOT_OK |
| 350 | ret false |
| 351 | end |
| 352 | if or ne get ctl SLOT_C_OFF_ACTIVE 1 ne get ctl SLOT_C_OFF_CAND SLOT_NONE |
| 353 | ret false |
| 354 | end |
| 355 | if or ne boot_rd64_le ctl SLOT_C_OFF_FLOOR 8 ne boot_rd64_le ctl SLOT_C_OFF_LASTGOOD 10 |
| 356 | ret false |
| 357 | end |
| 358 | note Cannot stage downgrade gen 9 <= last_good 10 |
| 359 | if ne slot_stage_candidate ctl 0 9 SLOT_ERR_FLOOR |
| 360 | ret false |
| 361 | end |
| 362 | note Stage slot 0 at gen 12, then abandon -> CANDIDATE_FAILED flag set |
| 363 | if ne slot_stage_candidate ctl 0 12 SLOT_OK |
| 364 | ret false |
| 365 | end |
| 366 | if ne slot_abandon_candidate ctl SLOT_OK |
| 367 | ret false |
| 368 | end |
| 369 | if or ne get ctl SLOT_C_OFF_CAND SLOT_NONE ne get ctl SLOT_C_OFF_FLAGS SLOT_C_FLAG_CAND_FAILED |
| 370 | ret false |
| 371 | end |
| 372 | ret true |
| 373 | end |
| 374 | |
| 375 | fn test_09_boot_rec_and_action to bool |
| 376 | ctl = new uchar 4096 0 |
| 377 | ctl_out = new uchar 4096 0 |
| 378 | man = new uchar 4096 0 |
| 379 | brec = new uchar 256 0 |
| 380 | slot_control_init ctl 0 |
| 381 | if ne slot_stage_candidate ctl 1 7 SLOT_OK |
| 382 | ret false |
| 383 | end |
| 384 | mk_valid_manifest man 7 5 4096 |
| 385 | for i ulong 8 |
| 386 | put brec i get slot_b_magic i |
| 387 | end |
| 388 | boot_wr32_le brec SLOT_B_OFF_VER SLOT_B_VERSION |
| 389 | put brec SLOT_B_OFF_SLOT 1 |
| 390 | put brec SLOT_B_OFF_REASON uchar SLOT_R_CANDIDATE_TRY |
| 391 | put brec SLOT_B_OFF_TRIES 2 |
| 392 | put brec SLOT_B_OFF_CTL_PRES 1 |
| 393 | boot_wr64_le brec SLOT_B_OFF_CTL_SEQ 1 |
| 394 | boot_wr64_le brec SLOT_B_OFF_GEN 7 |
| 395 | boot_wr64_le brec SLOT_B_OFF_PGEN 5 |
| 396 | for i ulong 64 |
| 397 | put brec add SLOT_B_OFF_IMGSHA i get man add SLOT_M_OFF_IMGSHA i |
| 398 | end |
| 399 | slot_boot_seal brec |
| 400 | if ne slot_boot_check brec SLOT_OK |
| 401 | ret false |
| 402 | end |
| 403 | note Unhealthy candidate try -> WAIT |
| 404 | if ne slot_kernel_action_inner brec ctl man false ctl_out SLOT_A_WAIT |
| 405 | ret false |
| 406 | end |
| 407 | note Healthy candidate try -> PROMOTE |
| 408 | if ne slot_kernel_action_inner brec ctl man true ctl_out SLOT_A_PROMOTE |
| 409 | ret false |
| 410 | end |
| 411 | if or ne get ctl_out SLOT_C_OFF_ACTIVE 1 ne boot_rd64_le ctl_out SLOT_C_OFF_FLOOR 5 |
| 412 | ret false |
| 413 | end |
| 414 | note Tampered boot record byte breaks SHA-256 -> REFUSE |
| 415 | put brec SLOT_B_OFF_TRIES 1 |
| 416 | if ne slot_boot_check brec SLOT_ERR_DIGEST |
| 417 | ret false |
| 418 | end |
| 419 | if ne slot_kernel_action_inner brec ctl man true ctl_out SLOT_A_REFUSE |
| 420 | ret false |
| 421 | end |
| 422 | ret true |
| 423 | end |
| 424 | |
| 425 | fn test_10_slot_sha512 to bool |
| 426 | img = new uchar 64 0 |
| 427 | for i ulong 64 |
| 428 | put img i uchar add 0x41 and i 0x1f |
| 429 | end |
| 430 | dig = new uchar 64 0 |
| 431 | dlen = sha2_digest 512 img dig |
| 432 | if ne dlen 64 |
| 433 | ret false |
| 434 | end |
| 435 | man = new uchar 4096 0 |
| 436 | mk_valid_manifest man 3 2 64 |
| 437 | for i ulong 64 |
| 438 | put man add SLOT_M_OFF_IMGSHA i get dig i |
| 439 | put man add SLOT_M_OFF_KSHA i get dig i |
| 440 | end |
| 441 | ev = new SlotEval 0 0 0 0 |
| 442 | if not slot_verify_image_sha512 man img 4096 ev |
| 443 | ret false |
| 444 | end |
| 445 | if or ne get ev valid 1 ne get ev generation 3 |
| 446 | ret false |
| 447 | end |
| 448 | note Corrupt one image byte -> verify fails |
| 449 | put img 10 xor get img 10 1 |
| 450 | if slot_verify_image_sha512 man img 4096 ev |
| 451 | ret false |
| 452 | end |
| 453 | if ne get ev err SLOT_ERR_SHA_MISMATCH |
| 454 | ret false |
| 455 | end |
| 456 | ret true |
| 457 | end |
| 458 | |
| 459 | fn nb_rt_offer_done nonce view uchar 16 mac view uchar 6 to bool |
| 460 | wire = new uchar 1056 0 |
| 461 | m2 = new NbMsg 0 0 0 0 0 0 0 |
| 462 | rn = new uchar 16 0 |
| 463 | extra = new uchar 1024 0 |
| 464 | m3 = new NbMsg NB_OFFER 0 0 0 0 8192 0 |
| 465 | n3 = nb_build m3 nonce mac wire |
| 466 | if ne n3 NB_MIN |
| 467 | ret false |
| 468 | end |
| 469 | if ne nb_parse part wire 0 n3 m2 rn extra NB_OK |
| 470 | ret false |
| 471 | end |
| 472 | if or ne get m2 mtype NB_OFFER ne get m2 total 8192 |
| 473 | ret false |
| 474 | end |
| 475 | m4 = new NbMsg NB_DONE 0 0 0 11 0 0 |
| 476 | n4 = nb_build m4 nonce b_nb_done wire |
| 477 | if ne n4 add NB_MIN 11 |
| 478 | ret false |
| 479 | end |
| 480 | if ne nb_parse part wire 0 n4 m2 rn extra NB_OK |
| 481 | ret false |
| 482 | end |
| 483 | if ne get m2 mtype NB_DONE |
| 484 | ret false |
| 485 | end |
| 486 | if ne get m2 mlen 11 |
| 487 | ret false |
| 488 | end |
| 489 | ret boot_eq_bytes part extra 0 11 b_nb_done |
| 490 | end |
| 491 | |
| 492 | fn test_11_netboot_roundtrip to bool |
| 493 | nonce = new uchar 16 0 |
| 494 | for i ulong 16 |
| 495 | put nonce i uchar add 0xa0 i |
| 496 | end |
| 497 | wire = new uchar 1056 0 |
| 498 | mac = new uchar 6 0 |
| 499 | put mac 0 0x02 |
| 500 | put mac 5 0x77 |
| 501 | m1 = new NbMsg NB_HELLO 0 0 0 0 0 0 |
| 502 | n1 = nb_build m1 nonce mac wire |
| 503 | if ne n1 NB_MIN |
| 504 | ret false |
| 505 | end |
| 506 | m2 = new NbMsg 0 0 0 0 0 0 0 |
| 507 | rn = new uchar 16 0 |
| 508 | extra = new uchar 1024 0 |
| 509 | if ne nb_parse part wire 0 n1 m2 rn extra NB_OK |
| 510 | ret false |
| 511 | end |
| 512 | if ne get m2 mtype NB_HELLO |
| 513 | ret false |
| 514 | end |
| 515 | if or ne get extra 0 0x02 ne get extra 5 0x77 |
| 516 | ret false |
| 517 | end |
| 518 | ret nb_rt_offer_done nonce mac |
| 519 | end |
| 520 | |
| 521 | fn test_12_netboot_negatives to bool |
| 522 | if ne nb_chunks 4097 5 |
| 523 | ret false |
| 524 | end |
| 525 | if ne nb_chunks 4096 4 |
| 526 | ret false |
| 527 | end |
| 528 | nonce = new uchar 16 1 |
| 529 | wire = new uchar 1056 0 |
| 530 | buf = new uchar 16 0x41 |
| 531 | note OFFER below NB_OBJECT_MIN refused |
| 532 | mbad = new NbMsg NB_OFFER 0 0 0 0 4096 0 |
| 533 | if ne nb_build mbad nonce buf wire 0 |
| 534 | ret false |
| 535 | end |
| 536 | note GET with unaligned offset refused |
| 537 | mget = new NbMsg NB_GET 0 0 4 0 0 512 |
| 538 | if ne nb_build mget nonce buf wire 0 |
| 539 | ret false |
| 540 | end |
| 541 | note DONE with non-printable byte refused |
| 542 | bad_txt = new uchar 4 0x41 |
| 543 | put bad_txt 2 0x01 |
| 544 | mdone = new NbMsg NB_DONE 0 0 0 4 0 0 |
| 545 | if ne nb_build mdone nonce bad_txt wire 0 |
| 546 | ret false |
| 547 | end |
| 548 | note Valid GET then corrupt reserved byte -> parse refused |
| 549 | mget_ok = new NbMsg NB_GET 0 0 4 0 0 1024 |
| 550 | n = nb_build mget_ok nonce buf wire |
| 551 | if ne n NB_MIN |
| 552 | ret false |
| 553 | end |
| 554 | put wire 30 1 |
| 555 | m2 = new NbMsg 0 0 0 0 0 0 0 |
| 556 | rn = new uchar 16 0 |
| 557 | extra = new uchar 1024 0 |
| 558 | if ne nb_parse part wire 0 n m2 rn extra NB_ERR |
| 559 | ret false |
| 560 | end |
| 561 | ret true |
| 562 | end |
| 563 | |
| 564 | fn main to int |
| 565 | failed = uint 0 |
| 566 | failed = add failed breport b_t01 test_01_handoff_magic |
| 567 | failed = add failed breport b_t02 test_02_handoff_model_fb |
| 568 | failed = add failed breport b_t03 test_03_handoff_mmap_rsvd |
| 569 | failed = add failed breport b_t04 test_04_model_map |
| 570 | failed = add failed breport b_t05 test_05_slot_struct_checks |
| 571 | failed = add failed breport b_t06 test_06_slot_select_cand |
| 572 | failed = add failed breport b_t07 test_07_slot_select_fallback |
| 573 | failed = add failed breport b_t08 test_08_slot_transitions |
| 574 | failed = add failed breport b_t09 test_09_boot_rec_and_action |
| 575 | failed = add failed breport b_t10 test_10_slot_sha512 |
| 576 | failed = add failed breport b_t11 test_11_netboot_roundtrip |
| 577 | failed = add failed breport b_t12 test_12_netboot_negatives |
| 578 | if eq failed 0 |
| 579 | w = bwrite_all 1 b_sum |
| 580 | if w |
| 581 | ret 0 |
| 582 | end |
| 583 | ret 1 |
| 584 | end |
| 585 | w = bwrite_all 1 b_fsum |
| 586 | if w |
| 587 | ret 1 |
| 588 | end |
| 589 | ret 1 |
| 590 | end |