3 # $ python dummy_map_server <bind-ip> <port>
11 map_notify = (b"\x40\x00\x00\x01"
14 + "\x00\x01\x00\x14" # key ID, Auth data length = 20
19 + "\x00\x00\x00\x00" # auth data
21 + "\x51\x80\x01\x18\x00\x00\x00\x00\x00\x01\x06\x00\x01\x00\x01\x01"
22 + "\x00\x00\x00\x04\x00\x01\x06\x00\x03\x01")
24 notify_nonce_offset = 4
25 notify_auth_data_len = 20
26 register_nonce_offset = 4
28 secret_key = 'password'
31 def build_notify(nonce):
32 rp = bytearray(map_notify)
35 rp[notify_nonce_offset + i] = nonce[i]
38 digest = hmac.new(secret_key, rp, hashlib.sha1).digest()
40 for i in range(0, notify_auth_data_len):
41 rp[auth_data_offset + i] = digest[i]
47 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
48 server_address = (host, int(port))
49 sock.bind(server_address)
52 data, address = sock.recvfrom(4096)
54 # extract nonce from message
55 nonce = data[register_nonce_offset:register_nonce_offset+8]
57 rp = build_notify(nonce)
58 sock.sendto(rp, address)
59 print 'Replied to ', ''.join(x.encode('hex') for x in nonce)
62 if __name__ == "__main__":
64 raise Exception('IP and port expected')
66 run(sys.argv[1], sys.argv[2])