ui: Allow devices to be blackliksted and unblacklisted.

This commit is contained in:
Damir Jelić 2019-05-17 14:57:36 +02:00
parent 694903e8bd
commit 48f94851d2
4 changed files with 141 additions and 2 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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

View File

@ -124,6 +124,34 @@ class Devices:
<arg type='aa{ss}' name='devices' direction='out'/>
</method>
<method name='Verify'>
<arg type='s' name='pan_user' direction='in'/>
<arg type='s' name='user_id' direction='in'/>
<arg type='s' name='device_id' direction='in'/>
<arg type='u' name='id' direction='out'/>
</method>
<method name='Unverify'>
<arg type='s' name='pan_user' direction='in'/>
<arg type='s' name='user_id' direction='in'/>
<arg type='s' name='device_id' direction='in'/>
<arg type='u' name='id' direction='out'/>
</method>
<method name='Blacklist'>
<arg type='s' name='pan_user' direction='in'/>
<arg type='s' name='user_id' direction='in'/>
<arg type='s' name='device_id' direction='in'/>
<arg type='u' name='id' direction='out'/>
</method>
<method name='Unblacklist'>
<arg type='s' name='pan_user' direction='in'/>
<arg type='s' name='user_id' direction='in'/>
<arg type='s' name='device_id' direction='in'/>
<arg type='u' name='id' direction='out'/>
</method>
<method name='StartKeyVerification'>
<arg type='s' name='pan_user' direction='in'/>
<arg type='s' name='user_id' direction='in'/>
@ -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,