From 072f90df4f40d74c24769c5b1c7802c23bd77c3c Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 18 Oct 2021 18:18:04 -0700 Subject: [PATCH 1/4] Move Submit button next to the input field in MoatDialog --- desktop/src/onionshare/moat_dialog.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/desktop/src/onionshare/moat_dialog.py b/desktop/src/onionshare/moat_dialog.py index 2651736e..fbaac788 100644 --- a/desktop/src/onionshare/moat_dialog.py +++ b/desktop/src/onionshare/moat_dialog.py @@ -58,6 +58,11 @@ class MoatDialog(QtWidgets.QDialog): self.solution_lineedit.editingFinished.connect( self.solution_lineedit_editing_finished ) + self.submit_button = QtWidgets.QPushButton(strings._("moat_captcha_submit")) + self.submit_button.clicked.connect(self.submit_clicked) + solution_layout = QtWidgets.QHBoxLayout() + solution_layout.addWidget(self.solution_lineedit) + solution_layout.addWidget(self.submit_button) # Error label self.error_label = QtWidgets.QLabel() @@ -65,8 +70,6 @@ class MoatDialog(QtWidgets.QDialog): self.error_label.hide() # Buttons - self.submit_button = QtWidgets.QPushButton(strings._("moat_captcha_submit")) - self.submit_button.clicked.connect(self.submit_clicked) self.reload_button = QtWidgets.QPushButton(strings._("moat_captcha_reload")) self.reload_button.clicked.connect(self.reload_clicked) self.cancel_button = QtWidgets.QPushButton( @@ -74,7 +77,6 @@ class MoatDialog(QtWidgets.QDialog): ) self.cancel_button.clicked.connect(self.cancel_clicked) buttons_layout = QtWidgets.QHBoxLayout() - buttons_layout.addWidget(self.submit_button) buttons_layout.addStretch() buttons_layout.addWidget(self.reload_button) buttons_layout.addWidget(self.cancel_button) @@ -83,7 +85,7 @@ class MoatDialog(QtWidgets.QDialog): layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) layout.addWidget(self.captcha) - layout.addWidget(self.solution_lineedit) + layout.addLayout(solution_layout) layout.addStretch() layout.addWidget(self.error_label) layout.addLayout(buttons_layout) From 1f5dcd1689760fb568926cd70388734e538a23fc Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Tue, 19 Oct 2021 08:41:40 -0700 Subject: [PATCH 2/4] Ask BridgeDB for obfs4 and snowflake bridges, because that is what OnionShare supports --- desktop/src/onionshare/moat_dialog.py | 34 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/desktop/src/onionshare/moat_dialog.py b/desktop/src/onionshare/moat_dialog.py index fbaac788..28193c25 100644 --- a/desktop/src/onionshare/moat_dialog.py +++ b/desktop/src/onionshare/moat_dialog.py @@ -22,6 +22,7 @@ from PySide2 import QtCore, QtWidgets, QtGui import requests import os import base64 +import json from . import strings from .gui_common import GuiCommon @@ -133,7 +134,11 @@ class MoatDialog(QtWidgets.QDialog): self.t_check = MoatThread( self.common, "check", - {"challenge": self.challenge, "solution": self.solution_lineedit.text()}, + { + "transport": self.transport, + "challenge": self.challenge, + "solution": self.solution_lineedit.text(), + }, ) self.t_check.bridgedb_error.connect(self.bridgedb_error) self.t_check.captcha_error.connect(self.captcha_error) @@ -164,9 +169,10 @@ class MoatDialog(QtWidgets.QDialog): self.solution_lineedit.setEnabled(True) - def captcha_ready(self, image, challenge): + def captcha_ready(self, transport, image, challenge): self.common.log("MoatDialog", "captcha_ready") + self.transport = transport self.challenge = challenge # Save captcha image to disk, so we can load it @@ -208,7 +214,7 @@ class MoatThread(QtCore.QThread): bridgedb_error = QtCore.Signal() captcha_error = QtCore.Signal(str) - captcha_ready = QtCore.Signal(str, str) + captcha_ready = QtCore.Signal(str, str, str) bridges_ready = QtCore.Signal(str) def __init__(self, common, action, data={}): @@ -216,7 +222,6 @@ class MoatThread(QtCore.QThread): self.common = common self.common.log("MoatThread", "__init__", f"action={action}") - self.transport = "obfs4" self.action = action self.data = data @@ -235,7 +240,10 @@ class MoatThread(QtCore.QThread): { "version": "0.1.0", "type": "client-transports", - "supported": [self.transport], + "supported": [ + "obfs4", + "snowflake", + ], } ] }, @@ -259,17 +267,12 @@ class MoatThread(QtCore.QThread): self.common.log("MoatThread", "run", f"type != moat-challange") self.bridgedb_error.emit() return - if moat_res["data"][0]["transport"] != self.transport: - self.common.log( - "MoatThread", "run", f"transport != {self.transport}" - ) - self.bridgedb_error.emit() - return + transport = moat_res["data"][0]["transport"] image = moat_res["data"][0]["image"] challenge = moat_res["data"][0]["challenge"] - self.captcha_ready.emit(image, challenge) + self.captcha_ready.emit(transport, image, challenge) except Exception as e: self.common.log("MoatThread", "run", f"hit exception: {e}") self.bridgedb_error.emit() @@ -288,7 +291,7 @@ class MoatThread(QtCore.QThread): "id": "2", "type": "moat-solution", "version": "0.1.0", - "transport": self.transport, + "transport": self.data["transport"], "challenge": self.data["challenge"], "solution": self.data["solution"], "qrcode": "false", @@ -303,6 +306,11 @@ class MoatThread(QtCore.QThread): try: moat_res = r.json() + self.common.log( + "MoatThread", + "run", + f"got bridges:\n{json.dumps(moat_res,indent=2)}", + ) if "errors" in moat_res: self.common.log("MoatThread", "run", f"errors={moat_res['errors']}") From 3aa790269592d9d7e25b98c5b7e639c191f01f7d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Tue, 19 Oct 2021 08:50:33 -0700 Subject: [PATCH 3/4] Don't print Bridge lines in torrc for blank lines --- cli/onionshare_cli/onion.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index d52af9f3..0d205b97 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -337,14 +337,16 @@ class Onion(object): for line in self.settings.get("tor_bridges_use_moat_bridges").split( "\n" ): - f.write(f"Bridge {line}\n") + if line.strip() != "": + f.write(f"Bridge {line}\n") f.write("\nUseBridges 1\n") elif self.settings.get("tor_bridges_use_custom_bridges"): for line in self.settings.get( "tor_bridges_use_custom_bridges" ).split("\n"): - f.write(f"Bridge {line}\n") + if line.strip() != "": + f.write(f"Bridge {line}\n") f.write("\nUseBridges 1\n") # Execute a tor subprocess From 596c819957d6e74db397e55a2f0c4dcb2b1cc65d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Tue, 19 Oct 2021 08:53:52 -0700 Subject: [PATCH 4/4] Allow custom snowflake bridges --- desktop/src/onionshare/tor_settings_dialog.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop/src/onionshare/tor_settings_dialog.py b/desktop/src/onionshare/tor_settings_dialog.py index adad6931..38ff512a 100644 --- a/desktop/src/onionshare/tor_settings_dialog.py +++ b/desktop/src/onionshare/tor_settings_dialog.py @@ -809,10 +809,14 @@ class TorSettingsDialog(QtWidgets.QDialog): meek_lite_pattern = re.compile( "(meek_lite)(\s)+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+)(\s)+([0-9A-Z]+)(\s)+url=(.+)(\s)+front=(.+)" ) + snowflake_pattern = re.compile( + "(snowflake)(\s)+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+)(\s)+([0-9A-Z]+)" + ) if ( ipv4_pattern.match(bridge) or ipv6_pattern.match(bridge) or meek_lite_pattern.match(bridge) + or snowflake_pattern.match(bridge) ): new_bridges.append(bridge) bridges_valid = True