From c4cf9f08ec97051af0c8f40a25921ad8ba0d92f4 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 6 May 2021 18:02:40 +1000 Subject: [PATCH] Rename things with client_auth_v3_ in the name because there is only one type of client_auth now that v2 is gone. --- cli/onionshare_cli/mode_settings.py | 4 +-- cli/onionshare_cli/onion.py | 27 +++++++++---------- .../src/onionshare/resources/locale/en.json | 8 +++--- .../tab/mode/mode_settings_widget.py | 20 +++++++------- desktop/src/onionshare/tab/server_status.py | 24 ++++++++--------- desktop/src/onionshare/tab/tab.py | 23 ++++++++-------- desktop/tests/gui_base_test.py | 6 ++--- desktop/tests/test_gui_share.py | 7 ++--- 8 files changed, 60 insertions(+), 59 deletions(-) diff --git a/cli/onionshare_cli/mode_settings.py b/cli/onionshare_cli/mode_settings.py index 736b6c31..89ca00ea 100644 --- a/cli/onionshare_cli/mode_settings.py +++ b/cli/onionshare_cli/mode_settings.py @@ -39,8 +39,8 @@ class ModeSettings: "private_key": None, "hidservauth_string": None, "password": None, - "client_auth_v3_priv_key": None, - "client_auth_v3_pub_key": None, + "client_auth_priv_key": None, + "client_auth_pub_key": None, }, "persistent": {"mode": None, "enabled": False}, "general": { diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index 0dde7070..198f05c3 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -606,7 +606,6 @@ class Onion(object): # https://trac.torproject.org/projects/tor/ticket/28619 self.supports_v3_onions = self.tor_version >= Version("0.3.5.7") - def is_authenticated(self): """ Returns True if the Tor connection is still working, or False otherwise. @@ -648,19 +647,19 @@ class Onion(object): ) raise TorTooOldStealth() else: - if key_type == "NEW" or not mode_settings.get("onion", "client_auth_v3_priv_key"): + if key_type == "NEW" or not mode_settings.get("onion", "client_auth_priv_key"): # Generate a new key pair for Client Auth on new onions, or if # it's a persistent onion but for some reason we don't them - client_auth_v3_priv_key_raw = nacl.public.PrivateKey.generate() - client_auth_v3_priv_key = self.key_str(client_auth_v3_priv_key_raw) - client_auth_v3_pub_key = self.key_str(client_auth_v3_priv_key_raw.public_key) + client_auth_priv_key_raw = nacl.public.PrivateKey.generate() + client_auth_priv_key = self.key_str(client_auth_priv_key_raw) + client_auth_pub_key = self.key_str(client_auth_priv_key_raw.public_key) else: # These should have been saved in settings from the previous run of a persistent onion - client_auth_v3_priv_key = mode_settings.get("onion", "client_auth_v3_priv_key") - client_auth_v3_pub_key = mode_settings.get("onion", "client_auth_v3_pub_key") + client_auth_priv_key = mode_settings.get("onion", "client_auth_priv_key") + client_auth_pub_key = mode_settings.get("onion", "client_auth_pub_key") else: - client_auth_v3_priv_key = None - client_auth_v3_pub_key = None + client_auth_priv_key = None + client_auth_pub_key = None try: if not self.supports_stealth: @@ -678,7 +677,7 @@ class Onion(object): basic_auth=None, key_type=key_type, key_content=key_content, - client_auth_v3=client_auth_v3_pub_key, + client_auth_v3=client_auth_pub_key, ) except ProtocolError as e: @@ -703,14 +702,14 @@ class Onion(object): # same share at a later date), and the private key to the other user for # their Tor Browser. if mode_settings.get("general", "client_auth"): - mode_settings.set("onion", "client_auth_v3_priv_key", client_auth_v3_priv_key) - mode_settings.set("onion", "client_auth_v3_pub_key", client_auth_v3_pub_key) + mode_settings.set("onion", "client_auth_priv_key", client_auth_priv_key) + mode_settings.set("onion", "client_auth_pub_key", client_auth_pub_key) # If we were pasting the client auth directly into the filesystem behind a Tor client, # it would need to be in the format below. However, let's just set the private key # by itself, as this can be pasted directly into Tor Browser, which is likely to # be the most common use case. - # self.auth_string = f"{onion_host}:x25519:{client_auth_v3_priv_key}" - self.auth_string = client_auth_v3_priv_key + # self.auth_string = f"{onion_host}:x25519:{client_auth_priv_key}" + self.auth_string = client_auth_priv_key return onion_host diff --git a/desktop/src/onionshare/resources/locale/en.json b/desktop/src/onionshare/resources/locale/en.json index c6c202ea..3fdca5c8 100644 --- a/desktop/src/onionshare/resources/locale/en.json +++ b/desktop/src/onionshare/resources/locale/en.json @@ -24,12 +24,12 @@ "gui_receive_stop_server_autostop_timer": "Stop Receive Mode ({} remaining)", "gui_receive_flatpak_data_dir": "Because you installed OnionShare using Flatpak, you must save files to a folder in ~/OnionShare.", "gui_copy_url": "Copy Address", - "gui_copy_client_auth_v3": "Copy ClientAuth", + "gui_copy_client_auth": "Copy ClientAuth", "gui_canceled": "Canceled", "gui_copied_url_title": "Copied OnionShare Address", "gui_copied_url": "OnionShare address copied to clipboard", - "gui_copied_client_auth_v3_title": "Copied ClientAuth", - "gui_copied_client_auth_v3": "ClientAuth private key copied to clipboard", + "gui_copied_client_auth_title": "Copied ClientAuth", + "gui_copied_client_auth": "ClientAuth private key copied to clipboard", "gui_show_url_qr_code": "Show QR Code", "gui_qr_code_dialog_title": "OnionShare QR Code", "gui_waiting_to_start": "Scheduled to start in {}. Click to cancel.", @@ -171,7 +171,7 @@ "mode_settings_public_checkbox": "Don't use a password", "mode_settings_autostart_timer_checkbox": "Start onion service at scheduled time", "mode_settings_autostop_timer_checkbox": "Stop onion service at scheduled time", - "mode_settings_client_auth_v3_checkbox": "Use client authorization", + "mode_settings_client_auth_checkbox": "Use client authorization", "mode_settings_share_autostop_sharing_checkbox": "Stop sharing after files have been sent (uncheck to allow downloading individual files)", "mode_settings_receive_data_dir_label": "Save files to", "mode_settings_receive_data_dir_browse_button": "Browse", diff --git a/desktop/src/onionshare/tab/mode/mode_settings_widget.py b/desktop/src/onionshare/tab/mode/mode_settings_widget.py index 0f1a7c28..5003e4ac 100644 --- a/desktop/src/onionshare/tab/mode/mode_settings_widget.py +++ b/desktop/src/onionshare/tab/mode/mode_settings_widget.py @@ -130,16 +130,16 @@ class ModeSettingsWidget(QtWidgets.QWidget): autostop_timer_layout.addWidget(self.autostop_timer_widget) # Client auth (v3) - self.client_auth_v3_checkbox = QtWidgets.QCheckBox() - self.client_auth_v3_checkbox.clicked.connect(self.client_auth_v3_checkbox_clicked) - self.client_auth_v3_checkbox.clicked.connect(self.update_ui) - self.client_auth_v3_checkbox.setText( - strings._("mode_settings_client_auth_v3_checkbox") + self.client_auth_checkbox = QtWidgets.QCheckBox() + self.client_auth_checkbox.clicked.connect(self.client_auth_checkbox_clicked) + self.client_auth_checkbox.clicked.connect(self.update_ui) + self.client_auth_checkbox.setText( + strings._("mode_settings_client_auth_checkbox") ) if self.settings.get("general", "client_auth"): - self.client_auth_v3_checkbox.setCheckState(QtCore.Qt.Checked) + self.client_auth_checkbox.setCheckState(QtCore.Qt.Checked) else: - self.client_auth_v3_checkbox.setCheckState(QtCore.Qt.Unchecked) + self.client_auth_checkbox.setCheckState(QtCore.Qt.Unchecked) # Toggle advanced settings self.toggle_advanced_button = QtWidgets.QPushButton() @@ -155,7 +155,7 @@ class ModeSettingsWidget(QtWidgets.QWidget): advanced_layout.addLayout(title_layout) advanced_layout.addLayout(autostart_timer_layout) advanced_layout.addLayout(autostop_timer_layout) - advanced_layout.addWidget(self.client_auth_v3_checkbox) + advanced_layout.addWidget(self.client_auth_checkbox) self.advanced_widget = QtWidgets.QWidget() self.advanced_widget.setLayout(advanced_layout) self.advanced_widget.hide() @@ -242,9 +242,9 @@ class ModeSettingsWidget(QtWidgets.QWidget): else: self.autostop_timer_widget.hide() - def client_auth_v3_checkbox_clicked(self): + def client_auth_checkbox_clicked(self): self.settings.set( - "general", "client_auth", self.client_auth_v3_checkbox.isChecked() + "general", "client_auth", self.client_auth_checkbox.isChecked() ) def toggle_advanced_clicked(self): diff --git a/desktop/src/onionshare/tab/server_status.py b/desktop/src/onionshare/tab/server_status.py index f53af912..cb9bfd92 100644 --- a/desktop/src/onionshare/tab/server_status.py +++ b/desktop/src/onionshare/tab/server_status.py @@ -38,7 +38,7 @@ class ServerStatus(QtWidgets.QWidget): server_canceled = QtCore.Signal() button_clicked = QtCore.Signal() url_copied = QtCore.Signal() - client_auth_v3_copied = QtCore.Signal() + client_auth_copied = QtCore.Signal() STATUS_STOPPED = 0 STATUS_WORKING = 1 @@ -95,8 +95,8 @@ class ServerStatus(QtWidgets.QWidget): self.common.gui.css["server_status_url_buttons"] ) self.copy_url_button.clicked.connect(self.copy_url) - self.copy_client_auth_v3_button = QtWidgets.QPushButton( - strings._("gui_copy_client_auth_v3") + self.copy_client_auth_button = QtWidgets.QPushButton( + strings._("gui_copy_client_auth") ) self.show_url_qr_code_button = QtWidgets.QPushButton( strings._("gui_show_url_qr_code") @@ -109,14 +109,14 @@ class ServerStatus(QtWidgets.QWidget): self.common.gui.css["server_status_url_buttons"] ) - self.copy_client_auth_v3_button.setStyleSheet( + self.copy_client_auth_button.setStyleSheet( self.common.gui.css["server_status_url_buttons"] ) - self.copy_client_auth_v3_button.clicked.connect(self.copy_client_auth_v3) + self.copy_client_auth_button.clicked.connect(self.copy_client_auth) url_buttons_layout = QtWidgets.QHBoxLayout() url_buttons_layout.addWidget(self.copy_url_button) url_buttons_layout.addWidget(self.show_url_qr_code_button) - url_buttons_layout.addWidget(self.copy_client_auth_v3_button) + url_buttons_layout.addWidget(self.copy_client_auth_button) url_buttons_layout.addStretch() url_layout = QtWidgets.QVBoxLayout() @@ -214,9 +214,9 @@ class ServerStatus(QtWidgets.QWidget): self.show_url_qr_code_button.show() if self.settings.get("general", "client_auth"): - self.copy_client_auth_v3_button.show() + self.copy_client_auth_button.show() else: - self.copy_client_auth_v3_button.hide() + self.copy_client_auth_button.hide() def update(self): """ @@ -246,7 +246,7 @@ class ServerStatus(QtWidgets.QWidget): self.url_description.hide() self.url.hide() self.copy_url_button.hide() - self.copy_client_auth_v3_button.hide() + self.copy_client_auth_button.hide() self.show_url_qr_code_button.hide() self.mode_settings_widget.update_ui() @@ -445,14 +445,14 @@ class ServerStatus(QtWidgets.QWidget): self.url_copied.emit() - def copy_client_auth_v3(self): + def copy_client_auth(self): """ - Copy the ClientAuth v3 private key line to the clipboard. + Copy the ClientAuth private key line to the clipboard. """ clipboard = self.qtapp.clipboard() clipboard.setText(self.app.auth_string) - self.client_auth_v3_copied.emit() + self.client_auth_copied.emit() def get_url(self): """ diff --git a/desktop/src/onionshare/tab/tab.py b/desktop/src/onionshare/tab/tab.py index 845fbf72..2d9b1a8c 100644 --- a/desktop/src/onionshare/tab/tab.py +++ b/desktop/src/onionshare/tab/tab.py @@ -275,7 +275,7 @@ class Tab(QtWidgets.QWidget): self.share_mode.start_server_finished.connect(self.clear_message) self.share_mode.server_status.button_clicked.connect(self.clear_message) self.share_mode.server_status.url_copied.connect(self.copy_url) - self.share_mode.server_status.client_auth_v3_copied.connect(self.copy_client_auth_v3) + self.share_mode.server_status.client_auth_copied.connect(self.copy_client_auth) self.change_title.emit(self.tab_id, strings._("gui_tab_name_share")) @@ -310,8 +310,8 @@ class Tab(QtWidgets.QWidget): self.receive_mode.start_server_finished.connect(self.clear_message) self.receive_mode.server_status.button_clicked.connect(self.clear_message) self.receive_mode.server_status.url_copied.connect(self.copy_url) - self.receive_mode.server_status.client_auth_v3_copied.connect( - self.copy_client_auth_v3 + self.receive_mode.server_status.client_auth_copied.connect( + self.copy_client_auth ) self.change_title.emit(self.tab_id, strings._("gui_tab_name_receive")) @@ -347,8 +347,8 @@ class Tab(QtWidgets.QWidget): self.website_mode.start_server_finished.connect(self.clear_message) self.website_mode.server_status.button_clicked.connect(self.clear_message) self.website_mode.server_status.url_copied.connect(self.copy_url) - self.website_mode.server_status.client_auth_v3_copied.connect( - self.copy_client_auth_v3 + self.website_mode.server_status.client_auth_copied.connect( + self.copy_client_auth ) self.change_title.emit(self.tab_id, strings._("gui_tab_name_website")) @@ -382,7 +382,7 @@ class Tab(QtWidgets.QWidget): self.chat_mode.start_server_finished.connect(self.clear_message) self.chat_mode.server_status.button_clicked.connect(self.clear_message) self.chat_mode.server_status.url_copied.connect(self.copy_url) - self.chat_mode.server_status.client_auth_v3_copied.connect(self.copy_client_auth_v3) + self.chat_mode.server_status.client_auth_copied.connect(self.copy_client_auth) self.change_title.emit(self.tab_id, strings._("gui_tab_name_chat")) @@ -597,14 +597,15 @@ class Tab(QtWidgets.QWidget): strings._("gui_copied_url_title"), strings._("gui_copied_url") ) - def copy_client_auth_v3(self): + def copy_client_auth(self): """ - When the v3 onion service ClientAuth private key gets copied to the clipboard, display this in the status bar. + When the onion service's ClientAuth private key gets copied to + the clipboard, display this in the status bar. """ - self.common.log("Tab", "copy_client_auth_v3") + self.common.log("Tab", "copy_client_auth") self.system_tray.showMessage( - strings._("gui_copied_client_auth_v3_title"), - strings._("gui_copied_client_auth_v3"), + strings._("gui_copied_client_auth_title"), + strings._("gui_copied_client_auth"), ) def clear_message(self): diff --git a/desktop/tests/gui_base_test.py b/desktop/tests/gui_base_test.py index da61f4e5..86c88a10 100644 --- a/desktop/tests/gui_base_test.py +++ b/desktop/tests/gui_base_test.py @@ -371,7 +371,7 @@ class GuiBaseTest(unittest.TestCase): self.assertFalse(tab.get_mode().server_status.url.isVisible()) self.assertFalse(tab.get_mode().server_status.url_description.isVisible()) self.assertFalse( - tab.get_mode().server_status.copy_client_auth_v3_button.isVisible() + tab.get_mode().server_status.copy_client_auth_button.isVisible() ) def web_server_is_stopped(self, tab): @@ -454,9 +454,9 @@ class GuiBaseTest(unittest.TestCase): def clientauth_is_visible(self, tab): self.assertTrue( - tab.get_mode().server_status.copy_client_auth_v3_button.isVisible() + tab.get_mode().server_status.copy_client_auth_button.isVisible() ) - tab.get_mode().server_status.copy_client_auth_v3_button.click() + tab.get_mode().server_status.copy_client_auth_button.click() clipboard = tab.common.gui.qtapp.clipboard() self.assertEqual(clipboard.text(), "E2GOT5LTUTP3OAMRCRXO4GSH6VKJEUOXZQUC336SRKAHTTT5OVSA") diff --git a/desktop/tests/test_gui_share.py b/desktop/tests/test_gui_share.py index 08924ca6..e13519da 100644 --- a/desktop/tests/test_gui_share.py +++ b/desktop/tests/test_gui_share.py @@ -611,12 +611,13 @@ class TestShare(GuiBaseTest): def test_client_auth(self): """ - Test the ClientAuth is received from the backend and that - the widget is visible in the UI + Test the ClientAuth is received from the backend, + that the widget is visible in the UI and that the + clipboard contains the ClientAuth string """ tab = self.new_share_tab() tab.get_mode().mode_settings_widget.toggle_advanced_button.click() - tab.get_mode().mode_settings_widget.client_auth_v3_checkbox.click() + tab.get_mode().mode_settings_widget.client_auth_checkbox.click() self.run_all_common_setup_tests() self.run_all_share_mode_setup_tests(tab)