encrypted .tox files support

This commit is contained in:
ingvar1995 2016-05-15 19:54:44 +03:00
parent 010c15a498
commit 0fa7ca7b5c
4 changed files with 52 additions and 18 deletions

View File

@ -10,6 +10,7 @@ from util import curr_directory, get_style
import styles.style import styles.style
import locale import locale
import toxencryptsave import toxencryptsave
from passwordscreen import PasswordScreen
class Toxygen(object): class Toxygen(object):
@ -19,12 +20,19 @@ class Toxygen(object):
self.tox = self.ms = self.init = self.mainloop = self.avloop = None self.tox = self.ms = self.init = self.mainloop = self.avloop = None
self.path = path self.path = path
def enter_pass(self, old_data): def enter_pass(self, data):
""" """
Show password screen Show password screen
""" """
# TODO: show password screen and decrypt data tmp = [data]
raise NotImplementedError() p = PasswordScreen(toxencryptsave.LibToxEncryptSave.get_instance(), tmp)
p.show()
self.app.connect(self.app, QtCore.SIGNAL("lastWindowClosed()"), self.app, QtCore.SLOT("quit()"))
self.app.exec_()
if tmp[0] == data:
raise SystemExit()
else:
return tmp[0]
def main(self): def main(self):
""" """
@ -32,6 +40,7 @@ class Toxygen(object):
""" """
app = QtGui.QApplication(sys.argv) app = QtGui.QApplication(sys.argv)
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png')) app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
self.app = app
# application color scheme # application color scheme
with open(curr_directory() + '/styles/style.qss') as fl: with open(curr_directory() + '/styles/style.qss') as fl:

View File

@ -145,10 +145,10 @@ class ProfileSettings(CenteredWidget):
self.not_match = QtGui.QLabel(self) self.not_match = QtGui.QLabel(self)
self.not_match.setGeometry(QtCore.QRect(340, 400, 300, 30)) self.not_match.setGeometry(QtCore.QRect(340, 400, 300, 30))
self.not_match.setVisible(False) self.not_match.setVisible(False)
self.not_match.setStyleSheet('QLabel { color: red; }') self.not_match.setStyleSheet('QLabel { color: #F70D1A; }')
self.warning = QtGui.QLabel(self) self.warning = QtGui.QLabel(self)
self.warning.setGeometry(QtCore.QRect(30, 490, 500, 30)) self.warning.setGeometry(QtCore.QRect(30, 490, 500, 30))
self.warning.setStyleSheet('QLabel { color: red; }') self.warning.setStyleSheet('QLabel { color: #F70D1A; }')
self.retranslateUi() self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
@ -225,10 +225,10 @@ class NetworkSettings(CenteredWidget):
def initUI(self): def initUI(self):
self.setObjectName("NetworkSettings") self.setObjectName("NetworkSettings")
self.resize(300, 300) self.resize(300, 330)
self.setMinimumSize(QtCore.QSize(300, 300)) self.setMinimumSize(QtCore.QSize(300, 330))
self.setMaximumSize(QtCore.QSize(300, 300)) self.setMaximumSize(QtCore.QSize(300, 330))
self.setBaseSize(QtCore.QSize(300, 300)) self.setBaseSize(QtCore.QSize(300, 330))
self.ipv = QtGui.QCheckBox(self) self.ipv = QtGui.QCheckBox(self)
self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22)) self.ipv.setGeometry(QtCore.QRect(20, 10, 97, 22))
self.ipv.setObjectName("ipv") self.ipv.setObjectName("ipv")
@ -260,6 +260,9 @@ class NetworkSettings(CenteredWidget):
self.proxyip.setText(settings['proxy_host']) self.proxyip.setText(settings['proxy_host'])
self.proxyport.setText(unicode(settings['proxy_port'])) self.proxyport.setText(unicode(settings['proxy_port']))
self.http.setChecked(settings['proxy_type'] == 1) self.http.setChecked(settings['proxy_type'] == 1)
self.warning = QtGui.QLabel(self)
self.warning.setGeometry(QtCore.QRect(40, 270, 200, 60))
self.warning.setStyleSheet('QLabel { color: #F70D1A; }')
self.retranslateUi() self.retranslateUi()
self.proxy.stateChanged.connect(lambda x: self.activate()) self.proxy.stateChanged.connect(lambda x: self.activate())
self.activate() self.activate()
@ -274,6 +277,8 @@ class NetworkSettings(CenteredWidget):
self.label_2.setText(QtGui.QApplication.translate("Form", "Port:", None, QtGui.QApplication.UnicodeUTF8)) self.label_2.setText(QtGui.QApplication.translate("Form", "Port:", None, QtGui.QApplication.UnicodeUTF8))
self.reconnect.setText(QtGui.QApplication.translate("NetworkSettings", "Restart TOX core", None, QtGui.QApplication.UnicodeUTF8)) self.reconnect.setText(QtGui.QApplication.translate("NetworkSettings", "Restart TOX core", None, QtGui.QApplication.UnicodeUTF8))
self.http.setText(QtGui.QApplication.translate("Form", "HTTP", None, QtGui.QApplication.UnicodeUTF8)) self.http.setText(QtGui.QApplication.translate("Form", "HTTP", None, QtGui.QApplication.UnicodeUTF8))
self.warning.setText(QtGui.QApplication.translate("Form", "WARNING:\nusing proxy with enabled UDP\ncan produce IP leak",
None, QtGui.QApplication.UnicodeUTF8))
def activate(self): def activate(self):
bl = self.proxy.isChecked() bl = self.proxy.isChecked()

