def get_db_paths(uuid): """ Return the secrets and local db paths needed for soledad initialization :param uuid: uuid for user :type uuid: str :return: a tuple with secrets, local_db paths :rtype: tuple """ prefix = os.path.join(get_path_prefix(), "leap", "soledad") secrets = "%s/%s.secret" % (prefix, uuid) local_db = "%s/%s.db" % (prefix, uuid) # We remove an empty file if found to avoid complains # about the db not being properly initialized if is_file(local_db) and is_empty_file(local_db): try: os.remove(local_db) except OSError: logger.warning( "Could not remove empty file %s" % local_db) return secrets, local_db
def _download_config_and_cert(self): """ Downloads the SMTP config and cert for the given provider. """ leap_assert(self._provider_config, "We need a provider configuration!") logger.debug("Downloading SMTP config for %s" % (self._provider_config.get_domain(),)) download_service_config( self._provider_config, self._smtp_config, self._session, self._download_if_needed) hosts = self._smtp_config.get_hosts() if len(hosts) == 0: raise NoSMTPHosts() # TODO handle more than one host and define how to choose hostname = hosts.keys()[0] logger.debug("Using hostname %s for SMTP" % (hostname,)) client_cert_path = self._smtp_config.get_client_cert_path( self._userid, self._provider_config, about_to_download=True) if not is_file(client_cert_path): # For re-download if something is wrong with the cert self._download_if_needed = ( self._download_if_needed and not leap_certs.should_redownload(client_cert_path)) if self._download_if_needed and os.path.isfile(client_cert_path): check_and_fix_urw_only(client_cert_path) return try: download_client_cert(self._provider_config, client_cert_path, self._session, kind="smtp") except HTTPError as exc: if exc.message.startswith('403 Client Error'): logger.debug( 'Auth problem downloading smtp certificate... ' 'It might be a provider problem, will try ' 'fetching from vpn pool') warnings.warn( 'Compatibility hack for platform 0.7 not fully ' 'supporting smtp certificates. Will be deprecated in ' 'bitmask 0.10') download_client_cert(self._provider_config, client_cert_path, self._session, kind="vpn") else: raise
def _download_config_and_cert(self): """ Downloads the SMTP config and cert for the given provider. """ leap_assert(self._provider_config, "We need a provider configuration!") logger.debug("Downloading SMTP config for %s" % (self._provider_config.get_domain(), )) download_service_config(self._provider_config, self._smtp_config, self._session, self._download_if_needed) hosts = self._smtp_config.get_hosts() if len(hosts) == 0: raise NoSMTPHosts() # TODO handle more than one host and define how to choose hostname = hosts.keys()[0] logger.debug("Using hostname %s for SMTP" % (hostname, )) client_cert_path = self._smtp_config.get_client_cert_path( self._userid, self._provider_config, about_to_download=True) if not is_file(client_cert_path): # For re-download if something is wrong with the cert self._download_if_needed = ( self._download_if_needed and not leap_certs.should_redownload(client_cert_path)) if self._download_if_needed and os.path.isfile(client_cert_path): check_and_fix_urw_only(client_cert_path) return try: download_client_cert(self._provider_config, client_cert_path, self._session, kind="smtp") except HTTPError as exc: if exc.message.startswith('403 Client Error'): logger.debug( 'Auth problem downloading smtp certificate... ' 'It might be a provider problem, will try ' 'fetching from vpn pool') warnings.warn( 'Compatibility hack for platform 0.7 not fully ' 'supporting smtp certificates. Will be deprecated in ' 'bitmask 0.10') download_client_cert(self._provider_config, client_cert_path, self._session, kind="vpn") else: raise
def _download_config_and_cert(self): """ Downloads the SMTP config and cert for the given provider. """ leap_assert(self._provider_config, "We need a provider configuration!") logger.debug("Downloading SMTP config for %s" % (self._provider_config.get_domain(),)) download_service_config( self._provider_config, self._smtp_config, self._session, self._download_if_needed) hosts = self._smtp_config.get_hosts() if len(hosts) == 0: raise NoSMTPHosts() # TODO handle more than one host and define how to choose hostname = hosts.keys()[0] logger.debug("Using hostname %s for SMTP" % (hostname,)) client_cert_path = self._smtp_config.get_client_cert_path( self._provider_config, about_to_download=True) if not is_file(client_cert_path): # For re-download if something is wrong with the cert self._download_if_needed = ( self._download_if_needed and not leap_certs.should_redownload(client_cert_path)) if self._download_if_needed and os.path.isfile(client_cert_path): check_and_fix_urw_only(client_cert_path) return download_client_cert(self._provider_config, client_cert_path, self._session)
def get_db_paths(uuid): """ Return the secrets and local db paths needed for soledad initialization :param uuid: uuid for user :type uuid: str :return: a tuple with secrets, local_db paths :rtype: tuple """ prefix = os.path.join(get_path_prefix(), "leap", "soledad") secrets = "%s/%s.secret" % (prefix, uuid) local_db = "%s/%s.db" % (prefix, uuid) # We remove an empty file if found to avoid complains # about the db not being properly initialized if is_file(local_db) and is_empty_file(local_db): try: os.remove(local_db) except OSError: logger.warning("Could not remove empty file %s" % local_db) return secrets, local_db
def check_smtp_config(self): """ Checks smtp config and tries to download smtp client cert if needed. Currently called when smtp_bootstrapped_stage has successfuly finished. """ logger.debug("Checking SMTP config...") leap_assert(self.smtp_bootstrapper._provider_config, "smtp bootstrapper does not have a provider_config") provider_config = self.smtp_bootstrapper._provider_config smtp_config = self.smtp_config hosts = smtp_config.get_hosts() # TODO handle more than one host and define how to choose if len(hosts) > 0: hostname = hosts.keys()[0] logger.debug("Using hostname %s for SMTP" % (hostname,)) host = hosts[hostname][self.IP_KEY].encode("utf-8") port = hosts[hostname][self.PORT_KEY] client_cert = smtp_config.get_client_cert_path( provider_config, about_to_download=True) # XXX change this logic! # check_config should be called from within start_service, # and not the other way around. if not is_file(client_cert): self.smtp_bootstrapper._download_client_certificates() if os.path.isfile(client_cert): self.start_smtp_service(host, port, client_cert) else: logger.warning("Tried to download email client " "certificate, but could not find any") else: logger.warning("No smtp hosts configured")
def _download_config_and_cert(self): """ Downloads the SMTP config and cert for the given provider. """ leap_assert(self._provider_config, "We need a provider configuration!") logger.debug("Downloading SMTP config for %s" % (self._provider_config.get_domain(), )) download_service_config(self._provider_config, self._smtp_config, self._session, self._download_if_needed) hosts = self._smtp_config.get_hosts() if len(hosts) == 0: raise NoSMTPHosts() # TODO handle more than one host and define how to choose hostname = hosts.keys()[0] logger.debug("Using hostname %s for SMTP" % (hostname, )) client_cert_path = self._smtp_config.get_client_cert_path( self._provider_config, about_to_download=True) if not is_file(client_cert_path): # For re-download if something is wrong with the cert self._download_if_needed = ( self._download_if_needed and not leap_certs.should_redownload(client_cert_path)) if self._download_if_needed and os.path.isfile(client_cert_path): check_and_fix_urw_only(client_cert_path) return download_client_cert(self._provider_config, client_cert_path, self._session)