Esempio n. 1
0
 def stage_two(self, stage_two_msg_edge):
     """
     Gets the public_key_edge_dh and saves it.
     Creates a DH key set for main and sends the public_key_main_dh.
     Calculates the shared key and returns it.
     :param stage_two_msg_edge (Bytes): public_key_edge_dh
     :return stage_two_msg_main (Bytes): public_key_main_dh
     :return shared_key: the final shared key
     """
     self.public_key_edge_dh = int(stage_two_msg_edge.decode())
     self.private_key_main_dh, self.public_key_main_dh = DH.gen_key_set()
     self.shared_key = DH.gen_shared_key(self.private_key_main_dh,
                                         self.public_key_edge_dh)
     stage_two_msg_main = str(self.public_key_main_dh).encode()
     return stage_two_msg_main, self.shared_key
Esempio n. 2
0
 def stage_two(self, stage_two_msg_main, dh_signature):
     """
     Gets the public_key_rsa_main as the stage_two_msg_main.
     The dh_signature
     Sends the public_key_edge_dh
     :param stage_two_msg_main (bytes): data from main
     :param dh_signature (bytes): dh_signature from main
     :return stage_two_msg_edge(Bytes)/ False: False if the signature failed. public_key_edge_dh if the signature is good.
     """
     to_verify_sig = (zRSA.public_key_to_bytes(stage_two_msg_main) + zRSA.public_key_to_bytes(self.public_rsa_edge))
     if zRSA.verify_signature(to_verify_sig, self.PUBLIC_KEY_MASTER_GLOBAL, dh_signature, 1.2) is False:
         return False
     self.public_rsa_main = stage_two_msg_main
     self.private_key_edge_dh, self.public_key_edge_dh = DH.gen_key_set()
     stage_two_msg_edge = str(self.public_key_edge_dh).encode()
     return stage_two_msg_edge