diff options
author | Miguel Jacq <mig@mig5.net> | 2021-11-30 10:50:47 +1100 |
---|---|---|
committer | Miguel Jacq <mig@mig5.net> | 2021-11-30 10:50:47 +1100 |
commit | 3273832da717aed487955be82bff71407991842a (patch) | |
tree | ee0fe6362148f14046cb87bf66e5e1c77cb33590 /cli/onionshare_cli/censorship.py | |
parent | b151eeb3c3a0eb6e2ff999377edf5fbc40742e09 (diff) | |
download | onionshare-3273832da717aed487955be82bff71407991842a.tar.gz onionshare-3273832da717aed487955be82bff71407991842a.zip |
Make the saving of the automatically-obtained bridges reusable (move it to CensorshipCircumvention class). Add the same functionality used in TorConnectionWidget to TorConnectionDialog.
Diffstat (limited to 'cli/onionshare_cli/censorship.py')
-rw-r--r-- | cli/onionshare_cli/censorship.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/cli/onionshare_cli/censorship.py b/cli/onionshare_cli/censorship.py index f84b1058..89513faa 100644 --- a/cli/onionshare_cli/censorship.py +++ b/cli/onionshare_cli/censorship.py @@ -167,3 +167,65 @@ class CensorshipCircumvention(object): return False return result + + def save_settings(self, settings, bridge_settings): + """ + Checks the bridges and saves them in settings. + """ + bridges_ok = False + self.settings = settings + + # @TODO there might be several bridge types recommended. + # Should we attempt to iterate over each type if one of them fails to connect? + # But if so, how to stop it starting 3 separate Tor connection threads? + # for bridges in request_bridges["settings"]: + bridges = bridge_settings["settings"][0]["bridges"] + self.common.log( + "CensorshipCircumvention", + "save_settings", + f"Obtained bridges: {bridges}", + ) + bridge_strings = bridges["bridge_strings"] + bridge_type = bridges["type"] + bridge_source = bridges["source"] + + # If the recommended bridge source is to use the built-in + # bridges, set that in our settings, as if the user had + # selected the built-in bridges for a specific PT themselves. + # + if bridge_source == "builtin": + self.settings.set("bridges_type", "built-in") + if bridge_type == "obfs4": + self.settings.set("bridges_builtin_pt", "obfs4") + if bridge_type == "snowflake": + self.settings.set("bridges_builtin_pt", "snowflake") + if bridge_type == "meek": + self.settings.set("bridges_builtin_pt", "meek-azure") + bridges_ok = True + else: + # Any other type of bridge we can treat as custom. + self.settings.set("bridges_type", "custom") + + # Sanity check the bridges provided from the Tor API before saving + bridges_checked = self.common.check_bridges_valid(bridge_strings) + + if bridges_checked: + self.settings.set("bridges_custom", "\n".join(bridges_checked)) + bridges_ok = True + + # If we got any good bridges, save them to settings and return. + if bridges_ok: + self.common.log( + "CensorshipCircumvention", + "save_settings", + "Saving settings with automatically-obtained bridges", + ) + self.settings.save() + return True + else: + self.common.log( + "CensorshipCircumvention", + "save_settings", + "Could not use any of the obtained bridges.", + ) + return False |