def _get_auth_transaction(self): # Get auth request ID self.request_transaction_id = generate_auth_token() #REQUEST # Pack auth content auth_content = self.comm_service._pack_auth_content( self.client_peer_id, self.request_transaction_id) # Pack authentication data into stream auth_stream = self.comm_service.stream_manager.pack_stream( stream_type=constants.PROTO_AUTH_TYPE, stream_content=auth_content, stream_flag=STREAM_TYPES.UNAUTH, stream_host=self.peer_ip ) #ACKNOWLEDGE # Get ack content aack_content = self.comm_service._pack_auth_content( self.server_peer_id, self.request_transaction_id) # Send current peer info aack_stream = self.comm_service.stream_manager.pack_stream( stream_type=constants.PROTO_AACK_TYPE, stream_content=aack_content, stream_flag=STREAM_TYPES.UNAUTH, stream_host=self.peer_ip ) log_stream( constants.PROTO_AACK_TYPE, aack_content, self.comm_service.peerkey, len(aack_stream) ) #DISCONNECT dcon_content = self.comm_service._pack_auth_content( self.client_peer_id, self.request_transaction_id) dcon_stream = self.comm_service.stream_manager.pack_stream( stream_type=constants.PROTO_DCON_TYPE, stream_content=dcon_content, stream_flag=STREAM_TYPES.UNAUTH, stream_host=self.peer_ip ) return (auth_stream, aack_stream, dcon_stream)
def start_authentication(self, pid, host="localhost", port=constants.LOCAL_TEST_PORT): "Start connection with specified host server." Logger.debug("COMM: Initiating authenticated connection with pid: {}.".format(pid)) # Save authentication request to map with authentication ack self.valid_auth_req_tokens[host] = generate_auth_token() # Check if TLS is enabled if constants.ENABLE_TLS and reactor.connectSSL( host, port, CommCoreAuthFactory(self), TLSCtxFactory(self.sslcrt, self.sslkey, self.ssca, self.on_ssl_verification), ): return True # Use normal TCP connection elif not constants.ENABLE_TLS and reactor.connectTCP(host, port, CommCoreAuthFactory(self)): return True # Could not establish connection else: return False