View File

@ -1,36 +1,53 @@
from widgets import CenteredWidget from widgets import CenteredWidget
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
# TODO: add onclick
class PasswordScreen(CenteredWidget): class PasswordScreen(CenteredWidget):
def __init__(self, encrypt): def __init__(self, encrypt, data):
super(PasswordScreen, self).__init__() super(PasswordScreen, self).__init__()
self._encrypt = encrypt self._encrypt = encrypt
self._data = data
self.initUI() self.initUI()
def initUI(self): def initUI(self):
self.resize(360, 200) self.resize(360, 170)
self.setMinimumSize(QtCore.QSize(360, 200)) self.setMinimumSize(QtCore.QSize(360, 170))
self.setMaximumSize(QtCore.QSize(360, 200)) self.setMaximumSize(QtCore.QSize(360, 170))
self.enter_pass = QtGui.QLabel(self) self.enter_pass = QtGui.QLabel(self)
self.enter_pass.setGeometry(QtCore.QRect(30, 10, 300, 30)) self.enter_pass.setGeometry(QtCore.QRect(30, 10, 300, 30))
self.password = QtGui.QLineEdit(self) self.password = QtGui.QLineEdit(self)
self.password.setGeometry(QtCore.QRect(30, 80, 300, 30)) self.password.setGeometry(QtCore.QRect(30, 50, 300, 30))
self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password) self.password.setEchoMode(QtGui.QLineEdit.EchoMode.Password)
self.button = QtGui.QPushButton(self) self.button = QtGui.QPushButton(self)
self.button.setGeometry(QtCore.QRect(30, 120, 300, 30)) self.button.setGeometry(QtCore.QRect(30, 90, 300, 30))
self.button.setText('OK') self.button.setText('OK')
self.button.clicked.connect(self.button_click)
self.warning = QtGui.QLabel(self)
self.warning.setGeometry(QtCore.QRect(30, 130, 300, 30))
self.warning.setStyleSheet('QLabel { color: #F70D1A; }')
self.warning.setVisible(False)
self.retranslateUi() self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self) QtCore.QMetaObject.connectSlotsByName(self)
def button_click(self):
if self.password.text():
try:
self._encrypt.set_password(self.password.text())
new_data = self._encrypt.pass_decrypt(self._data[0])
except RuntimeError:
self.warning.setVisible(True)
else:
self._data[0] = new_data
self.close()
def retranslateUi(self): def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("pass", "Enter password", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle(QtGui.QApplication.translate("pass", "Enter password", None, QtGui.QApplication.UnicodeUTF8))
self.enter_pass.setText(QtGui.QApplication.translate("pass", "Password:", None, QtGui.QApplication.UnicodeUTF8)) self.enter_pass.setText(QtGui.QApplication.translate("pass", "Password:", None, QtGui.QApplication.UnicodeUTF8))
self.warning.setText(QtGui.QApplication.translate("pass", "Incorrect password", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -4,6 +4,7 @@ import os
import locale import locale
from util import Singleton, curr_directory, log from util import Singleton, curr_directory, log
import pyaudio import pyaudio
from toxencryptsave import LibToxEncryptSave
class Settings(Singleton, dict): class Settings(Singleton, dict):
@ -145,7 +146,6 @@ class Settings(Singleton, dict):
return os.getenv('APPDATA') + '/Tox/' return os.getenv('APPDATA') + '/Tox/'
# TODO: encrypted profiles support
class ProfileHelper(Singleton): class ProfileHelper(Singleton):
""" """
Class with methods for search, load and save profiles Class with methods for search, load and save profiles
@ -171,6 +171,9 @@ class ProfileHelper(Singleton):
return self._directory return self._directory
def save_profile(self, data): def save_profile(self, data):
inst = LibToxEncryptSave.get_instance()
if inst.has_password():
data = inst.pass_encrypt(data)
with open(self._path, 'wb') as fl: with open(self._path, 'wb') as fl:
fl.write(data) fl.write(data)
print 'Profile saved successfully' print 'Profile saved successfully'