mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 08:49:30 -05:00
Move the saving of private key into the SettingsDialog and Onion objects entirely (no QPushButton to save it)
This commit is contained in:
parent
8e89a65a22
commit
e90908c5b0
@ -423,10 +423,9 @@ class Onion(object):
|
|||||||
onion_host = self.service_id + '.onion'
|
onion_host = self.service_id + '.onion'
|
||||||
|
|
||||||
# A new private key was generated and is in the Control port response.
|
# A new private key was generated and is in the Control port response.
|
||||||
if not self.settings.get('private_key'):
|
if self.settings.get('save_private_key'):
|
||||||
self.private_key = res.private_key
|
if not self.settings.get('private_key'):
|
||||||
else:
|
self.settings.set('private_key', res.private_key)
|
||||||
self.private_key = ''
|
|
||||||
|
|
||||||
if self.stealth:
|
if self.stealth:
|
||||||
# Similar to the PrivateKey, the Control port only returns the ClientAuth
|
# Similar to the PrivateKey, the Control port only returns the ClientAuth
|
||||||
@ -434,12 +433,18 @@ class Onion(object):
|
|||||||
# in the first place.
|
# in the first place.
|
||||||
# If we sent the basic_auth (due to a saved hidservauth_string in the settings),
|
# If we sent the basic_auth (due to a saved hidservauth_string in the settings),
|
||||||
# there is no response here, so use the saved value from settings.
|
# there is no response here, so use the saved value from settings.
|
||||||
if self.settings.get('hidservauth_string'):
|
if self.settings.get('save_private_key'):
|
||||||
self.auth_string = self.settings.get('hidservauth_string')
|
if self.settings.get('hidservauth_string'):
|
||||||
|
self.auth_string = self.settings.get('hidservauth_string')
|
||||||
|
else:
|
||||||
|
auth_cookie = list(res.client_auth.values())[0]
|
||||||
|
self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
|
||||||
|
self.settings.set('hidservauth_string', self.auth_string)
|
||||||
else:
|
else:
|
||||||
auth_cookie = list(res.client_auth.values())[0]
|
auth_cookie = list(res.client_auth.values())[0]
|
||||||
self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
|
self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
|
||||||
|
|
||||||
|
self.settings.save()
|
||||||
return onion_host
|
return onion_host
|
||||||
|
|
||||||
def cleanup(self, stop_tor=True):
|
def cleanup(self, stop_tor=True):
|
||||||
|
@ -78,9 +78,6 @@ class OnionShare(object):
|
|||||||
|
|
||||||
self.onion_host = self.onion.start_onion_service(self.port)
|
self.onion_host = self.onion.start_onion_service(self.port)
|
||||||
|
|
||||||
if self.onion.private_key:
|
|
||||||
self.private_key = self.onion.private_key
|
|
||||||
|
|
||||||
if self.stealth:
|
if self.stealth:
|
||||||
self.auth_string = self.onion.auth_string
|
self.auth_string = self.onion.auth_string
|
||||||
|
|
||||||
|
@ -60,7 +60,10 @@ class Settings(object):
|
|||||||
'systray_notifications': True,
|
'systray_notifications': True,
|
||||||
'use_stealth': False,
|
'use_stealth': False,
|
||||||
'use_autoupdate': True,
|
'use_autoupdate': True,
|
||||||
'autoupdate_timestamp': None
|
'autoupdate_timestamp': None,
|
||||||
|
'save_private_key': False,
|
||||||
|
'private_key': '',
|
||||||
|
'hidservauth_string': ''
|
||||||
}
|
}
|
||||||
self._settings = {}
|
self._settings = {}
|
||||||
self.fill_in_defaults()
|
self.fill_in_defaults()
|
||||||
|
@ -80,7 +80,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.file_selection.file_list.files_updated.connect(self.server_status.update)
|
self.file_selection.file_list.files_updated.connect(self.server_status.update)
|
||||||
self.server_status.url_copied.connect(self.copy_url)
|
self.server_status.url_copied.connect(self.copy_url)
|
||||||
self.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
self.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
||||||
self.server_status.private_key_saved.connect(self.private_key_saved)
|
|
||||||
self.starting_server_step2.connect(self.start_server_step2)
|
self.starting_server_step2.connect(self.start_server_step2)
|
||||||
self.starting_server_step3.connect(self.start_server_step3)
|
self.starting_server_step3.connect(self.start_server_step3)
|
||||||
self.starting_server_error.connect(self.start_server_error)
|
self.starting_server_error.connect(self.start_server_error)
|
||||||
@ -473,13 +472,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
common.log('OnionShareGui', 'copy_hidservauth')
|
common.log('OnionShareGui', 'copy_hidservauth')
|
||||||
self.status_bar.showMessage(strings._('gui_copied_hidservauth', True), 2000)
|
self.status_bar.showMessage(strings._('gui_copied_hidservauth', True), 2000)
|
||||||
|
|
||||||
def private_key_saved(self):
|
|
||||||
"""
|
|
||||||
When the private key gets saved, display this in the status bar.
|
|
||||||
"""
|
|
||||||
common.log('OnionShareGui', 'private_key_saved')
|
|
||||||
self.status_bar.showMessage(strings._('gui_private_key_saved', True), 2000)
|
|
||||||
|
|
||||||
def clear_message(self):
|
def clear_message(self):
|
||||||
"""
|
"""
|
||||||
Clear messages from the status bar.
|
Clear messages from the status bar.
|
||||||
|
@ -32,7 +32,6 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
server_stopped = QtCore.pyqtSignal()
|
server_stopped = QtCore.pyqtSignal()
|
||||||
url_copied = QtCore.pyqtSignal()
|
url_copied = QtCore.pyqtSignal()
|
||||||
hidservauth_copied = QtCore.pyqtSignal()
|
hidservauth_copied = QtCore.pyqtSignal()
|
||||||
private_key_saved = QtCore.pyqtSignal()
|
|
||||||
|
|
||||||
STATUS_STOPPED = 0
|
STATUS_STOPPED = 0
|
||||||
STATUS_WORKING = 1
|
STATUS_WORKING = 1
|
||||||
@ -90,13 +89,10 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
self.copy_url_button.clicked.connect(self.copy_url)
|
self.copy_url_button.clicked.connect(self.copy_url)
|
||||||
self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True))
|
self.copy_hidservauth_button = QtWidgets.QPushButton(strings._('gui_copy_hidservauth', True))
|
||||||
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
|
self.copy_hidservauth_button.clicked.connect(self.copy_hidservauth)
|
||||||
self.save_private_key_button = QtWidgets.QPushButton(strings._('gui_save_private_key', True))
|
|
||||||
self.save_private_key_button.clicked.connect(self.save_private_key)
|
|
||||||
url_layout = QtWidgets.QHBoxLayout()
|
url_layout = QtWidgets.QHBoxLayout()
|
||||||
url_layout.addWidget(self.url_label)
|
url_layout.addWidget(self.url_label)
|
||||||
url_layout.addWidget(self.copy_url_button)
|
url_layout.addWidget(self.copy_url_button)
|
||||||
url_layout.addWidget(self.copy_hidservauth_button)
|
url_layout.addWidget(self.copy_hidservauth_button)
|
||||||
url_layout.addWidget(self.save_private_key_button)
|
|
||||||
|
|
||||||
# add the widgets
|
# add the widgets
|
||||||
self.addLayout(shutdown_timeout_layout_group)
|
self.addLayout(shutdown_timeout_layout_group)
|
||||||
@ -146,9 +142,8 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
self.url_label.setText('http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug))
|
self.url_label.setText('http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug))
|
||||||
self.url_label.show()
|
self.url_label.show()
|
||||||
self.copy_url_button.show()
|
self.copy_url_button.show()
|
||||||
if not self.settings.get('private_key'):
|
if self.settings.get('save_private_key'):
|
||||||
self.save_private_key_button.show()
|
common.log('ServerStatus', 'update', '@TODO need to show a "persistent URL in use" label')
|
||||||
self.save_private_key_button.setEnabled(True)
|
|
||||||
|
|
||||||
if self.app.stealth:
|
if self.app.stealth:
|
||||||
self.copy_hidservauth_button.show()
|
self.copy_hidservauth_button.show()
|
||||||
@ -162,7 +157,6 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
self.url_label.hide()
|
self.url_label.hide()
|
||||||
self.copy_url_button.hide()
|
self.copy_url_button.hide()
|
||||||
self.copy_hidservauth_button.hide()
|
self.copy_hidservauth_button.hide()
|
||||||
self.save_private_key_button.hide()
|
|
||||||
|
|
||||||
# button
|
# button
|
||||||
if self.file_selection.get_num_files() == 0:
|
if self.file_selection.get_num_files() == 0:
|
||||||
@ -259,16 +253,3 @@ class ServerStatus(QtWidgets.QVBoxLayout):
|
|||||||
clipboard.setText(self.app.auth_string)
|
clipboard.setText(self.app.auth_string)
|
||||||
|
|
||||||
self.hidservauth_copied.emit()
|
self.hidservauth_copied.emit()
|
||||||
|
|
||||||
def save_private_key(self):
|
|
||||||
"""
|
|
||||||
Save the Onion private key to settings, so the Onion URL can be re-used.
|
|
||||||
"""
|
|
||||||
self.save_private_key_button.setEnabled(False)
|
|
||||||
self.settings.set('private_key', self.app.private_key)
|
|
||||||
if self.app.stealth:
|
|
||||||
self.settings.set('hidservauth_string', self.app.auth_string)
|
|
||||||
self.settings.save()
|
|
||||||
self.settings.load()
|
|
||||||
|
|
||||||
self.private_key_saved.emit()
|
|
||||||
|
@ -291,12 +291,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
else:
|
else:
|
||||||
self.systray_notifications_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
self.systray_notifications_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
save_private_key = self.old_settings.get('private_key')
|
save_private_key = self.old_settings.get('save_private_key')
|
||||||
if save_private_key:
|
if save_private_key:
|
||||||
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Checked)
|
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
else:
|
else:
|
||||||
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
self.save_private_key_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
self.save_private_key_checkbox.hide()
|
|
||||||
|
|
||||||
use_stealth = self.old_settings.get('use_stealth')
|
use_stealth = self.old_settings.get('use_stealth')
|
||||||
if use_stealth:
|
if use_stealth:
|
||||||
@ -565,9 +564,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked())
|
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked())
|
||||||
settings.set('systray_notifications', self.systray_notifications_checkbox.isChecked())
|
settings.set('systray_notifications', self.systray_notifications_checkbox.isChecked())
|
||||||
if self.save_private_key_checkbox.isChecked():
|
if self.save_private_key_checkbox.isChecked():
|
||||||
|
settings.set('save_private_key', True)
|
||||||
settings.set('private_key', self.old_settings.get('private_key'))
|
settings.set('private_key', self.old_settings.get('private_key'))
|
||||||
settings.set('hidservauth_string', self.old_settings.get('hidservauth_string'))
|
settings.set('hidservauth_string', self.old_settings.get('hidservauth_string'))
|
||||||
else:
|
else:
|
||||||
|
settings.set('save_private_key', False)
|
||||||
settings.set('private_key', '')
|
settings.set('private_key', '')
|
||||||
# Also unset the HidServAuth if we are removing our reusable private key
|
# Also unset the HidServAuth if we are removing our reusable private key
|
||||||
settings.set('hidservauth_string', '')
|
settings.set('hidservauth_string', '')
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
"gui_canceled": "Canceled",
|
"gui_canceled": "Canceled",
|
||||||
"gui_copied_url": "Copied URL to clipboard",
|
"gui_copied_url": "Copied URL to clipboard",
|
||||||
"gui_copied_hidservauth": "Copied HidServAuth line to clipboard",
|
"gui_copied_hidservauth": "Copied HidServAuth line to clipboard",
|
||||||
"gui_private_key_saved": "Private key saved to settings",
|
|
||||||
"gui_starting_server1": "Starting Tor onion service...",
|
"gui_starting_server1": "Starting Tor onion service...",
|
||||||
"gui_starting_server2": "Crunching files...",
|
"gui_starting_server2": "Crunching files...",
|
||||||
"gui_please_wait": "Please wait...",
|
"gui_please_wait": "Please wait...",
|
||||||
@ -124,6 +123,5 @@
|
|||||||
"gui_server_started_after_timeout": "The server started after your chosen auto-timeout.\nPlease start a new share.",
|
"gui_server_started_after_timeout": "The server started after your chosen auto-timeout.\nPlease start a new share.",
|
||||||
"gui_server_timeout_expired": "The chosen timeout has already expired.\nPlease update the timeout and then you may start sharing.",
|
"gui_server_timeout_expired": "The chosen timeout has already expired.\nPlease update the timeout and then you may start sharing.",
|
||||||
"share_via_onionshare": "Share via OnionShare",
|
"share_via_onionshare": "Share via OnionShare",
|
||||||
"gui_save_private_key": "Save private key",
|
"gui_save_private_key_checkbox": "Use a persistent URL\n(unchecking will delete any saved URL)"
|
||||||
"gui_save_private_key_checkbox": "Should the private key be saved for re-use?\nThis makes the Onion share URL persistent.\nUnchecking will remove the private key from settings."
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user