Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(device=None):
if not device:
raise ValueError("device")
config = _TEST_CONFIG[device.device]
log.debug("test_config for %s : %s", device.device, hexlify(config))
# ATEC_UTIL.dump_configuration(config)
if not device.atcab_is_locked(ATCA_CONSTANTS.LOCK_ZONE_CONFIG):
device.atcab_write_config_zone(config)
device.atcab_lock_config_zone()
else:
log.debug("configuration zone locked")
if not device.atcab_is_locked(ATCA_CONSTANTS.LOCK_ZONE_DATA):
device.atcab_lock_data_zone()
else:
log.debug("data zone locked")
slot = 11
if not device.atcab_is_slot_locked(slot):
public_key = _TEST_KEYS["PUBLIC"]
# # write public_key to slot
device.atcab_write_pubkey(slot, public_key)
# # verify wrote public_key
assert public_key == device.atcab_read_pubkey(slot)
else:
log.debug("slot %d locked", slot)
log.debug("atcab_read_serial_number: %s", hexlify(packet.response_data))
packets = device.atcab_read_config_zone()
config = b''.join([bytes(packet.response_data[1:-2])
for packet in packets])
log.debug("atcab_read_config_zone %d: %s", len(config), hexlify(config))
# ATEC_UTIL.dump_configuration(config)
for slot in range(16):
slot_locked = device.atcab_is_slot_locked(slot)
log.debug("atcab_is_slot_locked %d: %s", slot, slot_locked)
locked_config = device.atcab_is_locked(ATCA_CONSTANTS.LOCK_ZONE_CONFIG)
log.debug("atcab_is_locked LOCK_ZONE_CONFIG: %r", locked_config)
locked_data = device.atcab_is_locked(ATCA_CONSTANTS.LOCK_ZONE_DATA)
log.debug("atcab_is_locked LOCK_ZONE_DATA: %r", locked_data)
try:
slot = 11
public_key = device.atcab_read_pubkey(slot)
log.debug("atcab_read_pubkey slot %d: %s", slot, hexlify(public_key))
except ATCA_EXCEPTIONS.ExecutionError:
pass
ATCA_CONSTANTS.LOCK_ZONE_DATA
):
raise ATCA_EXCEPTIONS.BadArgumentError()
# Read the word with the lock bytes
# (UserExtra, Selector, LockValue, LockConfig) (config block = 2, word offset = 5)
packet = self.atcab_read_zone(
ATCA_CONSTANTS.ATCA_ZONE_CONFIG,
slot=0,
block=2,
offset=5,
length=ATCA_CONSTANTS.ATCA_WORD_SIZE
)
if zone == ATCA_CONSTANTS.LOCK_ZONE_CONFIG:
return bool(packet[3+1] != 0x55)
elif zone == ATCA_CONSTANTS.LOCK_ZONE_DATA:
return bool(packet[2+1] != 0x55)
def atcab_lock_data_zone_crc(self, crc):
return self.atcab_lock(ATCA_CONSTANTS.LOCK_ZONE_DATA, crc)
def atcab_is_locked(self, zone):
if zone not in (
ATCA_CONSTANTS.LOCK_ZONE_CONFIG,
ATCA_CONSTANTS.LOCK_ZONE_DATA
):
raise ATCA_EXCEPTIONS.BadArgumentError()
# Read the word with the lock bytes
# (UserExtra, Selector, LockValue, LockConfig) (config block = 2, word offset = 5)
packet = self.atcab_read_zone(
ATCA_CONSTANTS.ATCA_ZONE_CONFIG,
slot=0,
block=2,
offset=5,
length=ATCA_CONSTANTS.ATCA_WORD_SIZE
)
if zone == ATCA_CONSTANTS.LOCK_ZONE_CONFIG:
return bool(packet[3+1] != 0x55)
elif zone == ATCA_CONSTANTS.LOCK_ZONE_DATA:
return bool(packet[2+1] != 0x55)