mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-02-13 05:11:39 -05:00
ui: Add support for starting/canceling key verifications.
This commit is contained in:
parent
6dc126d03c
commit
a114b7b1a9
@ -193,6 +193,25 @@ class PanClient(AsyncClient):
|
|||||||
self.task = task
|
self.task = task
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
async def start_sas(self, message, device):
|
||||||
|
try:
|
||||||
|
await self.start_key_verification(device)
|
||||||
|
await self.send_message(
|
||||||
|
DaemonResponse(
|
||||||
|
message.message_id,
|
||||||
|
self.user_id,
|
||||||
|
"m.ok",
|
||||||
|
"Successfully started the key verification request"
|
||||||
|
))
|
||||||
|
except ClientConnectionError as e:
|
||||||
|
await self.send_message(
|
||||||
|
DaemonResponse(
|
||||||
|
message.message_id,
|
||||||
|
self.user_id,
|
||||||
|
"m.connection_error",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
|
||||||
async def accept_sas(self, message):
|
async def accept_sas(self, message):
|
||||||
user_id = message.user_id
|
user_id = message.user_id
|
||||||
device_id = message.device_id
|
device_id = message.device_id
|
||||||
@ -237,6 +256,43 @@ class PanClient(AsyncClient):
|
|||||||
e
|
e
|
||||||
))
|
))
|
||||||
|
|
||||||
|
async def cancel_sas(self, message):
|
||||||
|
user_id = message.user_id
|
||||||
|
device_id = message.device_id
|
||||||
|
|
||||||
|
sas = self.get_active_sas(user_id, device_id)
|
||||||
|
|
||||||
|
if not sas:
|
||||||
|
await self.send_message(
|
||||||
|
DaemonResponse(
|
||||||
|
message.message_id,
|
||||||
|
self.user_id,
|
||||||
|
Sas._txid_error[0],
|
||||||
|
Sas._txid_error[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self.cancel_key_verification(sas.transaction_id)
|
||||||
|
await self.send_message(
|
||||||
|
DaemonResponse(
|
||||||
|
message.message_id,
|
||||||
|
self.user_id,
|
||||||
|
"m.ok",
|
||||||
|
"Successfully canceled the key verification request"
|
||||||
|
))
|
||||||
|
except ClientConnectionError as e:
|
||||||
|
await self.send_message(
|
||||||
|
DaemonResponse(
|
||||||
|
message.message_id,
|
||||||
|
self.user_id,
|
||||||
|
"m.connection_error",
|
||||||
|
e
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
async def confirm_sas(self, message):
|
async def confirm_sas(self, message):
|
||||||
user_id = message.user_id
|
user_id = message.user_id
|
||||||
device_id = message.device_id
|
device_id = message.device_id
|
||||||
|
@ -18,11 +18,12 @@ from pantalaimon.client import PanClient
|
|||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
from pantalaimon.store import ClientInfo, PanStore
|
from pantalaimon.store import ClientInfo, PanStore
|
||||||
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
||||||
DeviceConfirmSasMessage,
|
ConfirmSasMessage,
|
||||||
DeviceUnverifyMessage,
|
DeviceUnverifyMessage,
|
||||||
DeviceVerifyMessage,
|
DeviceVerifyMessage,
|
||||||
ExportKeysMessage, ImportKeysMessage,
|
ExportKeysMessage, ImportKeysMessage,
|
||||||
SasMessage)
|
SasMessage, StartSasMessage,
|
||||||
|
CancelSasMessage)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
@ -121,7 +122,7 @@ class ProxyDaemon:
|
|||||||
|
|
||||||
if isinstance(
|
if isinstance(
|
||||||
message,
|
message,
|
||||||
(DeviceVerifyMessage, DeviceUnverifyMessage)
|
(DeviceVerifyMessage, DeviceUnverifyMessage, StartSasMessage)
|
||||||
):
|
):
|
||||||
|
|
||||||
device = client.device_store[message.user_id].get(
|
device = client.device_store[message.user_id].get(
|
||||||
@ -145,12 +146,16 @@ class ProxyDaemon:
|
|||||||
await self._verify_device(message.message_id, client, device)
|
await self._verify_device(message.message_id, client, device)
|
||||||
elif isinstance(message, DeviceUnverifyMessage):
|
elif isinstance(message, DeviceUnverifyMessage):
|
||||||
await self._unverify_device(message.message_id, client, device)
|
await self._unverify_device(message.message_id, client, device)
|
||||||
|
elif isinstance(message, StartSasMessage):
|
||||||
|
await client.start_sas(message, device)
|
||||||
|
|
||||||
elif isinstance(message, SasMessage):
|
elif isinstance(message, SasMessage):
|
||||||
if isinstance(message, AcceptSasMessage):
|
if isinstance(message, AcceptSasMessage):
|
||||||
await client.accept_sas(message)
|
await client.accept_sas(message)
|
||||||
elif isinstance(message, DeviceConfirmSasMessage):
|
elif isinstance(message, ConfirmSasMessage):
|
||||||
await client.confirm_sas(message)
|
await client.confirm_sas(message)
|
||||||
|
elif isinstance(message, CancelSasMessage):
|
||||||
|
await client.cancel_sas(message)
|
||||||
|
|
||||||
elif isinstance(message, ExportKeysMessage):
|
elif isinstance(message, ExportKeysMessage):
|
||||||
path = os.path.abspath(os.path.expanduser(message.file_path))
|
path = os.path.abspath(os.path.expanduser(message.file_path))
|
||||||
|
@ -50,6 +50,11 @@ class PanctlParser():
|
|||||||
start.add_argument("user_id", type=str)
|
start.add_argument("user_id", type=str)
|
||||||
start.add_argument("device_id", type=str)
|
start.add_argument("device_id", type=str)
|
||||||
|
|
||||||
|
cancel = subparsers.add_parser("cancel-verification")
|
||||||
|
cancel.add_argument("pan_user", type=str)
|
||||||
|
cancel.add_argument("user_id", type=str)
|
||||||
|
cancel.add_argument("device_id", type=str)
|
||||||
|
|
||||||
accept = subparsers.add_parser("accept-verification")
|
accept = subparsers.add_parser("accept-verification")
|
||||||
accept.add_argument("pan_user", type=str)
|
accept.add_argument("pan_user", type=str)
|
||||||
accept.add_argument("user_id", type=str)
|
accept.add_argument("user_id", type=str)
|
||||||
@ -262,6 +267,7 @@ class PanCtl:
|
|||||||
"verify-device",
|
"verify-device",
|
||||||
"unverify-device",
|
"unverify-device",
|
||||||
"start-verification",
|
"start-verification",
|
||||||
|
"cancel-verification",
|
||||||
"accept-verification",
|
"accept-verification",
|
||||||
"confirm-verification"
|
"confirm-verification"
|
||||||
]
|
]
|
||||||
@ -412,6 +418,22 @@ class PanCtl:
|
|||||||
elif command == "list-devices":
|
elif command == "list-devices":
|
||||||
self.list_devices(args)
|
self.list_devices(args)
|
||||||
|
|
||||||
|
elif command == "start-verification":
|
||||||
|
self.own_message_ids.append(
|
||||||
|
self.devices.StartKeyVerification(
|
||||||
|
args.pan_user,
|
||||||
|
args.user_id,
|
||||||
|
args.device_id
|
||||||
|
))
|
||||||
|
|
||||||
|
elif command == "cancel-verification":
|
||||||
|
self.own_message_ids.append(
|
||||||
|
self.devices.CancelKeyVerification(
|
||||||
|
args.pan_user,
|
||||||
|
args.user_id,
|
||||||
|
args.device_id
|
||||||
|
))
|
||||||
|
|
||||||
elif command == "accept-verification":
|
elif command == "accept-verification":
|
||||||
self.own_message_ids.append(
|
self.own_message_ids.append(
|
||||||
self.devices.AcceptKeyVerification(
|
self.devices.AcceptKeyVerification(
|
||||||
|
@ -62,7 +62,17 @@ class SasMessage(_VerificationMessage):
|
|||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class DeviceConfirmSasMessage(SasMessage):
|
class StartSasMessage(SasMessage):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class CancelSasMessage(SasMessage):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class ConfirmSasMessage(SasMessage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -79,11 +89,6 @@ class _SasSignal:
|
|||||||
transaction_id = attr.ib()
|
transaction_id = attr.ib()
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
|
||||||
class StartSasSignal(_SasSignal):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class InviteSasSignal(_SasSignal):
|
class InviteSasSignal(_SasSignal):
|
||||||
pass
|
pass
|
||||||
|
@ -9,12 +9,13 @@ from pydbus.generic import signal
|
|||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
from pantalaimon.store import PanStore
|
from pantalaimon.store import PanStore
|
||||||
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse,
|
||||||
DeviceConfirmSasMessage,
|
ConfirmSasMessage,
|
||||||
DevicesMessage, DeviceUnverifyMessage,
|
DevicesMessage, DeviceUnverifyMessage,
|
||||||
DeviceVerifyMessage,
|
DeviceVerifyMessage,
|
||||||
ExportKeysMessage, ImportKeysMessage,
|
ExportKeysMessage, ImportKeysMessage,
|
||||||
InviteSasSignal, SasDoneSignal,
|
InviteSasSignal, SasDoneSignal,
|
||||||
ShowSasSignal)
|
ShowSasSignal, StartSasMessage,
|
||||||
|
CancelSasMessage)
|
||||||
|
|
||||||
|
|
||||||
class IdCounter:
|
class IdCounter:
|
||||||
@ -111,6 +112,20 @@ class Devices:
|
|||||||
<arg type='aa{ss}' name='devices' direction='out'/>
|
<arg type='aa{ss}' name='devices' direction='out'/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<method name='StartKeyVerification'>
|
||||||
|
<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='CancelKeyVerification'>
|
||||||
|
<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='AcceptKeyVerification'>
|
<method name='AcceptKeyVerification'>
|
||||||
<arg type='s' name='pan_user' direction='in'/>
|
<arg type='s' name='pan_user' direction='in'/>
|
||||||
<arg type='s' name='user_id' direction='in'/>
|
<arg type='s' name='user_id' direction='in'/>
|
||||||
@ -202,41 +217,51 @@ class Devices:
|
|||||||
|
|
||||||
def Verify(self, pan_user, user_id, device_id):
|
def Verify(self, pan_user, user_id, device_id):
|
||||||
message = DeviceVerifyMessage(
|
message = DeviceVerifyMessage(
|
||||||
pan_user,
|
|
||||||
user_id,
|
|
||||||
device_id
|
|
||||||
)
|
|
||||||
self.queue.put(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
def UnVerify(self, pan_user, user_id, device_id):
|
|
||||||
message = DeviceUnverifyMessage(
|
|
||||||
pan_user,
|
|
||||||
user_id,
|
|
||||||
device_id
|
|
||||||
)
|
|
||||||
self.queue.put(message)
|
|
||||||
return
|
|
||||||
|
|
||||||
def StartSas(self, pan_user, user_id, device_id):
|
|
||||||
device_store = self.device_list.get(pan_user)
|
|
||||||
|
|
||||||
if not device_store:
|
|
||||||
logger.info(f"Not verifying device, no store found for user "
|
|
||||||
f"{user_id}")
|
|
||||||
return
|
|
||||||
|
|
||||||
logger.info(f"Verifying device {user_id} {device_id}")
|
|
||||||
return
|
|
||||||
|
|
||||||
def ConfirmKeyVerification(self, pan_user, user_id, device_id):
|
|
||||||
message = DeviceConfirmSasMessage(
|
|
||||||
self.message_id,
|
self.message_id,
|
||||||
pan_user,
|
pan_user,
|
||||||
user_id,
|
user_id,
|
||||||
device_id
|
device_id
|
||||||
)
|
)
|
||||||
print("HEEEELOOO {}".format(message.message_id))
|
self.queue.put(message)
|
||||||
|
return message.message_id
|
||||||
|
|
||||||
|
def UnVerify(self, pan_user, user_id, device_id):
|
||||||
|
message = DeviceUnverifyMessage(
|
||||||
|
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,
|
||||||
|
pan_user,
|
||||||
|
user_id,
|
||||||
|
device_id
|
||||||
|
)
|
||||||
|
self.queue.put(message)
|
||||||
|
return message.message_id
|
||||||
|
|
||||||
|
def CancelKeyVerification(self, pan_user, user_id, device_id):
|
||||||
|
message = CancelSasMessage(
|
||||||
|
self.message_id,
|
||||||
|
pan_user,
|
||||||
|
user_id,
|
||||||
|
device_id
|
||||||
|
)
|
||||||
|
self.queue.put(message)
|
||||||
|
return message.message_id
|
||||||
|
|
||||||
|
def ConfirmKeyVerification(self, pan_user, user_id, device_id):
|
||||||
|
message = ConfirmSasMessage(
|
||||||
|
self.message_id,
|
||||||
|
pan_user,
|
||||||
|
user_id,
|
||||||
|
device_id
|
||||||
|
)
|
||||||
self.queue.put(message)
|
self.queue.put(message)
|
||||||
return message.message_id
|
return message.message_id
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user