From 26a343971eb6f0e6e055441df353e60e81cf3595 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Sun, 10 Jul 2016 22:51:47 -0400 Subject: Sign/verifiy installable images Receive the image into sdram, verify the signature before copying to flash. It would be great if worked... --- projects/hsm/cryptech_upload | 51 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'projects/hsm/cryptech_upload') diff --git a/projects/hsm/cryptech_upload b/projects/hsm/cryptech_upload index 7590b38..9f401b8 100755 --- a/projects/hsm/cryptech_upload +++ b/projects/hsm/cryptech_upload @@ -79,16 +79,17 @@ def parse_args(): # positional argument(s) parser.add_argument('filename') + parser.add_argument('signature') return parser.parse_args() def _write(dst, data): dst.write(data) - #if len(data) == 4: - # print("Wrote 0x{!s}".format(data.encode('hex'))) - #else: - # print("Wrote {!r}".format(data)) + if len(data) == 4: + print("Wrote 0x{!s}".format(data.encode('hex'))) + else: + print("Wrote {!r}".format(data)) def _read(dst): @@ -99,7 +100,7 @@ def _read(dst): while x: res += x x = dst.read(1) - #print ("Read {!r}".format(res)) + print ("Read {!r}".format(res)) return res pin = None @@ -123,9 +124,16 @@ def _execute(dst, cmd): response = _read(dst) return response -def send_file(filename, args, dst): - s = os.stat(filename) - size = s.st_size +def send_file(filename, signature, args, dst): + def fsize(fn): + try: + s = os.stat(fn) + except OSError as e: + print e + exit(1) + return s.st_size + + size = fsize(filename) src = open(filename, 'rb') if args.fpga: chunk_size = FPGA_CHUNK_SIZE @@ -178,14 +186,29 @@ def send_file(filename, args, dst): crc = crc32(data, crc) & 0xffffffff - _read(dst) + src.close() - # 3. Write CRC-32 (4 bytes) - _write(dst, struct.pack('