@@ -57,6 +57,7 @@ class EncryptionManager:
5757 appservice_mode : bool
5858 periodically_delete_expired_keys : bool
5959 delete_outdated_inbound : bool
60+ msc4190 : bool
6061
6162 bridge : br .Bridge
6263 az : AppService
@@ -108,6 +109,7 @@ def __init__(
108109 self .crypto .send_keys_min_trust = TrustState .parse (verification_levels ["receive" ])
109110 self .key_sharing_enabled = bridge .config ["bridge.encryption.allow_key_sharing" ]
110111 self .appservice_mode = bridge .config ["bridge.encryption.appservice" ]
112+ self .msc4190 = bridge .config ["bridge.encryption.msc4190" ]
111113 if self .appservice_mode :
112114 self .az .otk_handler = self .crypto .handle_as_otk_counts
113115 self .az .device_list_handler = self .crypto .handle_as_device_lists
@@ -246,7 +248,7 @@ async def decrypt(self, evt: EncryptedEvent, wait_session_timeout: int = 5) -> M
246248
247249 async def start (self ) -> None :
248250 flows = await self .client .get_login_flows ()
249- if not flows .supports_type (LoginType .APPSERVICE ):
251+ if not self . msc4190 and not flows .supports_type (LoginType .APPSERVICE ):
250252 self .log .critical (
251253 "Encryption enabled in config, but homeserver does not support appservice login"
252254 )
@@ -261,16 +263,26 @@ async def start(self) -> None:
261263 device_id = await self .crypto_store .get_device_id ()
262264 if device_id :
263265 self .log .debug (f"Found device ID in database: { device_id } " )
264- # We set the API token to the AS token here to authenticate the appservice login
265- # It'll get overridden after the login
266- self .client .api .token = self .az .as_token
267- await self .client .login (
268- login_type = LoginType .APPSERVICE ,
269- device_name = self .device_name ,
270- device_id = device_id ,
271- store_access_token = True ,
272- update_hs_url = False ,
273- )
266+
267+ if self .msc4190 :
268+ if not device_id :
269+ self .log .debug ("Creating bot device with MSC4190" )
270+ self .client .api .token = self .az .as_token
271+ await self .client .create_device_msc4190 (
272+ device_id = device_id , initial_display_name = self .device_name
273+ )
274+ else :
275+ # We set the API token to the AS token here to authenticate the appservice login
276+ # It'll get overridden after the login
277+ self .client .api .token = self .az .as_token
278+ await self .client .login (
279+ login_type = LoginType .APPSERVICE ,
280+ device_name = self .device_name ,
281+ device_id = device_id ,
282+ store_access_token = True ,
283+ update_hs_url = False ,
284+ )
285+
274286 await self .crypto .load ()
275287 if not device_id :
276288 await self .crypto_store .put_device_id (self .client .device_id )
0 commit comments