예제 #1
0
    def handle_queue_payload(self, payload):
        desc = payload['desc']
        command_list = constants.command_list

        if desc == command_list.New_Contact_Req:
            self.handle_new_contact_request(payload)
        elif desc == command_list.New_Contact_Req_Client_Err:
            self.handle_new_contact_request_client_error(payload)
        elif desc == command_list.New_Contact_Req_Client_Res:
            self.handle_new_contact_request_client_response(payload)
        elif desc == command_list.New_Contact_Res:
            self.handle_new_contact_response(payload)
        elif desc == command_list.New_Contact_Res_Client_Err:
            self.handle_new_contact_response_client_error(payload)
        elif desc == command_list.Send_New_Message:
            self.handle_send_new_message(payload)
        elif desc == command_list.Received_New_Message:
            self.handle_received_new_message(payload)
        elif desc == command_list.Send_New_Message_Client_Err:
            self.handle_send_new_message_client_error(payload)
        elif desc == command_list.Send_New_Message_Client_Res:
            self.handle_send_new_message_client_response(payload)
        elif desc == command_list.New_Contact_Res_Client_Res:
            self.handle_new_contact_response_client_response(payload)
        elif desc == command_list.Server_Error:
            self.handle_server_error(payload)
        elif desc == command_list.Inspect_Message:
            self.handle_inspect_message(payload)
        else:
            log.error("ROOT CONTROLLER QUEUE UNHANDLED PAYLOAD:", payload)
예제 #2
0
 def validate(self):
     if not isinstance(self.valid_kwarg_keys, set):
         raise ValueError
     elif self.valid_kwarg_keys != self.kwargs.keys():
         log.error(
             "Key Error:\nValid kwarg keys: {}.\nGiven kwarg keys: {}".
             format(self.valid_kwarg_keys, self.kwargs.keys()))
         raise KeyError
     self.update_attrs_with_kwargs()
예제 #3
0
 def validate(self):
     if not isinstance(self.valid_kwarg_keys, set):
         log.error("Valid kwarg keys must be a set.")
         raise ValueError
     if self.valid_kwarg_keys != self.kwargs.keys():
         log.error(
             "Key Error: Invalid keys in receiver object.\nValid kwarg keys: {}.\nGiven kwarg keys: {}"
             .format(self.valid_kwarg_keys, self.kwargs.keys()))
         raise KeyError
     self.update_attrs_with_kwargs()
예제 #4
0
 def handle_tor_proxy_error(self, payload):
     # We get this error, ex. if tor service is not running
     log.error("Tor Proxy Error: {}".format(payload))
     log.debug("Is your local TOR service running?")
     server_name = payload['name']
     error = payload['error']
     if server_name == constants.command_list.Tor_Proxy_Request_Server:
         self.view.set_tor_onion_request_addr(error)
     elif server_name == constants.command_list.Tor_Proxy_Response_Server:
         self.view.set_tor_onion_response_addr(error)
     elif server_name == constants.command_list.Tor_Proxy_Message_Server:
         self.view.set_tor_onion_message_addr(error)
    def execute(self, payload):
        if not self.is_nonce_valid(payload):
            # TODO: alert user with popup?
            msg = "Major error, client found nonce error, but did not return as error"
            log.error(msg)
            return False

        self.insert_sent_message_from_payload_argspace_payload_dict(payload)
        self.update_sent_messages_treeview()

        success_message = 'Message successfully received by peer.'
        self.message_controller.launch_user_alert(success_message)
예제 #6
0
 def handle_queue_payload(self, payload):
     desc = payload['desc']
     if desc == constants.command_list.Tor_Proxy_Request_Server:
         self.handle_tor_proxy_request_server(payload)
     elif desc == constants.command_list.Tor_Proxy_Response_Server:
         self.handle_tor_proxy_response_server(payload)
     elif desc == constants.command_list.Tor_Proxy_Message_Server:
         self.handle_tor_proxy_message_server(payload)
     elif desc == constants.command_list.Tor_Proxy_Error:
         self.handle_tor_proxy_error(payload)
     else:
         log.error(
             "TorNetController QUEUE UNHANDLED PAYLOAD: {}".format(payload))
