From 7e5b3ad0a1955dd1d249ffdb4f3945e9182e580e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Tue, 15 Jan 2013 11:20:42 +0100 Subject: [PATCH] New networkbot request: AUTH to authenticate bots --- networkbot.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/networkbot.py b/networkbot.py index 756ab3c..17a04bf 100644 --- a/networkbot.py +++ b/networkbot.py @@ -32,6 +32,7 @@ class NetworkBot: self.context = context self.srv = srv self.dest = dest + self.key = None self.dcc = dcc # DCC connection to the other bot if self.dcc is not None: @@ -220,6 +221,23 @@ class NetworkBot: self.my_tag = random.randint(0,255) self.send_ack(tag) + elif cmd == b'AUTH': # Authenticate bot + if len(args) == 3: # Request pairing + g = int.from_bytes(args[0].decode('hex'), byteorder='big') + p = int.from_bytes(args[1].decode('hex'), byteorder='big') + A = int.from_bytes(args[2].decode('hex'), byteorder='big') + + self.key = pow(A, b, p) + + b = random.getrandbits(1024) + B = pow(g, b, p) + + self.send_response_final(tag, pack("!x", pow(r, self.key, q))) + elif len(args) == 2: # Auth + r = int.from_bytes(args[0].decode('hex'), byteorder='big') + q = int.from_bytes(args[1].decode('hex'), byteorder='big') + self.send_response_final(tag, pack("!x", pow(r, self.key, q))) + elif cmd == b'FETCH': # Get known commands for name in ["cmd_hook", "ask_hook", "msg_hook"]: elts = self.context.create_cache(name)