ui: Expose key exports on the dbus API.

This commit is contained in:
Damir Jelić 2019-04-18 15:52:21 +02:00
parent 8f57e42c2c
commit 3c09dbc80a
2 changed files with 51 additions and 6 deletions

View File

@ -29,7 +29,9 @@ from pantalaimon.ui import (
glib_loop, glib_loop,
shutdown_glib_loop, shutdown_glib_loop,
DeviceVerifyMessage, DeviceVerifyMessage,
DeviceUnverifyMessage DeviceUnverifyMessage,
ExportKeysMessage,
ImportKeysMessage
) )
@ -142,6 +144,25 @@ class ProxyDaemon:
else: else:
self._unverify_device(client, device) self._unverify_device(client, device)
elif isinstance(message, ExportKeysMessage):
client = self.pan_clients.get(message.pan_user, None)
if not client:
return
path = os.path.abspath(message.file_path)
logger.info(f"Exporting keys to {path}")
try:
client.export_keys(path, message.passphrase)
except OSError as e:
logger.warn(f"Error exporint keys for {client.user_id} to "
f"{path} {e}")
pass
elif isinstance(message, ImportKeysMessage):
pass
def get_access_token(self, request): def get_access_token(self, request):
# type: (aiohttp.web.BaseRequest) -> str # type: (aiohttp.web.BaseRequest) -> str
"""Extract the access token from the request. """Extract the access token from the request.

View File

@ -30,6 +30,23 @@ class DevicesMessage(Message):
devices = attr.ib() devices = attr.ib()
@attr.s
class _KeysOperation(Message):
pan_user = attr.ib()
file_path = attr.ib()
passphrase = attr.ib()
@attr.s
class ImportKeysMessage(_KeysOperation):
pass
@attr.s
class ExportKeysMessage(_KeysOperation):
pass
@attr.s @attr.s
class _VerificationMessage(Message): class _VerificationMessage(Message):
pan_user = attr.ib() pan_user = attr.ib()
@ -111,9 +128,10 @@ class Devices(dbus.service.Object):
class Control(dbus.service.Object): class Control(dbus.service.Object):
def __init__(self, bus_name, user_list=None): def __init__(self, bus_name, queue, user_list=None):
super().__init__(bus_name, "/org/pantalaimon/Control") super().__init__(bus_name, "/org/pantalaimon/Control")
self.users = user_list self.users = user_list
self.queue = queue
@dbus.service.method("org.pantalaimon.control.list_users", @dbus.service.method("org.pantalaimon.control.list_users",
out_signature="a(ss)") out_signature="a(ss)")
@ -121,8 +139,15 @@ class Control(dbus.service.Object):
return self.users return self.users
@dbus.service.method("org.pantalaimon.control.export_keys", @dbus.service.method("org.pantalaimon.control.export_keys",
in_signature="ss") in_signature="sss")
def export_keys(self, user, filepath): def export_keys(self, pan_user, filepath, passphrase):
message = ExportKeysMessage(
pan_user,
filepath,
passphrase
)
self.queue.put(message)
return return
@ -138,8 +163,7 @@ def glib_loop(receive_queue, send_queue, data_dir):
users = store.load_all_users() users = store.load_all_users()
devices = store.load_all_devices() devices = store.load_all_devices()
# TODO update bus data if the asyncio thread tells us so. Control(bus_name, send_queue, users)
Control(bus_name, users)
device_bus = Devices(bus_name, send_queue, devices) device_bus = Devices(bus_name, send_queue, devices)
def message_callback(): def message_callback():