From e4e5f35c3fc7ff02bc20a6ef7eaffae09f485061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Fri, 8 Mar 2013 14:24:05 -0300 Subject: Add keyring and username/password saving capabilities Also: - Fix translations in SRPAuth - Support non-ascii passwords - Make the server check if the characters are allowed, just check for easy passwords --- src/leap/crypto/srpauth.py | 4 +++- src/leap/gui/mainwindow.py | 33 +++++++++++++++++++++++++++++++-- src/leap/gui/wizard.py | 11 +++-------- 3 files changed, 37 insertions(+), 11 deletions(-) (limited to 'src/leap') diff --git a/src/leap/crypto/srpauth.py b/src/leap/crypto/srpauth.py index 8530b7da..2877efab 100644 --- a/src/leap/crypto/srpauth.py +++ b/src/leap/crypto/srpauth.py @@ -41,7 +41,7 @@ class SRPAuth(QtCore.QObject): SRPAuth singleton """ - class __impl(object): + class __impl(QtCore.QObject): """ Implementation of the SRPAuth interface """ @@ -57,6 +57,8 @@ class SRPAuth(QtCore.QObject): @param server: Server to which we will authenticate @type server: str """ + QtCore.QObject.__init__(self) + leap_assert(provider_config, "We need a provider config to authenticate") diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index d66ddbb5..68c73e4d 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -21,6 +21,7 @@ Main window for the leap client import os import logging import random +import keyring from PySide import QtCore, QtGui @@ -49,6 +50,9 @@ class MainWindow(QtGui.QMainWindow): GEOMETRY_KEY = "Geometry" WINDOWSTATE_KEY = "WindowState" + USER_KEY = "User" + + KEYRING_KEY = "leap_client" def __init__(self): QtGui.QMainWindow.__init__(self) @@ -183,6 +187,7 @@ class MainWindow(QtGui.QMainWindow): if self._wizard is None: self._wizard = Wizard(self._checker_thread) self._wizard.exec_() + self._wizard = None def _finish_init(self): self.ui.cmbProviders.addItems(self._configured_providers()) @@ -194,6 +199,17 @@ class MainWindow(QtGui.QMainWindow): self.ui.lnUser.setText(possible_username) self._focus_password() self._wizard = None + else: + settings = QtCore.QSettings() + saved_user = settings.value(self.USER_KEY, None) + + if saved_user is not None: + self.ui.lnUser.setText(saved_user) + self.ui.chkRemember.setChecked(True) + saved_password = keyring.get_password(self.KEYRING_KEY, + saved_user + .encode("utf8")) + self.ui.lnPassword.setText(saved_password.decode("utf8")) def _show_systray(self): """ @@ -442,6 +458,19 @@ class MainWindow(QtGui.QMainWindow): self._set_status(self.tr("Logging in...")) self._login_set_enabled(False) + if self.ui.chkRemember.isChecked(): + try: + keyring.set_password(self.KEYRING_KEY, + username.encode("utf8"), + password.encode("utf8")) + # Only save the username if it was saved correctly in + # the keyring + settings = QtCore.QSettings() + settings.setValue(self.USER_KEY, username) + except Exception as e: + logger.error("Problem saving data to keyring. %r" + % (e,)) + self._download_provider_config() def _provider_config_loaded(self, data): @@ -455,8 +484,8 @@ class MainWindow(QtGui.QMainWindow): leap_assert(self._provider_config, "We need a provider config!") if data[self._provider_bootstrapper.PASSED_KEY]: - username = self.ui.lnUser.text() - password = self.ui.lnPassword.text() + username = self.ui.lnUser.text().encode("utf8") + password = self.ui.lnPassword.text().encode("utf8") if self._srp_auth is None: self._srp_auth = SRPAuth(self._provider_config) diff --git a/src/leap/gui/wizard.py b/src/leap/gui/wizard.py index fa705645..72e791b3 100644 --- a/src/leap/gui/wizard.py +++ b/src/leap/gui/wizard.py @@ -148,13 +148,6 @@ class Wizard(QtGui.QWizard): """ message = None - try: - username.encode("ascii") - password.encode("ascii") - except: - message = self.tr(u"Refrain from using non " - u"ASCII characters like á, ñ, æ") - if message is not None and password != password2: message = self.tr("Passwords don't match") @@ -189,7 +182,9 @@ class Wizard(QtGui.QWizard): register.registration_finished.connect( self._registration_finished) self._checker_thread.add_checks( - [partial(register.register_user, username, password)]) + [partial(register.register_user, + username.encode("utf8"), + password.encode("utf8"))]) self._username = username self._set_register_status(self.tr("Starting registration...")) else: -- cgit v1.2.3