summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-02-06 19:38:58 +0100
committerRuben Pollan <meskio@sindominio.net>2017-02-09 18:35:54 +0100
commit374bb846b15596f99da77a4a7c9a348187774534 (patch)
treeb76b30ba3240b892817a0006d98523cf75c44199 /src/leap/bitmask/core
parent546190e59ba11fe109d933f4f22fed5398f86010 (diff)
[feat] add account based keymanagement API
- Resolves: #8755
Diffstat (limited to 'src/leap/bitmask/core')
-rw-r--r--src/leap/bitmask/core/dispatcher.py56
-rw-r--r--src/leap/bitmask/core/mail_services.py23
2 files changed, 55 insertions, 24 deletions
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 7c1cdbd4..2777d9a9 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -267,58 +267,74 @@ class KeysCmd(SubCommand):
@register_method("[dict]")
def do_LIST(self, service, *parts, **kw):
+ uid = parts[2]
+
private = False
if parts[-1] == 'private':
private = True
- bonafide = kw['bonafide']
- d = bonafide.do_get_active_user()
+ d = defer.succeed(uid)
+ if not uid:
+ d = self._get_active_user(kw['bonafide'])
d.addCallback(service.do_list_keys, private)
return d
@register_method('dict')
def do_EXPORT(self, service, *parts, **kw):
- if len(parts) < 3:
- return defer.fail("An email address is needed")
- address = parts[2]
+ if len(parts) < 4:
+ raise ValueError("An email address is needed")
+ uid = parts[2]
+ address = parts[3]
private = False
if parts[-1] == 'private':
private = True
- bonafide = kw['bonafide']
- d = bonafide.do_get_active_user()
+ d = defer.succeed(uid)
+ if not uid:
+ d = self._get_active_user(kw['bonafide'])
d.addCallback(service.do_export, address, private)
return d
@register_method('dict')
+ @defer.inlineCallbacks
def do_INSERT(self, service, *parts, **kw):
- if len(parts) < 5:
- return defer.fail("An email address is needed")
- address = parts[2]
- validation = parts[3]
- rawkey = parts[4]
-
- bonafide = kw['bonafide']
- d = bonafide.do_get_active_user()
+ if len(parts) < 6:
+ raise ValueError("An email address is needed")
+ uid = parts[2]
+ address = parts[3]
+ validation = parts[4]
+ rawkey = parts[5]
+
+ d = defer.succeed(uid)
+ if not uid:
+ d = self._get_active_user(kw['bonafide'])
d.addCallback(service.do_insert, address, rawkey, validation)
return d
@register_method('str')
+ @defer.inlineCallbacks
def do_DELETE(self, service, *parts, **kw):
- if len(parts) < 3:
- return defer.fail("An email address is needed")
- address = parts[2]
+ if len(parts) < 4:
+ raise ValueError("An email address is needed")
+ uid = parts[2]
+ address = parts[3]
private = False
if parts[-1] == 'private':
private = True
- bonafide = kw['bonafide']
- d = bonafide.do_get_active_user()
+ d = defer.succeed(uid)
+ if not uid:
+ d = self._get_active_user(kw['bonafide'])
d.addCallback(service.do_delete, address, private)
return d
+ def _get_active_user(self, bonafide):
+ d = bonafide.do_get_active_user()
+ d.addCallback(lambda active: active['user'])
+ return d
+
class EventsCmd(SubCommand):
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index 2842b5d8..b1bdea25 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -397,19 +397,31 @@ class KeymanagerService(HookableService):
# commands
def do_list_keys(self, userid, private=False):
- km = self._container.get_instance(userid['user'])
+ km = self._container.get_instance(userid)
+ if km is None:
+ return defer.fail(ValueError("User " + userid + " has no active "
+ "keymanager"))
+
d = km.get_all_keys(private=private)
d.addCallback(lambda keys: [dict(key) for key in keys])
return d
def do_export(self, userid, address, private=False):
- km = self._container.get_instance(userid['user'])
+ km = self._container.get_instance(userid)
+ if km is None:
+ return defer.fail(ValueError("User " + userid + " has no active "
+ "keymanager"))
+
d = km.get_key(address, private=private, fetch_remote=False)
d.addCallback(lambda key: dict(key))
return d
def do_insert(self, userid, address, rawkey, validation='Fingerprint'):
- km = self._container.get_instance(userid['user'])
+ km = self._container.get_instance(userid)
+ if km is None:
+ return defer.fail(ValueError("User " + userid + " has no active "
+ "keymanager"))
+
validation = ValidationLevels.get(validation)
d = km.put_raw_key(rawkey, address, validation=validation)
d.addCallback(lambda _: km.get_key(address, fetch_remote=False))
@@ -418,7 +430,10 @@ class KeymanagerService(HookableService):
@defer.inlineCallbacks
def do_delete(self, userid, address, private=False):
- km = self._container.get_instance(userid['user'])
+ km = self._container.get_instance(userid)
+ if km is None:
+ raise ValueError("User " + userid + " has no active keymanager")
+
key = yield km.get_key(address, private=private, fetch_remote=False)
km.delete_key(key)
defer.returnValue(key.fingerprint)