def stage4(self): s4_success = False while not s4_success: s4_buffer = network.recv_bcast(config.UDP_PAIRING_PORT)[0] try: target_server_guid = s4_buffer.split("$")[0] if target_server_guid == self.passwddb.get_server_guid(): decrypted_payload = safe.decrypt_aes(s4_buffer.split("$")[1], self.user_info.aes_key) if decrypted_payload == "OK": msg = self.candidate_smartphone_guid + "$" + safe.encrypt_aes("OK", self.user_info.aes_key) network.send_bcast(config.UDP_PAIRING_PORT, msg) self.user_info.smartphone_guid = self.candidate_smartphone_guid self.passwddb.save_user_info(self.user_info) except IndexError: print "Received message in unknown format"
def stage2(self): s2_success = False while not s2_success: s2_buffer = network.recv_bcast(config.UDP_PAIRING_PORT)[0] # decode and see if it matches print "Buffer Received: " + toHex(s2_buffer) try: smartphone_guid = s2_buffer.split("#")[0] print "Declared GUID: " + smartphone_guid try: decrypted_part = safe.decrypt_aes(s2_buffer.split("#")[1], self.user_info.aes_key) assert decrypted_part except: print "Could not decrypt payload" print "Decrypted into: " + decrypted_part if decrypted_part == smartphone_guid: self.candidate_smartphone_guid = smartphone_guid s2_success = True except IndexError: # No hash in the string... print "Invalid buffer format received."