Skip to content

Commit 72c3be7

Browse files
author
Adam Vrba
committed
Merge branch 'debug_model_l3_responses' into 'master'
invalid slot model l3 responses See merge request internal/development-environment/ts-tvl!17
2 parents b4a2ac4 + 19b8f1c commit 72c3be7

10 files changed

+31
-20
lines changed

tests/test_model/test_l3_api/test_ecc_key_erase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ def test_invalid_slot(host: Host, model: Tropic01Model, slot: int):
4444
assert model.r_ecc_keys.slots[slot] is None
4545
result = host.send_command(TsL3EccKeyEraseCommand(slot=slot))
4646

47-
assert result.result.value == L3ResultFieldEnum.FAIL
47+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED
4848
assert model.r_ecc_keys.slots[slot] is None

tests/test_model/test_l3_api/test_ecc_key_generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ def test_invalid_slot(host: Host, model: Tropic01Model, slot: int):
7070
)
7171
result = host.send_command(command)
7272

73-
assert result.result.value == L3ResultFieldEnum.FAIL
73+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED
7474
assert model.r_ecc_keys.slots[slot] is None

tests/test_model/test_l3_api/test_ecc_key_read.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ def test_invalid_slot(host: Host, model: Tropic01Model, slot: int):
5454
)
5555
result = host.send_command(command)
5656

57-
assert result.result.value == L3ResultFieldEnum.FAIL
57+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED
5858
assert model.r_ecc_keys.slots[slot] is None

tests/test_model/test_l3_api/test_ecc_key_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ def test_invalid_slot(host: Host, model: Tropic01Model, slot: int):
124124
command = randomize(TsL3EccKeyStoreCommand, slot=slot)
125125
result = host.send_command(command)
126126

127-
assert result.result.value == L3ResultFieldEnum.FAIL
127+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED
128128
assert model.r_ecc_keys.slots[slot] is None

tests/test_model/test_l3_api/test_ecdsa_sign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def test_invalid_slot(host: Host, slot: int):
5858
command = randomize(TsL3EcdsaSignCommand, slot=slot)
5959
result = host.send_command(command)
6060

61-
assert result.result.value == L3ResultFieldEnum.FAIL
61+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED

tests/test_model/test_l3_api/test_eddsa_sign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def test_invalid_slot(host: Host, slot: int):
4444
command = randomize(TsL3EddsaSignCommand, slot=slot)
4545
result = host.send_command(command)
4646

47-
assert result.result.value == L3ResultFieldEnum.FAIL
47+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED

tests/test_model/test_l3_api/test_r_mem_data_erase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def test_invalid_udata_slot(host: Host, udata_slot: int):
5757
)
5858
result = host.send_command(command)
5959

60-
assert result.result.value == L3ResultFieldEnum.FAIL
60+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED

tests/test_model/test_l3_api/test_r_mem_data_read.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def test_invalid_udata_slot(host: Host, udata_slot: int):
5858
)
5959
result = host.send_command(command)
6060

61-
assert result.result.value == L3ResultFieldEnum.FAIL
61+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED

tests/test_model/test_l3_api/test_r_mem_data_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ def test_invalid_udata_slot(host: Host, udata_slot: int):
100100
)
101101
result = host.send_command(command)
102102

103-
assert result.result.value == L3ResultFieldEnum.FAIL
103+
assert result.result.value == L3ResultFieldEnum.UNAUTHORIZED

tvl/targets/model/tropic01_l3_api_impl.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _check_pairing_key_slot_access_privileges(
102102
if address == int(name.rsplit("_", maxsplit=1)[-1]):
103103
self.check_access_privileges(name, value)
104104
return
105-
raise RuntimeError(f"Slot index {address=:#06x} out of range.")
105+
raise L3ProcessingErrorUnauthorized(f"Slot index {address=:#06x} out of range.")
106106

107107
def ts_l3_pairing_key_write(
108108
self, command: TsL3PairingKeyWriteCommand
@@ -352,6 +352,7 @@ def ts_l3_r_mem_data_write(
352352
("write_udata_slot_256_383", config.write_udata_slot_256_383),
353353
("write_udata_slot_384_511", config.write_udata_slot_384_511),
354354
],
355+
raise_on_failure=L3ProcessingErrorUnauthorized,
355356
)
356357

357358
self.logger.debug("User data slot address: %#06x.", address)
@@ -380,6 +381,7 @@ def ts_l3_r_mem_data_read(
380381
("read_udata_slot_256_383", config.read_udata_slot_256_383),
381382
("read_udata_slot_384_511", config.read_udata_slot_384_511),
382383
],
384+
raise_on_failure=L3ProcessingErrorUnauthorized,
383385
)
384386

385387
self.logger.debug("User data slot address: %#06x.", address)
@@ -400,6 +402,7 @@ def ts_l3_r_mem_data_erase(
400402
("erase_udata_slot_256_383", config.erase_udata_slot_256_383),
401403
("erase_udata_slot_384_511", config.erase_udata_slot_384_511),
402404
],
405+
raise_on_failure=L3ProcessingErrorUnauthorized,
403406
)
404407

