Add xap cli functions to test secure

This commit is contained in:
zvecr 2022-07-07 01:57:41 +01:00
parent 6ec0ff387b
commit ced7094ddd
4 changed files with 34 additions and 8 deletions

View File

@ -876,6 +876,7 @@ ifeq ($(strip $(XAP_ENABLE)), yes)
endif
OPT_DEFS += -DXAP_ENABLE
OPT_DEFS += -DBOOTLOADER_JUMP_SUPPORTED
DYNAMIC_KEYMAP_ENABLE := yes
SECURE_ENABLE := yes
EMBED_INFO_JSON := yes

View File

@ -70,12 +70,30 @@ class XAPShell(cmd.Cmd):
# TODO: request stuff?
print(self.device.info()['xap'])
def do_status(self, arg):
"""Prints out the current device state
"""
status = self.device.status()
print('Secure:%s' % status.get('lock', '???'))
def do_unlock(self, arg):
"""Initiate secure unlock
"""
self.device.unlock()
print('Unlock Requested...')
def do_lock(self, arg):
"""Disable secure routes
"""
self.device.lock()
def do_reset(self, arg):
"""Jump to bootloader if unlocked
"""
if not self.device.reset():
print("Reboot to bootloader failed")
return True
def do_listen(self, arg):
"""Log out XAP broadcast messages
"""
@ -89,9 +107,7 @@ class XAPShell(cmd.Cmd):
cli.log.info(' Secure[%s]', secure_status)
else:
data_str = ' '.join(['{:02X}'.format(b) for b in data])
cli.log.info(' Broadcast: type[%02x] data:[%s]', event, data_str)
cli.log.info(' Broadcast: type[%02x] data:[%s]', event, data.hex())
except KeyboardInterrupt:
cli.log.info('Stopping...')

View File

@ -148,9 +148,23 @@ class XAPDevice:
data['xap'] = self.version()['xap']
return data
def status(self):
lock = int.from_bytes(self.transaction(b'\x00\x03') or bytes(0), 'little')
data = {}
data['lock'] = XAPSecureStatus(lock).name
return data
def unlock(self):
self.transaction(b'\x00\x04')
def lock(self):
self.transaction(b'\x00\x05')
def reset(self):
status = int.from_bytes(self.transaction(b'\x01\x07') or bytes(0), 'little')
return status == 1
class XAPClient:
@staticmethod

View File

@ -83,11 +83,6 @@ bool xap_respond_secure_lock(xap_token_t token, const void *data, size_t length)
return xap_respond_data(token, NULL, 0);
}
// TODO: how to set this if "custom" is just an empty stub
#ifndef BOOTLOADER_JUMP_SUPPORTED
# define BOOTLOADER_JUMP_SUPPORTED
#endif
#ifdef BOOTLOADER_JUMP_SUPPORTED
bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked();