Start implementing moat

This commit is contained in:
Micah Lee 2021-10-15 14:44:09 -07:00
parent d1ae4e454f
commit 168e3057ae
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 58 additions and 19 deletions

View File

@ -68,6 +68,8 @@
"gui_settings_bridge_snowflake_radio_option": "Use built-in snowflake bridge", "gui_settings_bridge_snowflake_radio_option": "Use built-in snowflake bridge",
"gui_settings_meek_lite_expensive_warning": "Warning: The meek-azure bridges are very costly for the Tor Project to run.<br><br>Only use them if unable to connect to Tor directly, via obfs4 transports, or other normal bridges.", "gui_settings_meek_lite_expensive_warning": "Warning: The meek-azure bridges are very costly for the Tor Project to run.<br><br>Only use them if unable to connect to Tor directly, via obfs4 transports, or other normal bridges.",
"gui_settings_bridge_moat_radio_option": "Request a bridge from torproject.org", "gui_settings_bridge_moat_radio_option": "Request a bridge from torproject.org",
"gui_settings_bridge_moat_button": "Request a New Bridge...",
"gui_settings_bridge_moat_error": "Error requesting a bridge from torproject.org.",
"gui_settings_bridge_custom_radio_option": "Provide a bridge you learned about from a trusted source", "gui_settings_bridge_custom_radio_option": "Provide a bridge you learned about from a trusted source",
"gui_settings_tor_bridges_invalid": "None of the bridges you added work.\nDouble-check them or add others.", "gui_settings_tor_bridges_invalid": "None of the bridges you added work.\nDouble-check them or add others.",
"gui_settings_button_save": "Save", "gui_settings_button_save": "Save",

View File

@ -19,30 +19,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from PySide2 import QtCore, QtWidgets, QtGui from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtCore import Slot, Qt
from PySide2.QtGui import QPalette, QColor
import sys import sys
import platform import platform
import datetime
import re import re
import os import os
import requests
from onionshare_cli.settings import Settings from onionshare_cli.settings import Settings
from onionshare_cli.onion import ( from onionshare_cli.onion import Onion
Onion,
TorErrorInvalidSetting,
TorErrorAutomatic,
TorErrorSocketPort,
TorErrorSocketFile,
TorErrorMissingPassword,
TorErrorUnreadableCookieFile,
TorErrorAuthError,
TorErrorProtocolError,
BundledTorTimeout,
BundledTorBroken,
TorTooOldEphemeral,
TorTooOldStealth,
PortNotAvailable,
)
from . import strings from . import strings
from .widgets import Alert from .widgets import Alert
@ -159,10 +143,17 @@ class TorSettingsDialog(QtWidgets.QDialog):
strings._("gui_settings_bridge_moat_radio_option") strings._("gui_settings_bridge_moat_radio_option")
) )
self.bridge_moat_radio.toggled.connect(self.bridge_moat_radio_toggled) self.bridge_moat_radio.toggled.connect(self.bridge_moat_radio_toggled)
self.bridge_moat_button = QtWidgets.QPushButton(
strings._("gui_settings_bridge_moat_button")
)
self.bridge_moat_button.setMinimumHeight(20)
self.bridge_moat_button.clicked.connect(self.bridge_moat_button_clicked)
self.bridge_moat_textbox = QtWidgets.QPlainTextEdit() self.bridge_moat_textbox = QtWidgets.QPlainTextEdit()
self.bridge_moat_textbox.setMaximumHeight(200) self.bridge_moat_textbox.setMaximumHeight(200)
self.bridge_moat_textbox.setEnabled(False) self.bridge_moat_textbox.setEnabled(False)
self.bridge_moat_textbox.hide()
bridge_moat_textbox_options_layout = QtWidgets.QVBoxLayout() bridge_moat_textbox_options_layout = QtWidgets.QVBoxLayout()
bridge_moat_textbox_options_layout.addWidget(self.bridge_moat_button)
bridge_moat_textbox_options_layout.addWidget(self.bridge_moat_textbox) bridge_moat_textbox_options_layout.addWidget(self.bridge_moat_textbox)
self.bridge_moat_textbox_options = QtWidgets.QWidget() self.bridge_moat_textbox_options = QtWidgets.QWidget()
self.bridge_moat_textbox_options.setLayout(bridge_moat_textbox_options_layout) self.bridge_moat_textbox_options.setLayout(bridge_moat_textbox_options_layout)
@ -511,6 +502,52 @@ class TorSettingsDialog(QtWidgets.QDialog):
self.bridge_custom_textbox_options.hide() self.bridge_custom_textbox_options.hide()
self.bridge_moat_textbox_options.show() self.bridge_moat_textbox_options.show()
def bridge_moat_button_clicked(self):
"""
Request new bridge button clicked
"""
self.common.log("TorSettingsDialog", "bridge_moat_button_clicked")
def moat_error():
Alert(
self.common,
strings._("gui_settings_bridge_moat_error"),
title=strings._("gui_settings_bridge_moat_button"),
)
# TODO: Do all of this using domain fronting
# Request a bridge
r = requests.post(
"https://bridges.torproject.org/moat/fetch",
headers={"Content-Type": "application/vnd.api+json"},
json={
"data": [
{
"version": "0.1.0",
"type": "client-transports",
"supported": ["obfs4"],
}
]
},
)
if r.status_code != 200:
return moat_error()
try:
moat_res = r.json()
if "errors" in moat_res or "data" not in moat_res:
return moat_error()
if moat_res["type"] != "moat-challenge":
return moat_error()
moat_type = moat_res["type"]
moat_transport = moat_res["transport"]
moat_image = moat_res["image"]
moat_challenge = moat_res["challenge"]
except:
return moat_error()
def bridge_custom_radio_toggled(self, checked): def bridge_custom_radio_toggled(self, checked):
""" """
Custom bridges option was toggled. If checked, show custom bridge options. Custom bridges option was toggled. If checked, show custom bridge options.