Unverified Commit eed534dc authored by meskio's avatar meskio
Browse files

[feat] implement key export

parent 34411693
......@@ -140,6 +140,8 @@ GENERAL COMMANDS:
help='List all known keys')
parser.add_argument('--export', action='store_true',
help='Export the given key')
parser.add_argument('address', nargs='?',
help='email address of the key')
args = parser.parse_args(sys.argv[2:])
self.subargs = args
......@@ -192,6 +194,27 @@ def do_print_result(stuff):
print Fore.RED + 'ERROR:' + '%s' % obj['error'] + Fore.RESET
def do_print_key(stuff):
obj = json.loads(stuff[0])
if obj['error']:
do_print_result(stuff)
return
key = obj['result']
print Fore.GREEN
print "Uids: " + ', '.join(key['uids'])
print "Fingerprint: " + key['fingerprint']
print "Length: " + str(key['length'])
print "Expiration: " + key['expiry_date']
print "Validation: " + key['validation']
print("Used: " + "sig:" + str(key['sign_used']) +
", encr:" + str(key['encr_used']))
print "Refresed: " + key['refreshed_at']
print Fore.RESET
print ""
print key['key_data']
def send_command(cli):
args = cli.args
......@@ -314,12 +337,16 @@ def send_command(cli):
elif subargs.export:
data += ['export']
cb = do_print_key
else:
error('Use bitmask_cli keys --help to see available subcommands',
stop=True)
return
if subargs.address:
data.append(subargs.address)
s = get_zmq_connection()
d = s.sendMsg(*data, timeout=60)
......
......@@ -162,8 +162,14 @@ class KeysCmd(SubCommand):
@register_method('str')
def do_EXPORT(self, service, *parts, **kw):
# TODO
return defer.succeed("")
if len(parts) < 3:
return defer.fail("An email address is needed")
address = parts[2]
bonafide = kw['bonafide']
d = bonafide.do_get_active_user()
d.addCallback(service.do_export, address)
return d
class CommandDispatcher(object):
......
......@@ -354,6 +354,12 @@ class KeymanagerService(HookableService):
(key.address, key.fingerprint) for key in keys])
return d
def do_export(self, userid, address):
km = self._container.get_instance(userid)
d = km.get_key(address, fetch_remote=False)
d.addCallback(lambda key: dict(key))
return d
class StandardMailService(service.MultiService, HookableService):
"""
......
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