From 32da9c4e8cb2b5252c13b363db7c28675cf60bb5 Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 23 Mar 2021 19:04:11 +0100 Subject: Fix up firmware and demos --- fw/hexnoise.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'fw/hexnoise.py') diff --git a/fw/hexnoise.py b/fw/hexnoise.py index c7acd65..2313f8f 100755 --- a/fw/hexnoise.py +++ b/fw/hexnoise.py @@ -16,6 +16,8 @@ from noise.exceptions import NoiseInvalidMessage import keymap from hexdump import hexdump +BINDING_INCANTATION_LENGTH = 4 + class PacketType(enum.Enum): _RESERVED = 0 INITIATE_HANDSHAKE = 1 @@ -122,7 +124,7 @@ class KeyMapper: class Magic: @classmethod def map_bytes_to_incantation(kls, data): - elems = [ f'{kls.ADJECTIVES[a]} {kls.NOUNS[b]}' for a, b in zip(data[0::2], data[1::2]) ] + elems = [ f'{kls.EVEN[a]} {kls.ODD[b]}' for a, b in zip(data[0::2], data[1::2]) ] nfirst = ", ".join(elems[:-1]) return f'{nfirst} and {elems[-1]}' @@ -232,6 +234,8 @@ class NoiseEngine: def perform_handshake(self): self.packetizer.send_packet(PacketType.INITIATE_HANDSHAKE, b'') self.debug_print('Handshake started') + import time + time.sleep(0.5) # FIXME while True: if self.proto.handshake_finished: @@ -262,7 +266,8 @@ class NoiseEngine: def channel_binding_incantation(self): hhash = self.proto.get_handshake_hash() - return '\n'.join(Magic.map_bytes_to_incantation(hhash[i:i+8]) for i in range(0, 16, 8)) + #return '\n'.join(Magic.map_bytes_to_incantation(hhash[i:i+8]) for i in range(0, 16, 8)) + return '\n'.join(Magic.map_bytes_to_incantation(hhash[i:min(BINDING_INCANTATION_LENGTH, i+8)]) for i in range(0, BINDING_INCANTATION_LENGTH, 8)) def receive_loop(self): while True: @@ -368,7 +373,8 @@ if __name__ == '__main__': ser = serial.Serial(args.serial, args.baudrate) packetizer = Packetizer(ser, debug=args.debug, width=args.width) - noise = NoiseEngine(packetizer, debug=args.debug) + temp_priv_key = NoiseEngine.generate_private_key_x25519() + noise = NoiseEngine(temp_priv_key, packetizer, debug=args.debug) noise.perform_handshake() print('Handshake channel binding incantation:') -- cgit