405408
self.logger.debug("User data slot address: %#06x.", address)
@@ -513,11 +516,6 @@ def ts_l3_mcounter_get(
513516
def ts_l3_ecc_key_generate(
514517
self, command: TsL3EccKeyGenerateCommand
515518
) -> TsL3EccKeyGenerateResult:
516-
try:
517-
curve = TsL3EccKeyGenerateCommand.CurveEnum(command.curve.value)
518-
except ValueError as exc:
519-
raise L3ProcessingErrorFail(exc) from None
520-
521519
config = self.config.cfg_uap_ecc_key_generate
522520
self._check_ranged_access_privileges(
523521
(slot := command.slot.value),
@@ -527,9 +525,15 @@ def ts_l3_ecc_key_generate(
527525
("gen_ecckey_slot_16_23", config.gen_ecckey_slot_16_23),
528526
("gen_ecckey_slot_24_31", config.gen_ecckey_slot_24_31),
529527
],
528+
raise_on_failure=L3ProcessingErrorUnauthorized,
530529
)
531530

532531
self.logger.debug("ECC key slot: %d.", slot)
532+
try:
533+
curve = TsL3EccKeyGenerateCommand.CurveEnum(command.curve.value)
534+
except ValueError as exc:
535+
raise L3ProcessingErrorFail(exc) from None
536+
533537
try:
534538
self.r_ecc_keys.generate(slot, curve, self.trng2)
535539
except ECCKeyExistsInSlotError as exc:
@@ -541,11 +545,6 @@ def ts_l3_ecc_key_generate(
541545
def ts_l3_ecc_key_store(
542546
self, command: TsL3EccKeyStoreCommand
543547
) -> TsL3EccKeyStoreResult:
544-
try:
545-
curve = TsL3EccKeyStoreCommand.CurveEnum(command.curve.value)
546-
except ValueError as exc:
547-
raise L3ProcessingErrorFail(exc) from None
548-
549548
config = self.config.cfg_uap_ecc_key_store
550549
self._check_ranged_access_privileges(
551550
(slot := command.slot.value),
@@ -555,9 +554,16 @@ def ts_l3_ecc_key_store(
555554
("store_ecckey_slot_16_23", config.store_ecckey_slot_16_23),
556555
("store_ecckey_slot_24_31", config.store_ecckey_slot_24_31),
557556
],
557+
raise_on_failure=L3ProcessingErrorUnauthorized,
558558
)
559559

560560
self.logger.debug("ECC key slot: %d.", slot)
561+
try:
562+
curve = TsL3EccKeyStoreCommand.CurveEnum(command.curve.value)
563+
except ValueError as exc:
564+
raise L3ProcessingErrorFail(exc) from None
565+
566+
561567
try:
562568
self.r_ecc_keys.store(slot, curve, command.k.to_bytes())
563569
except (ECCKeyExistsInSlotError, ECCKeySetupError) as exc:
@@ -578,6 +584,7 @@ def ts_l3_ecc_key_read(
578584
("read_ecckey_slot_16_23", config.read_ecckey_slot_16_23),
579585
("read_ecckey_slot_24_31", config.read_ecckey_slot_24_31),
580586
],
587+
raise_on_failure=L3ProcessingErrorUnauthorized,
581588
)
582589

583590
self.logger.debug("ECC key slot: %d.", slot)
@@ -614,6 +621,7 @@ def ts_l3_ecc_key_erase(
614621
("erase_ecckey_slot_16_23", config.erase_ecckey_slot_16_23),
615622
("erase_ecckey_slot_24_31", config.erase_ecckey_slot_24_31),
616623
],
624+
raise_on_failure=L3ProcessingErrorUnauthorized,
617625
)
618626

619627
self.logger.debug("ECC key slot: %d.", slot)
@@ -632,6 +640,7 @@ def ts_l3_ecdsa_sign(self, command: TsL3EcdsaSignCommand) -> TsL3EcdsaSignResult
632640
("ecdsa_ecckey_slot_16_23", config.ecdsa_ecckey_slot_16_23),
633641
("ecdsa_ecckey_slot_24_31", config.ecdsa_ecckey_slot_24_31),
634642
],
643+
raise_on_failure=L3ProcessingErrorUnauthorized,
635644
)
636645

637646
msg_hash = command.msg_hash.to_bytes()
@@ -671,6 +680,7 @@ def ts_l3_eddsa_sign(self, command: TsL3EddsaSignCommand) -> TsL3EddsaSignResult
671680
("eddsa_ecckey_slot_16_23", config.eddsa_ecckey_slot_16_23),
672681
("eddsa_ecckey_slot_24_31", config.eddsa_ecckey_slot_24_31),
673682
],
683+
raise_on_failure=L3ProcessingErrorUnauthorized,
674684
)
675685

676686
msg_bytes = command.msg.to_bytes()
@@ -710,6 +720,7 @@ def ts_l3_mac_and_destroy(
710720
("macandd_64_95", config.macandd_64_95),
711721
("macandd_96_127", config.macandd_96_127),
712722
],
723+
raise_on_failure=L3ProcessingErrorUnauthorized,
713724
)
714725
self.logger.info("Executing Mac-and-Destroy sequence.")
715726
slot_bytes = bytes([command.slot.value])

0 commit comments

Comments
 (0)