@@ -57,6 +57,7 @@ class EncryptionManager:
57
57
appservice_mode : bool
58
58
periodically_delete_expired_keys : bool
59
59
delete_outdated_inbound : bool
60
+ msc4190 : bool
60
61
61
62
bridge : br .Bridge
62
63
az : AppService
@@ -108,6 +109,7 @@ def __init__(
108
109
self .crypto .send_keys_min_trust = TrustState .parse (verification_levels ["receive" ])
109
110
self .key_sharing_enabled = bridge .config ["bridge.encryption.allow_key_sharing" ]
110
111
self .appservice_mode = bridge .config ["bridge.encryption.appservice" ]
112
+ self .msc4190 = bridge .config ["bridge.encryption.msc4190" ]
111
113
if self .appservice_mode :
112
114
self .az .otk_handler = self .crypto .handle_as_otk_counts
113
115
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
246
248
247
249
async def start (self ) -> None :
248
250
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 ):
250
252
self .log .critical (
251
253
"Encryption enabled in config, but homeserver does not support appservice login"
252
254
)
@@ -261,16 +263,26 @@ async def start(self) -> None:
261
263
device_id = await self .crypto_store .get_device_id ()
262
264
if device_id :
263
265
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
+
274
286
await self .crypto .load ()
275
287
if not device_id :
276
288
await self .crypto_store .put_device_id (self .client .device_id )
0 commit comments