Esempio n. 1
0
    def __init__(self, **kwargs: Any) -> None:
        """Create new GatewaySettings mock object."""
        self.serial_baudrate = 19200
        self.serial_error_correction = 5
        self.use_serial_usb_adapter = True
        self.built_in_serial_interface = 'ttyS0'

        self.software_operation = TX
        self.local_testing_mode = False
        self.data_diode_sockets = False

        self.all_keys = list(vars(self).keys())
        self.key_list = self.all_keys[:self.all_keys.index('software_operation'
                                                           )]
        self.defaults = {k: self.__dict__[k] for k in self.key_list}

        self.session_serial_error_correction = self.serial_error_correction
        self.session_serial_baudrate = self.serial_baudrate
        self.session_usb_serial_adapter = self.use_serial_usb_adapter

        self.tx_inter_packet_delay = 0.0
        self.rx_receive_timeout = 0.0

        self.race_condition_delay = calculate_race_condition_delay(
            self.session_serial_error_correction, self.serial_baudrate)

        # Override defaults with specified kwargs
        for key, value in kwargs.items():
            setattr(self, key, value)
Esempio n. 2
0
    def __init__(self,
                 local_testing: bool,
                 dd_sockets: bool,
                 operation=NH) -> None:
        # Fixed settings
        self.relay_to_im_client = True  # False stops forwarding messages to IM client

        # Controllable settings
        self.serial_usb_adapter = True  # False uses system's integrated serial interface
        self.disable_gui_dialog = False  # True replaces Tkinter dialogs with CLI prompts
        self.serial_baudrate = 19200  # The speed of serial interface in bauds per second
        self.serial_error_correction = 5  # Number of byte errors serial datagrams can recover from

        self.software_operation = operation
        self.file_name = '{}{}_settings'.format(DIR_USER_DATA, operation)

        # Settings from launcher / CLI arguments
        self.local_testing_mode = local_testing
        self.data_diode_sockets = dd_sockets

        ensure_dir(DIR_USER_DATA)
        if os.path.isfile(self.file_name):
            self.load_settings()
        else:
            self.setup()
            self.store_settings()

        # Following settings change only when program is restarted
        self.session_serial_error_correction = self.serial_error_correction
        self.session_serial_baudrate = self.serial_baudrate
        self.race_condition_delay = calculate_race_condition_delay(self)

        self.receive_timeout, self.transmit_delay = calculate_serial_delays(
            self.session_serial_baudrate)
Esempio n. 3
0
    def __init__(self,
                 operation:  str,
                 local_test: bool,
                 dd_sockets: bool,
                 qubes:      bool
                 ) -> None:
        """Create a new Settings object.

        The settings below are altered from within the program itself.
        Changes made to the default settings are stored in the JSON
        file under $HOME/tfc/user_data from where, if needed, they can
        be manually altered by the user.
        """
        self.serial_baudrate           = 19200
        self.serial_error_correction   = 5
        self.use_serial_usb_adapter    = True
        self.built_in_serial_interface = 'ttyS0'

        self.software_operation = operation
        self.local_testing_mode = local_test
        self.data_diode_sockets = dd_sockets

        self.qubes    = qubes
        self.all_keys = list(vars(self).keys())
        self.key_list = self.all_keys[:self.all_keys.index('software_operation')]
        self.defaults = {k: self.__dict__[k] for k in self.key_list}

        self.file_name = f'{DIR_USER_DATA}{self.software_operation}_serial_settings.json'

        ensure_dir(DIR_USER_DATA)
        if os.path.isfile(self.file_name):
            self.load_settings()
        else:
            self.setup()
            self.store_settings()

        self.session_serial_baudrate         = self.serial_baudrate
        self.session_serial_error_correction = self.serial_error_correction
        self.session_usb_serial_adapter      = self.use_serial_usb_adapter

        self.tx_inter_packet_delay, self.rx_receive_timeout = self.calculate_serial_delays(self.session_serial_baudrate)

        self.race_condition_delay = calculate_race_condition_delay(self.session_serial_error_correction,
                                                                   self.serial_baudrate)
Esempio n. 4
0
 def test_race_condition_delay_calculation(self):
     self.assertIsInstance(calculate_race_condition_delay(5, 9600), float)
Esempio n. 5
0
    def __init__(self, master_key: 'MasterKey', operation: str,
                 local_test: bool, dd_sockets: bool) -> None:
        """Create a new Settings object.

        The settings below are altered from within the program itself.
        Changes made to the default settings are stored in encrypted
        settings database.

        :param master_key: MasterKey object
        :param operation:  Operation mode of the program (tx or rx)
        :param local_test: Setting value passed from command-line argument
        :param dd_sockets: Setting value passed from command-line argument
        """
        # Common settings
        self.disable_gui_dialog = False
        self.max_number_of_group_members = 20
        self.max_number_of_groups = 20
        self.max_number_of_contacts = 20
        self.serial_baudrate = 19200
        self.serial_error_correction = 5
        self.log_messages_by_default = False
        self.accept_files_by_default = False
        self.show_notifications_by_default = True
        self.logfile_masking = False

        # Transmitter settings
        self.txm_usb_serial_adapter = True
        self.nh_bypass_messages = True
        self.confirm_sent_files = True
        self.double_space_exits = False
        self.traffic_masking = False
        self.traffic_masking_static_delay = 2.0
        self.traffic_masking_random_delay = 2.0
        self.multi_packet_random_delay = False
        self.max_duration_of_random_delay = 10.0

        # Receiver settings
        self.rxm_usb_serial_adapter = True
        self.new_message_notify_preview = False
        self.new_message_notify_duration = 1.0

        self.master_key = master_key
        self.software_operation = operation
        self.local_testing_mode = local_test
        self.data_diode_sockets = dd_sockets

        self.file_name = f'{DIR_USER_DATA}{operation}_settings'

        self.key_list = list(vars(self).keys())
        self.key_list = self.key_list[:self.key_list.index('master_key')]
        self.defaults = {k: self.__dict__[k] for k in self.key_list}

        ensure_dir(DIR_USER_DATA)
        if os.path.isfile(self.file_name):
            self.load_settings()
            if operation == RX:
                # TxM is unable to send serial interface type changing command if
                # RxM looks for the type of adapter user doesn't have available.
                # Therefore setup() is run every time the Receiver program starts.
                self.setup()
        else:
            self.setup()
        self.store_settings()

        # Following settings change only when program is restarted
        self.session_serial_error_correction = self.serial_error_correction
        self.session_serial_baudrate = self.serial_baudrate
        self.session_traffic_masking = self.traffic_masking
        self.session_usb_serial_adapter = self.rxm_usb_serial_adapter if operation == RX else self.txm_usb_serial_adapter
        self.race_condition_delay = calculate_race_condition_delay(self,
                                                                   txm=True)

        self.rxm_receive_timeout, self.txm_inter_packet_delay = calculate_serial_delays(
            self.session_serial_baudrate)