client: Handle key verification exceptions.

This commit is contained in:
Damir Jelić 2019-04-29 09:49:42 +02:00
parent 776f6e37d8
commit 7a2ee980ff

View File

@ -42,6 +42,7 @@ class PanClient(AsyncClient):
self.key_verification_cb, self.key_verification_cb,
KeyVerificationEvent KeyVerificationEvent
) )
self.key_verificatins_tasks = []
def verify_devices(self, changed_devices): def verify_devices(self, changed_devices):
# Verify new devices automatically for now. # Verify new devices automatically for now.
@ -59,12 +60,10 @@ class PanClient(AsyncClient):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
if isinstance(event, KeyVerificationStart): if isinstance(event, KeyVerificationStart):
try: task = loop.create_task(
loop.create_task(
self.accept_key_verification(event.transaction_id) self.accept_key_verification(event.transaction_id)
) )
except LocalProtocolError as e: self.key_verificatins_tasks.append(task)
self.info(e)
elif isinstance(event, KeyVerificationKey): elif isinstance(event, KeyVerificationKey):
sas = self.key_verifications.get(event.transaction_id, None) sas = self.key_verifications.get(event.transaction_id, None)
@ -89,12 +88,10 @@ class PanClient(AsyncClient):
u"{}".format(device.user_id, device.id, short_string)) u"{}".format(device.user_id, device.id, short_string))
elif isinstance(event, KeyVerificationMac): elif isinstance(event, KeyVerificationMac):
try: task = loop.create_task(
loop.create_task(
self.accept_short_auth_string(event.transaction_id) self.accept_short_auth_string(event.transaction_id)
) )
except LocalProtocolError as e: self.key_verificatins_tasks.append(task)
self.info(e)
def start_loop(self): def start_loop(self):
"""Start a loop that runs forever and keeps on syncing with the server. """Start a loop that runs forever and keeps on syncing with the server.
@ -146,6 +143,13 @@ class PanClient(AsyncClient):
await self.send_to_device_messages() await self.send_to_device_messages()
try:
await asyncio.gather(*self.key_verificatins_tasks)
except LocalProtocolError as e:
logger.info(e)
self.key_verificatins_tasks = []
if self.should_upload_keys: if self.should_upload_keys:
await self.keys_upload() await self.keys_upload()