Fix shared secret double-puppeting

This commit is contained in:
Andrew Ferrazzutti 2021-05-05 02:40:28 -04:00
parent d894eafc21
commit b197d90118
2 changed files with 6 additions and 18 deletions

View File

@ -175,7 +175,7 @@ class Portal(DBPortal, BasePortal):
async def _bridge_own_message_pm(self, source: 'u.User', sender: Optional['p.Puppet'], mid: str, async def _bridge_own_message_pm(self, source: 'u.User', sender: Optional['p.Puppet'], mid: str,
invite: bool = True) -> Optional[IntentAPI]: invite: bool = True) -> Optional[IntentAPI]:
# Use bridge bot as puppet for own user when puppet for own user is unavailable # Use bridge bot as puppet for own user when puppet for own user is unavailable
# TODO Use own LINE puppet instead, if it's available # TODO Use own LINE puppet instead, and create it if it's not available yet
intent = sender.intent if sender else self.az.intent intent = sender.intent if sender else self.az.intent
if self.is_direct and (sender is None or sender.mid == source.mid and not sender.is_real_user): if self.is_direct and (sender is None or sender.mid == source.mid and not sender.is_real_user):
if self.invite_own_puppet_to_pm and invite: if self.invite_own_puppet_to_pm and invite:
@ -509,8 +509,8 @@ class Portal(DBPortal, BasePortal):
async def _update_matrix_room(self, source: 'u.User', info: ChatInfo) -> None: async def _update_matrix_room(self, source: 'u.User', info: ChatInfo) -> None:
await self.main_intent.invite_user(self.mxid, source.mxid, check_cache=True) await self.main_intent.invite_user(self.mxid, source.mxid, check_cache=True)
puppet = await p.Puppet.get_by_custom_mxid(source.mxid) puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
if puppet: if puppet and puppet.intent:
await puppet.az.intent.ensure_joined(self.mxid) await puppet.intent.ensure_joined(self.mxid)
await self.update_info(info, source.client) await self.update_info(info, source.client)
await self.backfill(source) await self.backfill(source)
@ -540,8 +540,6 @@ class Portal(DBPortal, BasePortal):
"type": str(EventType.ROOM_ENCRYPTION), "type": str(EventType.ROOM_ENCRYPTION),
"content": {"algorithm": "m.megolm.v1.aes-sha2"}, "content": {"algorithm": "m.megolm.v1.aes-sha2"},
}) })
if self.is_direct:
invites.append(self.az.bot_mxid)
# NOTE Set the room title even for direct chats, because # NOTE Set the room title even for direct chats, because
# the LINE bot itself may appear in the title otherwise. # the LINE bot itself may appear in the title otherwise.
#if self.encrypted or not self.is_direct: #if self.encrypted or not self.is_direct:
@ -590,22 +588,13 @@ class Portal(DBPortal, BasePortal):
await self.update() await self.update()
self.log.debug(f"Matrix room created: {self.mxid}") self.log.debug(f"Matrix room created: {self.mxid}")
self.by_mxid[self.mxid] = self self.by_mxid[self.mxid] = self
await self.backfill(source)
if not self.is_direct: if not self.is_direct:
# For multi-user chats, backfill before updating participants, # For multi-user chats, backfill before updating participants,
# to act as as a best guess of when users actually joined. # to act as as a best guess of when users actually joined.
# No way to tell when a user actually left, so just check the # No way to tell when a user actually left, so just check the
# participants list after backfilling. # participants list after backfilling.
await self.backfill(source)
await self._update_participants(info.participants) await self._update_participants(info.participants)
else:
puppet = await p.Puppet.get_by_custom_mxid(source.mxid)
if puppet:
try:
await puppet.az.intent.join_room_by_id(self.mxid)
except MatrixError:
self.log.debug("Failed to join custom puppet into newly created portal",
exc_info=True)
await self.backfill(source)
return self.mxid return self.mxid

View File

@ -150,7 +150,6 @@ class Puppet(DBPuppet, BasePuppet):
@classmethod @classmethod
async def get_by_custom_mxid(cls, mxid: UserID) -> Optional['u.User']: async def get_by_custom_mxid(cls, mxid: UserID) -> Optional['u.User']:
# TODO double-puppeting if mxid == cls.config["bridge.user"]:
#if mxid == cls.config["bridge.user"]: return await cls.bridge.get_user(mxid)
# return await cls.bridge.get_user(mxid)
return None return None