Added option to block non-trusted callers

This commit is contained in:
Mark Qvist 2025-03-14 15:05:51 +01:00
parent 4d9bba3e4c
commit dd12a76bf9
3 changed files with 77 additions and 11 deletions

View file

@ -853,6 +853,8 @@ class SidebandCore():
self.config["voice_input"] = None self.config["voice_input"] = None
if not "voice_ringer" in self.config: if not "voice_ringer" in self.config:
self.config["voice_ringer"] = None self.config["voice_ringer"] = None
if not "voice_trusted_only" in self.config:
self.config["voice_trusted_only"] = False
# Make sure we have a database # Make sure we have a database
if not os.path.isfile(self.db_path): if not os.path.isfile(self.db_path):
@ -1074,6 +1076,20 @@ class SidebandCore():
RNS.log("Error while checking trust for "+RNS.prettyhexrep(context_dest)+": "+str(e), RNS.LOG_ERROR) RNS.log("Error while checking trust for "+RNS.prettyhexrep(context_dest)+": "+str(e), RNS.LOG_ERROR)
return False return False
def voice_is_trusted(self, identity_hash):
context_dest = identity_hash
try:
lxmf_destination_hash = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", identity_hash)
existing_voice = self._db_conversation(context_dest)
existing_lxmf = self._db_conversation(lxmf_destination_hash)
if existing_lxmf: trust = existing_lxmf["trust"]
else: trust = existing_voice["trust"]
return trust == 1
except Exception as e:
RNS.log("Could not decode a valid peer name from data: "+str(e), RNS.LOG_DEBUG)
return False
def is_object(self, context_dest, conv_data = None): def is_object(self, context_dest, conv_data = None):
try: try:
if conv_data == None: if conv_data == None:

View file

@ -51,6 +51,7 @@ class ReticulumTelephone():
self.telephone.set_speaker(self.speaker_device) self.telephone.set_speaker(self.speaker_device)
self.telephone.set_microphone(self.microphone_device) self.telephone.set_microphone(self.microphone_device)
self.telephone.set_ringer(self.ringer_device) self.telephone.set_ringer(self.ringer_device)
self.telephone.set_allowed(self.__is_allowed)
RNS.log(f"{self} initialised", RNS.LOG_DEBUG) RNS.log(f"{self} initialised", RNS.LOG_DEBUG)
def set_ringtone(self, ringtone_path): def set_ringtone(self, ringtone_path):
@ -155,6 +156,11 @@ class ReticulumTelephone():
self.state = self.STATE_IN_CALL self.state = self.STATE_IN_CALL
RNS.log(f"Call established with {RNS.prettyhexrep(self.caller.hash)}", RNS.LOG_DEBUG) RNS.log(f"Call established with {RNS.prettyhexrep(self.caller.hash)}", RNS.LOG_DEBUG)
def __is_allowed(self, identity_hash):
if self.owner.config["voice_trusted_only"]:
return self.owner.voice_is_trusted(identity_hash)
else: return True
def __spin(self, until=None, msg=None, timeout=None): def __spin(self, until=None, msg=None, timeout=None):
if msg: RNS.log(msg, RNS.LOG_DEBUG) if msg: RNS.log(msg, RNS.LOG_DEBUG)
if timeout != None: timeout = time.time()+timeout if timeout != None: timeout = time.time()+timeout

View file

@ -200,6 +200,9 @@ class Voice():
if not self.app.sideband.config["voice_ringer"] in self.output_devices: self.output_devices.append(self.app.sideband.config["voice_ringer"]) if not self.app.sideband.config["voice_ringer"] in self.output_devices: self.output_devices.append(self.app.sideband.config["voice_ringer"])
def update_settings_screen(self, sender=None): def update_settings_screen(self, sender=None):
self.voice_settings_screen.ids.voice_trusted_only.active = self.app.sideband.config["voice_trusted_only"]
self.voice_settings_screen.ids.voice_trusted_only.bind(active=self.settings_save_action)
bp = 6; ml = 45; fs = 16; ics = 14 bp = 6; ml = 45; fs = 16; ics = 14
self.update_devices() self.update_devices()
@ -257,6 +260,9 @@ class Voice():
self.voice_settings_screen.ids.ringer_devices.add_widget(device_button) self.voice_settings_screen.ids.ringer_devices.add_widget(device_button)
self.listed_ringer_devices.append(device) self.listed_ringer_devices.append(device)
def settings_save_action(self, sender=None, event=None):
self.app.sideband.config["voice_trusted_only"] = self.voice_settings_screen.ids.voice_trusted_only.active
self.app.sideband.save_configuration()
def output_device_action(self, sender=None): def output_device_action(self, sender=None):
self.app.sideband.config["voice_output"] = sender.device self.app.sideband.config["voice_output"] = sender.device
@ -377,7 +383,42 @@ MDScreen:
orientation: "vertical" orientation: "vertical"
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
padding: [dp(28), dp(32), dp(28), dp(16)] padding: [dp(28), dp(48), dp(28), dp(16)]
MDLabel:
text: "Call Handling"
font_style: "H6"
height: self.texture_size[1]
padding: [dp(0), dp(0), dp(0), dp(12)]
MDLabel:
id: voice_settings_info
markup: True
text: "You can block calls from all other callers than contacts marked as trusted, by enabling the following option."
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
padding: [dp(0), dp(16), dp(0), dp(16)]
MDBoxLayout:
orientation: "horizontal"
padding: [0,0,dp(24),0]
size_hint_y: None
height: dp(48)
MDLabel:
text: "Block non-trusted callers"
font_style: "H6"
MDSwitch:
id: voice_trusted_only
pos_hint: {"center_y": 0.3}
active: False
MDLabel:
text: "Audio Devices"
font_style: "H6"
padding: [dp(0), dp(96), dp(0), dp(12)]
MDLabel: MDLabel:
id: voice_settings_info id: voice_settings_info
@ -386,11 +427,12 @@ MDScreen:
size_hint_y: None size_hint_y: None
text_size: self.width, None text_size: self.width, None
height: self.texture_size[1] height: self.texture_size[1]
padding: [dp(0), dp(0), dp(0), dp(48)] padding: [dp(0), dp(64), dp(0), dp(32)]
MDLabel: MDLabel:
text: "Output Device" text: "[b]Output[/b]"
font_style: "H6" font_size: dp(18)
markup: True
MDBoxLayout: MDBoxLayout:
id: output_devices id: output_devices
@ -398,7 +440,7 @@ MDScreen:
spacing: "12dp" spacing: "12dp"
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
padding: [dp(0), dp(35), dp(0), dp(48)] padding: [dp(0), dp(24), dp(0), dp(48)]
# MDRectangleFlatIconButton: # MDRectangleFlatIconButton:
# id: output_default_button # id: output_default_button
@ -411,8 +453,9 @@ MDScreen:
# disabled: False # disabled: False
MDLabel: MDLabel:
text: "Input Device" text: "[b]Input[/b]"
font_style: "H6" font_size: dp(18)
markup: True
MDBoxLayout: MDBoxLayout:
id: input_devices id: input_devices
@ -420,11 +463,12 @@ MDScreen:
spacing: "12dp" spacing: "12dp"
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
padding: [dp(0), dp(35), dp(0), dp(48)] padding: [dp(0), dp(24), dp(0), dp(48)]
MDLabel: MDLabel:
text: "Ringer Device" text: "[b]Ringer[/b]"
font_style: "H6" font_size: dp(18)
markup: True
MDBoxLayout: MDBoxLayout:
id: ringer_devices id: ringer_devices
@ -432,6 +476,6 @@ MDScreen:
spacing: "12dp" spacing: "12dp"
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
padding: [dp(0), dp(35), dp(0), dp(48)] padding: [dp(0), dp(24), dp(0), dp(48)]
""" """