summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-07-18 15:43:35 +0200
committerKali Kaneko <kali@leap.se>2017-08-24 17:13:39 -0400
commit8cebf955ad71975a20275a780a67b31099759e3a (patch)
tree998562d9398e0aee9b7adb7cfbb28170b816c00a /src/leap
parent3b4508dff9dc1a681f3c96edcef4e43aa3da29a8 (diff)
[feat] add a mock mixnet_status call to the API
For now we say it will be mixed on every request if the mixnet is enabled. We might want a better mock in the future. - Resolves: #8972
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/bitmask/cli/mail.py21
-rw-r--r--src/leap/bitmask/core/configurable.py1
-rw-r--r--src/leap/bitmask/core/dispatcher.py11
-rw-r--r--src/leap/bitmask/core/mail_services.py11
-rw-r--r--src/leap/bitmask/core/service.py21
5 files changed, 52 insertions, 13 deletions
diff --git a/src/leap/bitmask/cli/mail.py b/src/leap/bitmask/cli/mail.py
index 1624606..21b93c2 100644
--- a/src/leap/bitmask/cli/mail.py
+++ b/src/leap/bitmask/cli/mail.py
@@ -20,8 +20,6 @@ Bitmask Command Line interface: mail
import argparse
import sys
-from colorama import Fore
-
from leap.bitmask.cli import command
@@ -58,3 +56,22 @@ SUBCOMMANDS:
self.data += ['status', uid]
return self._send(command.print_status)
+
+ def mixnet_status(self, raw_args):
+ parser = argparse.ArgumentParser(
+ description='Bitmask mixnet status',
+ prog='%s %s %s' % tuple(sys.argv[:3]))
+ parser.add_argument('-u', '--userid', default='',
+ help='uid to check the status of')
+ parser.add_argument('address', nargs=1,
+ help='the recipient address')
+ subargs = parser.parse_args(raw_args)
+
+ userid = None
+ if subargs.userid:
+ userid = subargs.userid
+ else:
+ userid = self.cfg.get('bonafide', 'active', default=None)
+ self.data += ['mixnet_status', userid, subargs.address[0]]
+
+ return self._send(command.default_dict_printer)
diff --git a/src/leap/bitmask/core/configurable.py b/src/leap/bitmask/core/configurable.py
index 726c541..262f030 100644
--- a/src/leap/bitmask/core/configurable.py
+++ b/src/leap/bitmask/core/configurable.py
@@ -51,6 +51,7 @@ zmq = True
web = True
onion = False
websockets = False
+mixnet = False
"""
__all__ = ["ConfigurableService", DEFAULT_BASEDIR, MissingConfigEntry]
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 7a2d48a..519ec9d 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -267,6 +267,17 @@ class MailCmd(SubCommand):
d = mail.get_token()
return d
+ @register_method('dict')
+ def do_MIXNET_STATUS(self, mail, *parts, **kw):
+ try:
+ userid = parts[2]
+ address = parts[3]
+ except IndexError:
+ raise DispatchError(
+ 'wrong number of arguments: expected 2')
+ d = mail.do_mixnet_status(userid, address)
+ return d
+
class WebUICmd(SubCommand):
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index 20d6a34..be84b3c 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -469,13 +469,14 @@ class StandardMailService(service.MultiService, HookableService):
# TODO factor out Mail Service to inside mail package.
- def __init__(self, basedir):
+ def __init__(self, basedir, mixnet_enabled=False):
self._basedir = basedir
self._soledad_sessions = {}
self._keymanager_sessions = {}
self._sendmail_opts = {}
self._service_tokens = {}
self._active_user = None
+ self._mixnet_enabled = mixnet_enabled
super(StandardMailService, self).__init__()
self.initializeChildrenServices()
@@ -603,6 +604,14 @@ class StandardMailService(service.MultiService, HookableService):
}
defer.returnValue(merge_status(childrenStatus))
+ def do_mixnet_status(self, userid, address):
+ # XXX: for now there is no support in the provider
+ # we'll mock it if it's enabled
+ status = 'disabled'
+ if self._mixnet_enabled:
+ status = 'ok'
+ return {'status': status}
+
def get_token(self):
active_user = self._active_user
if not active_user:
diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py
index 5b4f5f7..e823d82 100644
--- a/src/leap/bitmask/core/service.py
+++ b/src/leap/bitmask/core/service.py
@@ -83,9 +83,6 @@ class BitmaskBackend(configurable.ConfigurableService):
# top of the global app token, this should be removed.
self.tokens = {}
- def enabled(service):
- return self.get_config('services', service, False, boolean=True)
-
def with_manhole():
user = self.get_config('manhole', 'user', '')
passwd = self.get_config('manhole', 'passwd', '')
@@ -101,26 +98,29 @@ class BitmaskBackend(configurable.ConfigurableService):
on_start(self.init_bonafide)
on_start(self.init_sessions)
- if enabled('mail'):
+ if self._enabled('mail'):
on_start(self._init_mail_services)
- if enabled('vpn'):
+ if self._enabled('vpn'):
on_start(self._init_vpn)
- if enabled('zmq'):
+ if self._enabled('zmq'):
on_start(self._init_zmq)
- if enabled('web'):
- onion = enabled('onion')
+ if self._enabled('web'):
+ onion = self._enabled('onion')
on_start(self._init_web, onion=onion)
- if enabled('websockets'):
+ if self._enabled('websockets'):
on_start(self._init_websockets)
manholecfg = with_manhole()
if manholecfg:
on_start(self._init_manhole, manholecfg)
+ def _enabled(self, service):
+ return self.get_config('services', service, False, boolean=True)
+
def _touch_token_file(self):
path = os.path.join(self.basedir, 'authtoken')
with open(path, 'w') as f:
@@ -203,7 +203,8 @@ class BitmaskBackend(configurable.ConfigurableService):
def _init_mail(self):
service = mail_services.StandardMailService
- self._maybe_init_service('mail', service, self.basedir)
+ self._maybe_init_service('mail', service, self.basedir,
+ self._enabled('mixnet'))
def _init_vpn(self):
if HAS_VPN: