1
0
Fork 0

New networkbot request: AUTH to authenticate bots

This commit is contained in:
Némunaire 2013-01-15 11:20:42 +01:00
parent dead687e9f
commit 7e5b3ad0a1
1 changed files with 18 additions and 0 deletions

View File

@ -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)