Switch to mautrix-python crypto

This commit is contained in:
Tulir Asokan
2020-07-08 23:05:39 +03:00
parent bbfcc9d7d8
commit 4e670a8cbe
11 changed files with 99 additions and 26 deletions
+1
View File
@@ -108,6 +108,7 @@ class Config(BaseBridgeConfig):
copy("bridge.animated_sticker.args")
copy("bridge.encryption.allow")
copy("bridge.encryption.default")
copy("bridge.encryption.database")
copy("bridge.private_chat_portal_meta")
copy("bridge.delivery_receipts")
copy("bridge.delivery_error_reports")
+9
View File
@@ -211,6 +211,15 @@ bridge:
# Default to encryption, force-enable encryption in all portals the bridge creates
# This will cause the bridge bot to be in private chats for the encryption to work properly.
default: false
# Database for the encryption data. Currently only supports Postgres and an in-memory
# store that's persisted as a pickle.
# If set to `default`, will use the appservice postgres database
# or a pickle file if the appservice database is sqlite.
#
# Format examples:
# Pickle: pickle://filename.pickle
# Postgres: postgres://username:password@hostname/dbname
database: default
# Whether or not to explicitly set the avatar and room name for private
# chat portal rooms. This will be implicitly enabled if encryption.default is true.
private_chat_portal_meta: false
+1 -1
View File
@@ -52,7 +52,7 @@ if TYPE_CHECKING:
from ..config import Config
try:
from nio.crypto import decrypt_attachment
from mautrix.crypto.attachments import decrypt_attachment
except ImportError:
decrypt_attachment = None
+6 -10
View File
@@ -411,17 +411,13 @@ class PortalMetadata(BasePortal, ABC):
if not room_id:
raise Exception(f"Failed to create room")
if self.encrypted and self.matrix.e2ee:
members = [self.main_intent.mxid]
if direct:
try:
await self.az.intent.join_room_by_id(room_id)
members += [self.az.intent.mxid]
except Exception:
self.log.warning(f"Failed to add bridge bot to new private chat {room_id}")
await self.matrix.e2ee.add_room(room_id, members=members, encrypted=True)
if self.encrypted and self.matrix.e2ee and direct:
try:
await self.az.intent.ensure_joined(room_id)
except Exception:
self.log.warning(f"Failed to add bridge bot to new private chat {room_id}")
self.mxid = RoomID(room_id)
self.mxid = room_id
self.by_mxid[self.mxid] = self
self.save()
self.az.state_store.set_power_levels(self.mxid, power_levels)
+1 -1
View File
@@ -49,7 +49,7 @@ except ImportError:
VideoFileClip = None
try:
from nio.crypto import encrypt_attachment
from mautrix.crypto.attachments import encrypt_attachment
except ImportError:
encrypt_attachment = None
@@ -41,7 +41,7 @@ from ..tgclient import MautrixTelegramClient
from ..db import TelegramFile as DBTelegramFile
try:
from nio.crypto import async_encrypt_attachment
from mautrix.crypto.attachments import async_encrypt_attachment
except ImportError:
async_encrypt_attachment = None