Added support for stealth onion services in the GUI version

This commit is contained in:
Micah Lee 2016-12-22 17:47:05 -08:00
parent 6fdef85878
commit 286573bda5
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
4 changed files with 58 additions and 2 deletions

View File

@ -91,6 +91,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
self.stop_server_finished.connect(self.server_status.stop_server_finished)
self.file_selection.file_list.files_updated.connect(self.server_status.update)
self.server_status.url_copied.connect(self.copy_url)
self.server_status.hidservauth_copied.connect(self.copy_hidservauth)
self.starting_server_step2.connect(self.start_server_step2)
self.starting_server_step3.connect(self.start_server_step3)
self.starting_server_error.connect(self.start_server_error)
@ -154,6 +155,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
# pick an available local port for the http service to listen on
self.app.choose_port()
# disable the stealth option
self.options.set_stealth_enabled(False)
# start onionshare http service in new thread
t = threading.Thread(target=web.start, args=(self.app.port, self.app.stay_open, self.app.transparent_torification))
t.daemon = True
@ -240,6 +244,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
web.stop(self.app.port)
self.app.cleanup()
self.filesize_warning.hide()
self.options.set_stealth_enabled(True)
self.stop_server_finished.emit()
@staticmethod
@ -310,6 +315,12 @@ class OnionShareGui(QtWidgets.QMainWindow):
"""
self.status_bar.showMessage(strings._('gui_copied_url', True), 2000)
def copy_hidservauth(self):
"""
When the stealth onion service HidServAuth gets copied to the clipboard, display this in the status bar.
"""
self.status_bar.showMessage(strings._('gui_copied_hidservauth', True), 2000)
def clear_message(self):
"""
Clear messages from the status bar.

View File

@ -21,7 +21,7 @@ from PyQt5 import QtCore, QtWidgets
from onionshare import strings, helpers
class Options(QtWidgets.QHBoxLayout):
class Options(QtWidgets.QVBoxLayout):
"""
The extra onionshare options in the GUI.
"""
@ -40,8 +40,15 @@ class Options(QtWidgets.QHBoxLayout):
self.close_automatically.setText(strings._("close_on_finish", True))
self.close_automatically.stateChanged.connect(self.stay_open_changed)
# stealth
self.stealth = QtWidgets.QCheckBox()
self.stealth.setCheckState(QtCore.Qt.Unchecked)
self.stealth.setText(strings._("create_stealth", True))
self.stealth.stateChanged.connect(self.stealth_changed)
# add the widgets
self.addWidget(self.close_automatically)
self.addWidget(self.stealth)
def stay_open_changed(self, state):
"""
@ -53,3 +60,19 @@ class Options(QtWidgets.QHBoxLayout):
else:
self.web.set_stay_open(True)
self.app.stay_open = True
def stealth_changed(self, state):
"""
When the 'stealth' checkbox is toggled, let the onionshare app know.
"""
if state == 2:
self.app.stealth = True
else:
self.app.stealth = False
def set_stealth_enabled(self, enabled):
"""
You cannot toggle stealth after an onion service has started. This method
disables and re-enabled the stealth checkbox.
"""
self.stealth.setEnabled(enabled)

View File

@ -29,6 +29,7 @@ class ServerStatus(QtWidgets.QVBoxLayout):
server_started = QtCore.pyqtSignal()
server_stopped = QtCore.pyqtSignal()
url_copied = QtCore.pyqtSignal()
hidservauth_copied = QtCore.pyqtSignal()
STATUS_STOPPED = 0
STATUS_WORKING = 1
@ -63,9 +64,12 @@ class ServerStatus(QtWidgets.QVBoxLayout):
self.url_label.setAlignment(QtCore.Qt.AlignCenter)
self.copy_url_button = QtWidgets.QPushButton(strings._('gui_copy_url', True))
self.copy_url_button.clicked.connect(self.copy_url)
self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True))
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
url_layout = QtWidgets.QHBoxLayout()
url_layout.addWidget(self.url_label)
url_layout.addWidget(self.copy_url_button)
url_layout.addWidget(self.copy_hidservauth_button)
# add the widgets
self.addLayout(server_layout)
@ -91,12 +95,18 @@ class ServerStatus(QtWidgets.QVBoxLayout):
self.url_label.show()
self.copy_url_button.show()
if self.app.stealth:
self.copy_hidservauth_button.show()
else:
self.copy_hidservauth_button.hide()
# resize parent widget
p = self.parentWidget()
p.resize(p.sizeHint())
else:
self.url_label.hide()
self.copy_url_button.hide()
self.copy_hidservauth_button.hide()
# button
if self.file_selection.get_num_files() == 0:
@ -163,3 +173,12 @@ class ServerStatus(QtWidgets.QVBoxLayout):
clipboard.setText(url)
self.url_copied.emit()
def copy_hidservauth(self):
"""
Copy the HidServAuth line to the clipboard.
"""
clipboard = self.qtapp.clipboard()
clipboard.setText(self.app.auth_string)
self.hidservauth_copied.emit()

View File

@ -35,9 +35,11 @@
"gui_start_server": "Start Sharing",
"gui_stop_server": "Stop Sharing",
"gui_copy_url": "Copy URL",
"gui_copy_hidservauth": "Copy HidServAuth",
"gui_downloads": "Downloads:",
"gui_canceled": "Canceled",
"gui_copied_url": "Copied URL to clipboard",
"gui_copied_hidservauth": "Copied HidServAuth line to clipboard",
"gui_starting_server1": "Starting Tor onion service...",
"gui_starting_server2": "Crunching files...",
"gui_starting_server3": "Waiting for Tor onion service...",
@ -54,5 +56,6 @@
"gui_quit_warning_dont_quit": "Don't Quit",
"error_rate_limit": "An attacker might be trying to guess your URL. To prevent this, OnionShare has automatically stopped the server. To share the files you must start it again and share the new URL.",
"zip_progress_bar_format": "Crunching files: %p%",
"error_stealth_not_supported": "Your versions of tor or stem are too old. You need to upgrade them to create stealth onion services."
"error_stealth_not_supported": "Your versions of tor or stem are too old. You need to upgrade them to create stealth onion services.",
"create_stealth": "Create stealth onion service (advanced)"
}