summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/bonafide
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/bonafide')
-rw-r--r--src/leap/bitmask/bonafide/_protocol.py17
-rw-r--r--src/leap/bitmask/bonafide/config.py28
-rw-r--r--src/leap/bitmask/bonafide/service.py9
-rw-r--r--src/leap/bitmask/bonafide/session.py11
4 files changed, 36 insertions, 29 deletions
diff --git a/src/leap/bitmask/bonafide/_protocol.py b/src/leap/bitmask/bonafide/_protocol.py
index 1112550..622086f 100644
--- a/src/leap/bitmask/bonafide/_protocol.py
+++ b/src/leap/bitmask/bonafide/_protocol.py
@@ -1,4 +1,4 @@
-# -*- coding: utf-8 -*-
+ # -*- coding: utf-8 -*-
# _protocol.py
# Copyright (C) 2014-2015 LEAP
#
@@ -28,12 +28,15 @@ from leap.common.config import get_path_prefix
from twisted.cred.credentials import UsernamePassword
from twisted.internet.defer import fail
-from twisted.python import log
+from twisted.logger import Logger
# TODO [ ] enable-disable services
# TODO [ ] read provider info
+logger = Logger()
+
+
COMMANDS = 'signup', 'authenticate', 'logout', 'stats'
_preffix = get_path_prefix()
@@ -78,7 +81,7 @@ class BonafideProtocol(object):
# Service public methods
def do_signup(self, full_id, password, invite=None, autoconf=False):
- log.msg('SIGNUP for %s' % full_id)
+ logger.debug('SIGNUP for %s' % full_id)
_, provider_id = config.get_username_and_provider(full_id)
provider = config.Provider(provider_id, autoconf=autoconf)
@@ -125,7 +128,7 @@ class BonafideProtocol(object):
# TODO -- turn this into JSON response
return str(_session.token), str(_session.uuid)
- log.msg('AUTH for %s' % full_id)
+ logger.debug('AUTH for %s' % full_id)
# XXX get deferred?
session = self._get_session(provider, full_id, password)
@@ -136,7 +139,7 @@ class BonafideProtocol(object):
def do_logout(self, full_id):
# XXX use the AVATAR here
- log.msg('LOGOUT for %s' % full_id)
+ logger.debug('LOGOUT for %s' % full_id)
if (full_id not in self._sessions or
not self._sessions[full_id].is_authenticated):
return fail(RuntimeError("There is no session for such user"))
@@ -155,7 +158,7 @@ class BonafideProtocol(object):
return users
def do_change_password(self, full_id, current_password, new_password):
- log.msg('Change password for %s' % full_id)
+ logger.debug('change password for %s' % full_id)
if (full_id not in self._sessions or
not self._sessions[full_id].is_authenticated):
return fail(RuntimeError("There is no session for such user"))
@@ -194,7 +197,7 @@ class BonafideProtocol(object):
pass
def do_stats(self):
- log.msg('Calculating Bonafide Service STATS')
+ logger.debug('calculating Bonafide Service STATS')
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
return {'sessions': len(self._sessions),
'mem': '%s KB' % (mem / 1024)}
diff --git a/src/leap/bitmask/bonafide/config.py b/src/leap/bitmask/bonafide/config.py
index e4e2bf4..bf16d30 100644
--- a/src/leap/bitmask/bonafide/config.py
+++ b/src/leap/bitmask/bonafide/config.py
@@ -28,7 +28,7 @@ from urlparse import urlparse
from twisted.internet import defer, reactor
from twisted.internet.ssl import ClientContextFactory
-from twisted.python import log
+from twisted.logger import Logger
from twisted.web.client import Agent, downloadPage
from leap.bitmask.bonafide._http import httpRequest
@@ -38,7 +38,8 @@ from leap.bitmask.bonafide.errors import NotConfiguredError, NetworkError
from leap.common.check import leap_assert
from leap.common.config import get_path_prefix as common_get_path_prefix
from leap.common.files import mkdir_p
-# check_and_fix_urw_only, get_mtime
+
+logger = Logger()
APPNAME = "bonafide"
@@ -189,14 +190,15 @@ class Provider(object):
if not is_configured:
if autoconf:
- log.msg('provider %s not configured: downloading files...' %
- domain)
+ logger.debug(
+ 'provider %s not configured: downloading files...' %
+ domain)
self.bootstrap()
else:
raise NotConfiguredError("Provider %s is not configured"
% (domain,))
else:
- log.msg('Provider already initialized')
+ logger.debug('provider already initialized')
self.first_bootstrap[self._domain] = defer.succeed(
'already_initialized')
self.ongoing_bootstrap[self._domain] = defer.succeed(
@@ -233,10 +235,10 @@ class Provider(object):
def bootstrap(self):
domain = self._domain
- log.msg("Bootstrapping provider %s" % domain)
+ logger.debug("bootstrapping provider %s" % domain)
ongoing = self.ongoing_bootstrap.get(domain)
if ongoing:
- log.msg('already bootstrapping this provider...')
+ logger.debug('already bootstrapping this provider...')
return
self.first_bootstrap[self._domain] = defer.Deferred()
@@ -341,7 +343,7 @@ class Provider(object):
# See: # https://leap.se/code/issues/7906
def further_bootstrap_needs_auth(ignored):
- log.err('cannot download services config yet, need auth')
+ logger.warning('cannot download services config yet, need auth')
pending_deferred = defer.Deferred()
self.stuck_bootstrap[self._domain] = pending_deferred
return pending_deferred
@@ -364,8 +366,8 @@ class Provider(object):
def workaround_for_config_fetch(failure):
# FIXME --- configs.json raises 500, see #7914.
# This is a workaround until that's fixed.
- log.err(failure)
- log.msg(
+ logger.error(failure)
+ logger.debug(
"COULD NOT VERIFY CONFIGS.JSON, WORKAROUND: DIRECT DOWNLOAD")
if 'mx' in self._provider_config.services:
@@ -394,7 +396,7 @@ class Provider(object):
if stuck:
d = self._get_config_for_all_services(session)
d.addCallback(lambda _: stuck.callback('continue!'))
- d.addErrback(log.err)
+ d.addErrback(logger.err)
return d
if not self.has_fetched_services_config():
@@ -479,7 +481,7 @@ class Provider(object):
def _load_provider_json(self):
path = self._get_provider_json_path()
if not is_file(path):
- log.msg("Cannot LOAD provider config path %s" % path)
+ logger.debug("cannot LOAD provider config path %s" % path)
return
with open(path, 'r') as config:
@@ -517,7 +519,7 @@ class Provider(object):
return services_dict
def _fetch_provider_configs_unauthenticated(self, uri, path):
- log.msg('Downloading config for %s...' % uri)
+ logger.info('downloading config for %s...' % uri)
d = downloadPage(uri, path, method='GET')
return d
diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py
index 4e25172..0cd1053 100644
--- a/src/leap/bitmask/bonafide/service.py
+++ b/src/leap/bitmask/bonafide/service.py
@@ -26,9 +26,10 @@ from leap.common.service_hooks import HookableService
from leap.bitmask.bonafide._protocol import BonafideProtocol
from twisted.internet import defer
-from twisted.python import log
+from twisted.logger import Logger
+logger = Logger()
_preffix = get_path_prefix()
@@ -46,7 +47,7 @@ class BonafideService(HookableService):
self._active_user = None
def startService(self):
- log.msg('Starting Bonafide Service')
+ logger.debug('starting Bonafide Service')
super(BonafideService, self).startService()
# Commands
@@ -59,8 +60,8 @@ class BonafideService(HookableService):
def notify_bonafide_auth(result):
if not result:
- msg = "Authentication hook did not return anything"
- log.msg(msg)
+ msg = "authentication hook did not return anything"
+ logger.debug(msg)
raise RuntimeError(msg)
token, uuid = result
diff --git a/src/leap/bitmask/bonafide/session.py b/src/leap/bitmask/bonafide/session.py
index 213e773..5a743e9 100644
--- a/src/leap/bitmask/bonafide/session.py
+++ b/src/leap/bitmask/bonafide/session.py
@@ -18,12 +18,14 @@
LEAP Session management.
"""
from twisted.internet import defer, reactor
-from twisted.python import log
+from twisted.logger import Logger
from leap.bitmask.bonafide import _srp
from leap.bitmask.bonafide import provider
from leap.bitmask.bonafide._http import httpRequest, cookieAgentFactory
+logger = Logger()
+
OK = 'ok'
@@ -88,7 +90,7 @@ class Session(object):
def authenticate(self):
uri = self._api.get_handshake_uri()
met = self._api.get_handshake_method()
- log.msg("%s to %s" % (met, uri))
+ logger.debug("%s to %s" % (met, uri))
params = self._srp_auth.get_handshake_params()
handshake = yield self._request(self._agent, uri, values=params,
@@ -98,7 +100,7 @@ class Session(object):
uri = self._api.get_authenticate_uri(login=self.username)
met = self._api.get_authenticate_method()
- log.msg("%s to %s" % (met, uri))
+ logger.debug("%s to %s" % (met, uri))
params = self._srp_auth.get_authentication_params()
auth = yield self._request(self._agent, uri, values=params,
@@ -215,8 +217,7 @@ if __name__ == "__main__":
reactor.stop()
def auth_eb(failure):
- print "[ERROR!]", failure.getErrorMessage()
- log.err(failure)
+ logger.error(failure)
d = session.authenticate()
d.addCallback(print_result)