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", str(e) ) )
async def handle_key_request_message(self, message): if isinstance(message, ContinueKeyShare): continued = False for share in self.get_active_key_requests(message.user_id, message.device_id): continued = True if not self.continue_key_share(share): await self.send_message( DaemonResponse( message.message_id, self.user_id, "m.error", (f"Unable to continue the key sharing for " f"{message.user_id} via {message.device_id}: The " f"device is still not verified."), )) return if continued: try: await self.send_to_device_messages() except ClientConnectionError: # We can safely ignore this since this will be retried # after the next sync in the sync_forever method. pass response = (f"Succesfully continued the key requests from " f"{message.user_id} via {message.device_id}") ret = "m.ok" else: response = (f"No active key requests from {message.user_id} " f"via {message.device_id} found.") ret = "m.error" await self.send_message( DaemonResponse(message.message_id, self.user_id, ret, response)) elif isinstance(message, CancelKeyShare): cancelled = False for share in self.get_active_key_requests(message.user_id, message.device_id): cancelled = self.cancel_key_share(share) if cancelled: response = (f"Succesfully cancelled key requests from " f"{message.user_id} via {message.device_id}") ret = "m.ok" else: response = (f"No active key requests from {message.user_id} " f"via {message.device_id} found.") ret = "m.error" await self.send_message( DaemonResponse(message.message_id, self.user_id, ret, response))
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", str(e)))
async def confirm_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.confirm_short_auth_string(sas.transaction_id) except ClientConnectionError as e: await self.send_message( DaemonResponse( message.message_id, self.user_id, "m.connection_error", str(e) ) ) return device = sas.other_olm_device if sas.verified: await self.send_update_device(device) await self.send_message( SasDoneSignal( self.user_id, device.user_id, device.id, sas.transaction_id ) ) else: await self.send_message( DaemonResponse( message.message_id, self.user_id, "m.ok", f"Waiting for {device.user_id} to confirm.", ) )
async def send_info(message_id, pan_user, code, string): message = DaemonResponse(message_id, pan_user, code, string) await send_queue.put(message)
async def send_response(self, message_id, pan_user, code, message): """Send a thread response message to the UI thread.""" message = DaemonResponse(message_id, pan_user, code, message) await self.send_ui_message(message)