diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 65ecf0e..4120571 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -29,7 +29,9 @@ from pantalaimon.ui import ( glib_loop, shutdown_glib_loop, DeviceVerifyMessage, - DeviceUnverifyMessage + DeviceUnverifyMessage, + ExportKeysMessage, + ImportKeysMessage ) @@ -142,6 +144,25 @@ class ProxyDaemon: else: 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): # type: (aiohttp.web.BaseRequest) -> str """Extract the access token from the request. diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index 2d848b5..ba0f923 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -30,6 +30,23 @@ class DevicesMessage(Message): 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 class _VerificationMessage(Message): pan_user = attr.ib() @@ -111,9 +128,10 @@ class Devices(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") self.users = user_list + self.queue = queue @dbus.service.method("org.pantalaimon.control.list_users", out_signature="a(ss)") @@ -121,8 +139,15 @@ class Control(dbus.service.Object): return self.users @dbus.service.method("org.pantalaimon.control.export_keys", - in_signature="ss") - def export_keys(self, user, filepath): + in_signature="sss") + def export_keys(self, pan_user, filepath, passphrase): + message = ExportKeysMessage( + pan_user, + filepath, + passphrase + ) + self.queue.put(message) + return @@ -138,8 +163,7 @@ def glib_loop(receive_queue, send_queue, data_dir): users = store.load_all_users() devices = store.load_all_devices() - # TODO update bus data if the asyncio thread tells us so. - Control(bus_name, users) + Control(bus_name, send_queue, users) device_bus = Devices(bus_name, send_queue, devices) def message_callback():