예제 #7
0
 def execute(self, incoming_payload):
     payload_dict = incoming_payload['payload']
     validator = self.validate_message(payload_dict)
     if validator.valid:
         self.database_facade_insert_received_message(payload_dict)
         self.check_peer_contact_from_new_message(validator.data_dict,
                                                  validator.verify_result)
         self.message_controller_update_received_messages_treeview()
     else:
         # TODO: decide how to handle this case
         # We fall into this path when:
         #     - remote peer makes contact request
         #     - we accept
         #     - they send us a message and they are added to our peer contacts
         #     - then we delete their peer contact
         #     - and we delete their key from the key ring
         # - alert user
         log.error("Handle received new message payload is NOT valid.")
예제 #8
0
    def handle_valid_contact_response(self, validator_data_dict):
        gpg_pub_key = self.fetch_contact_response_pub_key_by_nonce(
            validator_data_dict)
        gpg_pub_key_validator = self.validate_pubkey(gpg_pub_key)
        if gpg_pub_key_validator.valid is False:
            # TODO: alert user?
            log.error(
                "Handle Valid Contact Response: SEVERE ERROR, pub key not valid"
            )
            return False

        peer_contact_payload = self.build_peer_contact_payload(
            gpg_pub_key, gpg_pub_key_validator, validator_data_dict)
        self.database_facade_insert_peer_contact(peer_contact_payload)
        self.import_gpg_pub_key_to_key_ring(gpg_pub_key)
        self.message_controller_update_contacts_treeview()
        self.database_facade_delete_pending_contact_response_by_gpg_fingerprint(
            gpg_pub_key_validator)
        self.requests_controller_update_sent_requests_treeview()
        self.launch_blink_alert("New Peer Contact")
예제 #9
0
    def build_contact_request_dict(self):
        tor_response_onion_addr = self.tor_datacontext.get_tor_response_proxy_addr(
        )
        if not tor_response_onion_addr.endswith('onion'):
            log.info("Tor address not yet set, cannot send request.")
            return False

        factory = contactrequestfactory.ContactRequestFactory(
            self.tor_datacontext.get_tor_response_proxy_addr(),
            self.gpg_homedir_observer.get(),
            self.root_params.get_session_passphrase_observable())
        build_result = factory.build()

        if hasattr(build_result, 'stderr'):
            msg = "Build contact request dict, GPG SIG ERROR: {}".format(
                build_result.stderr)
            log.error(msg)
            return False

        return build_result
예제 #10
0
    def build_new_message_payload_dict(self, gpg_pub_key, msg_text):
        tor_message_onion_addr = self.tor_datacontext_get_tor_message_proxy_addr(
        )
        if tor_message_onion_addr is False:
            msg = 'Cannot build message dict, tor address not set to onion address'
            log.error(msg)
            return False

        message_factory = messagefactory.MessageFactory(
            tor_message_onion_addr,
            self.gpg_datacontext.get_home_dir(), gpg_pub_key,
            self.gpg_datacontext.get_host_key_fingerprint(), msg_text,
            self.root_params.get_session_passphrase_observable())
        result = message_factory.build()

        if message_factory.valid:
            return result
        else:
            log.error("Message Factory Build returned error: {}".format(
                message_factory.error))
            return False
예제 #11
0
    def build_contact_response_dict(self, data_record):
        """
        Build payload for ContactResponseClient
        :param data_record:
        :return: build result payload dict or false on error
        """
        tor_response_onion_addr = self.tor_datacontext.get_tor_message_proxy_addr(
        )
        if not tor_response_onion_addr.endswith('onion'):
            log.info(
                "Cannot build contact response dict, tor address not set.")
            return False

        factory = contactresponsefactory.ContactResponseFactory(
            tor_response_onion_addr, self.gpg_homedir_observer.get(),
            data_record, self.root_params.get_session_passphrase_observable())
        build_result = factory.build()
        if factory.valid:
            return build_result
        else:
            log.error("Contact Response Factory Build Error: {}".format(
                factory.error))
            return False
예제 #12
0
 def handle_server_error(self, payload):
     # TODO: add tests and handling for Server Error
     log.error("RootController interface {} found server error: {}".format(
         payload['interface'], payload['error']))