Unverified Commit 593803ed authored by meskio's avatar meskio
Browse files

[feat] add support for private keys into bitmask cli

parent f15673c6
......@@ -136,6 +136,8 @@ GENERAL COMMANDS:
parser = argparse.ArgumentParser(
description='Bitmask Keymanager management service',
prog='bitmask_cli keys')
parser.add_argument('--private', action='store_true',
help='Use private keys (by default uses public)')
parser.add_argument('--list', action='store_true',
help='List all known keys')
parser.add_argument('--export', action='store_true',
......@@ -366,6 +368,11 @@ def send_command(cli):
if subargs.address:
data.append(subargs.address)
if subargs.private:
data += ['private']
else:
data += ['public']
s = get_zmq_connection()
d = s.sendMsg(*data, timeout=60)
......
......@@ -153,22 +153,30 @@ class KeysCmd(SubCommand):
label = 'keys'
@register_method("[[str, str]]")
@register_method("[dict]")
def do_LIST(self, service, *parts, **kw):
private = False
if parts[-1] == 'private':
private = True
bonafide = kw['bonafide']
d = bonafide.do_get_active_user()
d.addCallback(service.do_list_keys)
d.addCallback(service.do_list_keys, private)
return d
@register_method('str')
@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]
private = False
if parts[-1] == 'private':
private = True
bonafide = kw['bonafide']
d = bonafide.do_get_active_user()
d.addCallback(service.do_export, address)
d.addCallback(service.do_export, address, private)
return d
@register_method('str')
......@@ -177,9 +185,13 @@ class KeysCmd(SubCommand):
return defer.fail("An email address is needed")
address = parts[2]
private = False
if parts[-1] == 'private':
private = True
bonafide = kw['bonafide']
d = bonafide.do_get_active_user()
d.addCallback(service.do_delete, address)
d.addCallback(service.do_delete, address, private)
return d
......
......@@ -346,22 +346,22 @@ class KeymanagerService(HookableService):
# commands
def do_list_keys(self, userid):
def do_list_keys(self, userid, private=False):
km = self._container.get_instance(userid)
d = km.get_all_keys()
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):
def do_export(self, userid, address, private=False):
km = self._container.get_instance(userid)
d = km.get_key(address, fetch_remote=False)
d = km.get_key(address, private=private, fetch_remote=False)
d.addCallback(lambda key: dict(key))
return d
@defer.inlineCallbacks
def do_delete(self, userid, address):
def do_delete(self, userid, address, private=False):
km = self._container.get_instance(userid)
key = yield km.get_key(address, fetch_remote=False)
key = yield km.get_key(address, private=private, fetch_remote=False)
km.delete_key(key)
defer.returnValue(key.fingerprint)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment