From 5955b267cdb6e82c57bee74a66ba8fa3d5308c60 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 6 Nov 2013 11:15:34 -0200 Subject: Initializes mail service with the user id. This will be used to properly obtain the private key that now is a property. It will also be needed for the imap authentication. --- src/leap/bitmask/services/mail/conductor.py | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/mail/conductor.py b/src/leap/bitmask/services/mail/conductor.py index c294381b..4d34a13b 100644 --- a/src/leap/bitmask/services/mail/conductor.py +++ b/src/leap/bitmask/services/mail/conductor.py @@ -81,16 +81,12 @@ class IMAPControl(object): "We need a non-null keymanager for initializing imap " "service") - if self.imap_service is None: - # first time. - self.imap_service, \ - self.imap_port, \ + self.imap_service, self.imap_port, \ self.imap_factory = imap.start_imap_service( self._soledad, - self._keymanager) - else: - # we have the fetcher. just start it. - self.imap_service.start_loop() + self._keymanager, + userid=self.userid) + self.imap_service.start_loop() def stop_imap_service(self): """ @@ -339,11 +335,25 @@ class MailConductor(IMAPControl, SMTPControl): SMTPControl.__init__(self) self._soledad = soledad self._keymanager = keymanager - self._mail_machine = None - self._mail_connection = mail_connection.MailConnection() + self.userid = None + + @property + def userid(self): + return self._userid + + @userid.setter + def _userid(self, userid): + """ + Sets the user id this conductor is configured for. + + :param userid: the user id, in the form "user@provider" + :type userid: str + """ + self._userid = userid + def start_mail_machine(self, **kwargs): """ Starts mail machine. @@ -354,15 +364,10 @@ class MailConductor(IMAPControl, SMTPControl): # we have instantiated the connections while building the composite # machines, and we have to use the qtsigs instantiated there. - # XXX we could probably use a proxy here too to make the thing - # transparent. self.set_imap_connection(imap.conn) self.set_smtp_connection(smtp.conn) self._mail_machine = mail - # XXX ------------------- - # need to keep a reference? - #self._mail_events = mail.events self._mail_machine.start() self._imap_machine = imap -- cgit v1.2.3 From 9674b93f9d6fbe25e10330a6f807e5b7196c01b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Wed, 6 Nov 2013 11:54:03 -0300 Subject: Reject sender if it's not the logged in user --- src/leap/bitmask/services/mail/conductor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/mail/conductor.py b/src/leap/bitmask/services/mail/conductor.py index 4d34a13b..6dcf0c6f 100644 --- a/src/leap/bitmask/services/mail/conductor.py +++ b/src/leap/bitmask/services/mail/conductor.py @@ -200,6 +200,7 @@ class SMTPControl(object): from leap.mail.smtp import setup_smtp_relay self._smtp_service, self._smtp_port = setup_smtp_relay( port=2013, + userid=self.userid, keymanager=self._keymanager, smtp_host=host, smtp_port=port, @@ -345,7 +346,7 @@ class MailConductor(IMAPControl, SMTPControl): return self._userid @userid.setter - def _userid(self, userid): + def userid(self, userid): """ Sets the user id this conductor is configured for. -- cgit v1.2.3 From 540734c3aaffcdcd9140f0f6f723a7fac4ab18f0 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 8 Nov 2013 16:04:19 -0300 Subject: Use module attributes to store services strings. --- src/leap/bitmask/services/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/__init__.py b/src/leap/bitmask/services/__init__.py index e62277b6..ba12ba4e 100644 --- a/src/leap/bitmask/services/__init__.py +++ b/src/leap/bitmask/services/__init__.py @@ -37,7 +37,9 @@ from leap.common.files import get_mtime logger = logging.getLogger(__name__) -DEPLOYED = ["openvpn", "mx"] +EIP_SERVICE = u"openvpn" +MX_SERVICE = u"mx" +DEPLOYED = [EIP_SERVICE, MX_SERVICE] def get_service_display_name(service): -- cgit v1.2.3 From 59868c95c23e825544b2c986bf7fe6c15538bbe5 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 7 Nov 2013 17:09:15 -0200 Subject: Fix call to smtp gateway. --- src/leap/bitmask/services/mail/conductor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/mail/conductor.py b/src/leap/bitmask/services/mail/conductor.py index 6dcf0c6f..a9621b13 100644 --- a/src/leap/bitmask/services/mail/conductor.py +++ b/src/leap/bitmask/services/mail/conductor.py @@ -197,8 +197,8 @@ class SMTPControl(object): # TODO remove hard-coded port and let leap.mail set # the specific default. self.smtp_connection.qtsigs.connecting_signal.emit() - from leap.mail.smtp import setup_smtp_relay - self._smtp_service, self._smtp_port = setup_smtp_relay( + from leap.mail.smtp import setup_smtp_gateway + self._smtp_service, self._smtp_port = setup_smtp_gateway( port=2013, userid=self.userid, keymanager=self._keymanager, -- cgit v1.2.3 From 02a72c675107f9d324184265e414600c69763d7a Mon Sep 17 00:00:00 2001 From: drebs Date: Mon, 11 Nov 2013 14:40:59 -0200 Subject: Send user's key to nickserver whenever the keymanager is initialized. --- src/leap/bitmask/services/soledad/soledadbootstrapper.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index 54ef67eb..ce8bf813 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -367,6 +367,8 @@ class SoledadBootstrapper(AbstractBootstrapper): api_version=self._provider_config.get_api_version(), uid=srp_auth.get_uid(), gpgbinary=self._get_gpg_bin_path()) + # make sure key is in server + self._keymanager.send_key(openpgp.OpenPGPKey) def _gen_key(self, _): """ @@ -393,7 +395,7 @@ class SoledadBootstrapper(AbstractBootstrapper): try: self._keymanager.gen_key(openpgp.OpenPGPKey) except Exception as exc: - logger.error("error while generating key!") + logger.error("Error while generating key!") logger.exception(exc) raise @@ -401,7 +403,7 @@ class SoledadBootstrapper(AbstractBootstrapper): try: self._keymanager.send_key(openpgp.OpenPGPKey) except Exception as exc: - logger.error("error while sending key!") + logger.error("Error while sending key!") logger.exception(exc) raise -- cgit v1.2.3 From 1fb82f0ad4a2a397e4b938748e58a64d057599e4 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 12 Nov 2013 13:39:26 -0200 Subject: deferToThread initial soledad sync --- src/leap/bitmask/services/soledad/soledadbootstrapper.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index 54ef67eb..c672c893 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -28,6 +28,8 @@ from PySide import QtCore from u1db import errors as u1db_errors from zope.proxy import sameProxiedObjects +from twisted.internet.threads import deferToThread + from leap.bitmask.config import flags from leap.bitmask.config.providerconfig import ProviderConfig from leap.bitmask.crypto.srpauth import SRPAuth @@ -194,7 +196,12 @@ class SoledadBootstrapper(AbstractBootstrapper): leap_assert(not sameProxiedObjects(self._soledad, None), "Null soledad, error while initializing") + self.deferred = deferToThread(self._do_soledad_sync) + def _do_soledad_sync(self): + """ + Does several retries to get an initial soledad sync. + """ # and now, let's sync sync_tries = self.MAX_SYNC_RETRIES while sync_tries > 0: -- cgit v1.2.3 From 19df4a679664e76874e970813599c13c94dfd745 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 12 Nov 2013 23:28:17 -0200 Subject: re-raise the exceptions on init as expected --- src/leap/bitmask/services/mail/conductor.py | 2 +- src/leap/bitmask/services/soledad/soledadbootstrapper.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/mail/conductor.py b/src/leap/bitmask/services/mail/conductor.py index a9621b13..addf9bef 100644 --- a/src/leap/bitmask/services/mail/conductor.py +++ b/src/leap/bitmask/services/mail/conductor.py @@ -98,6 +98,7 @@ class IMAPControl(object): logger.debug('Stopping imap service.') # Stop the loop call in the fetcher self.imap_service.stop() + self.imap_service = None # Stop listening on the IMAP port self.imap_port.stopListening() # Stop the protocol @@ -107,7 +108,6 @@ class IMAPControl(object): """ Fetches incoming mail. """ - # TODO have a mutex over fetch operation. if self.imap_service: logger.debug('Client connected, fetching mail...') self.imap_service.fetch() diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index c672c893..b046d279 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -207,10 +207,6 @@ class SoledadBootstrapper(AbstractBootstrapper): while sync_tries > 0: try: self._try_soledad_sync() - - # at this point, sometimes the client - # gets stuck and does not progress to - # the _gen_key step. XXX investigate. logger.debug("Soledad has been synced.") # so long, and thanks for all the fish return @@ -266,26 +262,32 @@ class SoledadBootstrapper(AbstractBootstrapper): except socket.timeout: logger.debug("SOLEDAD initialization TIMED OUT...") self.soledad_timeout.emit() + raise except socket.error as exc: logger.warning("Socket error while initializing soledad") self.soledad_timeout.emit() + raise except BootstrapSequenceError as exc: logger.warning("Error while initializing soledad") self.soledad_timeout.emit() + raise # unrecoverable except u1db_errors.Unauthorized: logger.error("Error while initializing soledad " "(unauthorized).") self.soledad_failed.emit() + raise except u1db_errors.HTTPError as exc: logger.exception("Error whie initializing soledad " "(HTTPError)") self.soledad_failed.emit() + raise except Exception as exc: logger.exception("Unhandled error while initializating " "soledad: %r" % (exc,)) self.soledad_failed.emit() + raise def _try_soledad_sync(self): """ @@ -299,9 +301,8 @@ class SoledadBootstrapper(AbstractBootstrapper): logger.error("%r" % (exc,)) raise SoledadSyncError("Failed to sync soledad") except Exception as exc: - logger.exception("Unhandled error while syncing" + logger.exception("Unhandled error while syncing " "soledad: %r" % (exc,)) - self.soledad_failed.emit() raise SoledadSyncError("Failed to sync soledad") def _download_config(self): -- cgit v1.2.3 From 223d17f74f59121875d2eb42c3a4e4d638ae2f08 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 13 Nov 2013 16:42:15 -0200 Subject: do not raise if error while syncing --- .../services/soledad/soledadbootstrapper.py | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/leap/bitmask/services') diff --git a/src/leap/bitmask/services/soledad/soledadbootstrapper.py b/src/leap/bitmask/services/soledad/soledadbootstrapper.py index 70318ab8..e8c7e9ce 100644 --- a/src/leap/bitmask/services/soledad/soledadbootstrapper.py +++ b/src/leap/bitmask/services/soledad/soledadbootstrapper.py @@ -364,19 +364,32 @@ class SoledadBootstrapper(AbstractBootstrapper): """ srp_auth = self.srpauth logger.debug('initializing keymanager...') - self._keymanager = KeyManager( - address, - "https://nicknym.%s:6425" % (self._provider_config.get_domain(),), - self._soledad, - #token=srp_auth.get_token(), # TODO: enable token usage - session_id=srp_auth.get_session_id(), - ca_cert_path=self._provider_config.get_ca_cert_path(), - api_uri=self._provider_config.get_api_uri(), - api_version=self._provider_config.get_api_version(), - uid=srp_auth.get_uid(), - gpgbinary=self._get_gpg_bin_path()) + try: + self._keymanager = KeyManager( + address, + "https://nicknym.%s:6425" % ( + self._provider_config.get_domain(),), + self._soledad, + #token=srp_auth.get_token(), # TODO: enable token usage + session_id=srp_auth.get_session_id(), + ca_cert_path=self._provider_config.get_ca_cert_path(), + api_uri=self._provider_config.get_api_uri(), + api_version=self._provider_config.get_api_version(), + uid=srp_auth.get_uid(), + gpgbinary=self._get_gpg_bin_path()) + except Exception as exc: + logger.exception(exc) + raise + + logger.debug('sending key to server...') + # make sure key is in server - self._keymanager.send_key(openpgp.OpenPGPKey) + try: + self._keymanager.send_key(openpgp.OpenPGPKey) + except Exception as exc: + logger.error("Error sending key to server.") + logger.exception(exc) + # but we do not raise def _gen_key(self, _): """ -- cgit v1.2.3