def run(self): try: client_number = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(client_number, intended_length=1): beta = self.create_private_key() own_number = mod_pow(self.g, beta, self.p) self.K = mod_pow(client_number, beta, self.p) cipher = Cipher(self.K) self.output_queue.put( (own_number, self.prepare_encrypted_message(first_number=client_number, second_number=own_number, cipher=cipher)), timeout=self.timeout) client_message = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(client_message, intended_length=1): if self.is_encrypted_message_valid( client_number=client_number, server_number=own_number, encrypted_message=client_message, cipher=cipher, partner_id=self.client_id): self.finished_successfully = True return except: pass self.finished_successfully = False
def run(self): try: alpha = self.create_private_key() own_number = mod_pow(self.g, alpha, self.p) self.output_queue.put(own_number, timeout=self.timeout) message_from_server = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(message_from_server, intended_length=2): server_number, encrypted_message = message_from_server self.K = mod_pow(server_number, alpha, self.p) cipher = Cipher(self.K) if self.is_encrypted_message_valid( client_number=own_number, server_number=server_number, encrypted_message=encrypted_message, cipher=cipher, partner_id=self.server_id): self.output_queue.put(self.prepare_encrypted_message( own_number, server_number, cipher), timeout=self.timeout) self.finished_successfully = True return except: pass self.finished_successfully = False
def run(self): try: client_number = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(client_number, intended_length=1): beta = self.create_private_key() own_number = mod_pow(self.g, beta, self.p) self.K = mod_pow(client_number, beta, self.p) cipher = Cipher(self.K) self.output_queue.put((own_number, self.prepare_encrypted_message(first_number=client_number, second_number=own_number, cipher=cipher)), timeout=self.timeout) client_message = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(client_message, intended_length=1): if self.is_encrypted_message_valid(client_number=client_number, server_number=own_number, encrypted_message=client_message, cipher=cipher, partner_id=self.client_id): self.finished_successfully = True return except: pass self.finished_successfully = False
def run(self): try: alpha = self.create_private_key() own_number = mod_pow(self.g, alpha, self.p) self.output_queue.put(own_number, timeout=self.timeout) message_from_server = self.input_queue.get(timeout=self.timeout) if self.is_message_valid(message_from_server, intended_length=2): server_number, encrypted_message = message_from_server self.K = mod_pow(server_number, alpha, self.p) cipher = Cipher(self.K) if self.is_encrypted_message_valid(client_number=own_number, server_number=server_number, encrypted_message=encrypted_message, cipher=cipher, partner_id=self.server_id): self.output_queue.put(self.prepare_encrypted_message(own_number, server_number, cipher), timeout=self.timeout) self.finished_successfully = True return except: pass self.finished_successfully = False
def is_signature_valid(signed_message, expected_content, public_key, n): try: actual_content = mod_pow(int(signed_message), public_key, n) return actual_content == expected_content except: return False