From 48f94851d20762206e9ee7f14e21e864f10e87b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 17 May 2019 14:57:36 +0200 Subject: [PATCH] ui: Allow devices to be blackliksted and unblacklisted. --- pantalaimon/daemon.py | 39 +++++++++++++++++++++++++-- pantalaimon/panctl.py | 46 ++++++++++++++++++++++++++++++++ pantalaimon/thread_messages.py | 10 +++++++ pantalaimon/ui.py | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 2 deletions(-) diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index 59b6645..7a630f3 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -112,7 +112,35 @@ class ProxyDaemon: await self.send_update_devcies() else: msg = (f"Device {device.id} of user " - f"{device.user_id} already unverified") + f"{device.user_id} already unverified.") + + logger.info(msg) + await self.send_response(message_id, client.user_id, "m.ok", msg) + + async def _blacklist_device(self, message_id, client, device): + ret = client.blacklist_device(device) + + if ret: + msg = (f"Device {device.id} of user " + f"{device.user_id} succesfully blacklisted.") + await self.send_update_devcies() + else: + msg = (f"Device {device.id} of user " + f"{device.user_id} already blacklisted.") + + logger.info(msg) + await self.send_response(message_id, client.user_id, "m.ok", msg) + + async def _unblacklist_device(self, message_id, client, device): + ret = client.unblacklist_device(device) + + if ret: + msg = (f"Device {device.id} of user " + f"{device.user_id} succesfully unblacklisted.") + await self.send_update_devcies() + else: + msg = (f"Device {device.id} of user " + f"{device.user_id} already unblacklisted.") logger.info(msg) await self.send_response(message_id, client.user_id, "m.ok", msg) @@ -131,7 +159,8 @@ class ProxyDaemon: if isinstance( message, - (DeviceVerifyMessage, DeviceUnverifyMessage, StartSasMessage) + (DeviceVerifyMessage, DeviceUnverifyMessage, StartSasMessage, + DeviceBlacklistMessage, DeviceUnblacklistMessage) ): device = client.device_store[message.user_id].get( @@ -155,6 +184,12 @@ class ProxyDaemon: await self._verify_device(message.message_id, client, device) elif isinstance(message, DeviceUnverifyMessage): await self._unverify_device(message.message_id, client, device) + elif isinstance(message, DeviceBlacklistMessage): + await self._blacklist_device(message.message_id, client, + device) + elif isinstance(message, DeviceUnblacklistMessage): + await self._unblacklist_device(message.message_id, client, + device) elif isinstance(message, StartSasMessage): await client.start_sas(message, device) diff --git a/pantalaimon/panctl.py b/pantalaimon/panctl.py index 118aacc..c4fccfb 100644 --- a/pantalaimon/panctl.py +++ b/pantalaimon/panctl.py @@ -75,6 +75,16 @@ class PanctlParser(): unverify.add_argument("user_id", type=str) unverify.add_argument("device_id", type=str) + blacklist = subparsers.add_parser("blacklist-device") + blacklist.add_argument("pan_user", type=str) + blacklist.add_argument("user_id", type=str) + blacklist.add_argument("device_id", type=str) + + unblacklist = subparsers.add_parser("unblacklist-device") + unblacklist.add_argument("pan_user", type=str) + unblacklist.add_argument("user_id", type=str) + unblacklist.add_argument("device_id", type=str) + import_keys = subparsers.add_parser("import-keys") import_keys.add_argument("pan_user", type=str) import_keys.add_argument("path", type=str) @@ -202,6 +212,8 @@ class PanCompleter(Completer): "cancel-verification", "verify-device", "unverify-device", + "blacklist-device", + "unblacklist-device", ]: return self.complete_verification(command, last_word, words) @@ -267,6 +279,8 @@ class PanCtl: "import-keys", "verify-device", "unverify-device", + "blacklist-device", + "unblacklist-device", "start-verification", "cancel-verification", "accept-verification", @@ -443,6 +457,38 @@ class PanCtl: elif command == "list-devices": self.list_devices(args) + elif command == "verify-device": + self.own_message_ids.append( + self.devices.Verify( + args.pan_user, + args.user_id, + args.device_id + )) + + elif command == "unverify-device": + self.own_message_ids.append( + self.devices.Unverify( + args.pan_user, + args.user_id, + args.device_id + )) + + elif command == "blacklist-device": + self.own_message_ids.append( + self.devices.Blacklist( + args.pan_user, + args.user_id, + args.device_id + )) + + elif command == "unblacklist-device": + self.own_message_ids.append( + self.devices.Unblacklist( + args.pan_user, + args.user_id, + args.device_id + )) + elif command == "start-verification": self.own_message_ids.append( self.devices.StartKeyVerification( diff --git a/pantalaimon/thread_messages.py b/pantalaimon/thread_messages.py index 3075712..75ec87e 100644 --- a/pantalaimon/thread_messages.py +++ b/pantalaimon/thread_messages.py @@ -60,6 +60,16 @@ class DeviceUnverifyMessage(_VerificationMessage): pass +@attr.s +class DeviceBlacklistMessage(_VerificationMessage): + pass + + +@attr.s +class DeviceUnblacklistMessage(_VerificationMessage): + pass + + @attr.s class SasMessage(_VerificationMessage): pass diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index 27f39bd..0fcbc7e 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -124,6 +124,34 @@ class Devices: + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -249,6 +277,26 @@ class Devices: self.queue.put(message) return message.message_id + def Blacklist(self, pan_user, user_id, device_id): + message = DeviceBlacklistMessage( + self.message_id, + pan_user, + user_id, + device_id + ) + self.queue.put(message) + return message.message_id + + def Unblacklist(self, pan_user, user_id, device_id): + message = DeviceUnblacklistMessage( + self.message_id, + pan_user, + user_id, + device_id + ) + self.queue.put(message) + return message.message_id + def StartKeyVerification(self, pan_user, user_id, device_id): message = StartSasMessage( self.message_id,