add rng command

This commit is contained in:
Conor Patrick 2018-12-05 19:35:22 -05:00
parent beedc24839
commit 1a07b4a73a
3 changed files with 30 additions and 2 deletions

View File

@ -716,7 +716,23 @@ uint8_t ctaphid_handle_packet(uint8_t * pkt_raw)
boot_st_bootloader();
break;
#endif
#if !defined(IS_BOOTLOADER)
case CTAPHID_GETRNG:
printf1(TAG_HID,"CTAPHID_GETRNG\n");
ctap_response_init(&ctap_resp);
ctaphid_write_buffer_init(&wb);
wb.cid = cid;
wb.cmd = CTAPHID_GETRNG;
wb.bcnt = ctap_buffer[0];
if (!wb.bcnt)
wb.bcnt = 57;
memset(ctap_buffer,0,wb.bcnt);
ctap_generate_rng(ctap_buffer, wb.bcnt);
ctaphid_write(&wb, &ctap_buffer, wb.bcnt);
ctaphid_write(&wb, NULL, 0);
is_busy = 0;
break;
#endif
default:
printf2(TAG_ERR,"error, unimplemented HID cmd: %02x\r\n", buffer_cmd());
ctaphid_send_error(cid, CTAP1_ERR_INVALID_COMMAND);

View File

@ -42,6 +42,7 @@
#define CTAPHID_BOOT (TYPE_INIT | 0x50)
#define CTAPHID_ENTERBOOT (TYPE_INIT | 0x51)
#define CTAPHID_ENTERSTBOOT (TYPE_INIT | 0x52)
#define CTAPHID_GETRNG (TYPE_INIT | 0x60)
#define ERR_INVALID_CMD 0x01
#define ERR_INVALID_PAR 0x02

View File

@ -29,6 +29,7 @@ class SoloBootloader:
HIDCommandBoot = 0x50
HIDCommandEnterBoot = 0x51
HIDCommandEnterSTBoot = 0x52
HIDCommandRNG = 0x60
TAG = b'\x8C\x27\x90\xf6'
@ -118,6 +119,9 @@ class Programmer():
def write_flash(self,addr,data):
self.exchange(SoloBootloader.write,addr,data)
def get_rng(self,num=0):
ret = self.send_data_hid(SoloBootloader.HIDCommandRNG,struct.pack('B', num))
return ret
def verify_flash(self,sig):
"""
@ -266,6 +270,7 @@ if __name__ == '__main__':
parser.add_argument("--enter-bootloader", action="store_true", help = 'Don\'t write anything, try to enter bootloader. Typically only supported by Solo Hacker builds.')
parser.add_argument("--st-dfu", action="store_true", help = 'Don\'t write anything, try to enter ST DFU. Warning, you could brick your Solo if you overwrite everything. You should reprogram the option bytes just to be safe (boot to Solo bootloader first, then run this command).')
parser.add_argument("--disable", action="store_true", help = 'Disable the Solo bootloader. Cannot be undone. No future updates can be applied.')
parser.add_argument("--rng", action="store_true", help = 'Continuously dump random numbers generated from Solo.')
args = parser.parse_args()
print()
@ -286,6 +291,12 @@ if __name__ == '__main__':
p.reboot()
sys.exit(0)
if args.rng:
while True:
r = p.get_rng(255)
sys.stdout.buffer.write(r)
sys.exit(0)
if args.st_dfu:
print('Sending command to boot into ST DFU...')
p.enter_st_dfu()
@ -296,7 +307,7 @@ if __name__ == '__main__':
sys.exit(0)
try:
print('version is ', p.version())
p.version()
except CtapError as e:
if e.code == CtapError.ERR.INVALID_COMMAND:
attempt_to_boot_bootloader(p)