@@ -21,6 +21,7 @@ import {
21
21
RoomId ,
22
22
UserId ,
23
23
HistoryVisibility as RustHistoryVisibility ,
24
+ ToDeviceRequest ,
24
25
} from "@matrix-org/matrix-sdk-crypto-wasm" ;
25
26
26
27
import { EventType } from "../@types/event" ;
@@ -43,6 +44,7 @@ export class RoomEncryptor {
43
44
/**
44
45
* @param olmMachine - The rust-sdk's OlmMachine
45
46
* @param keyClaimManager - Our KeyClaimManager, which manages the queue of one-time-key claim requests
47
+ * @param outgoingRequestProcessor - The OutgoingRequestProcessor, which sends outgoing requests
46
48
* @param room - The room we want to encrypt for
47
49
* @param encryptionSettings - body of the m.room.encryption event currently in force in this room
48
50
*/
@@ -91,8 +93,10 @@ export class RoomEncryptor {
91
93
*
92
94
* This ensures that we have a megolm session ready to use and that we have shared its key with all the devices
93
95
* in the room.
96
+ *
97
+ * @param globalBlacklistUnverifiedDevices - When `true`, it will not send encrypted messages to unverified devices
94
98
*/
95
- public async ensureEncryptionSession ( ) : Promise < void > {
99
+ public async ensureEncryptionSession ( globalBlacklistUnverifiedDevices : boolean ) : Promise < void > {
96
100
if ( this . encryptionSettings . algorithm !== "m.megolm.v1.aes-sha2" ) {
97
101
throw new Error (
98
102
`Cannot encrypt in ${ this . room . roomId } for unsupported algorithm '${ this . encryptionSettings . algorithm } '` ,
@@ -127,7 +131,12 @@ export class RoomEncryptor {
127
131
rustEncryptionSettings . rotationPeriodMessages = BigInt ( this . encryptionSettings . rotation_period_msgs ) ;
128
132
}
129
133
130
- const shareMessages = await this . olmMachine . shareRoomKey (
134
+ // When this.room.getBlacklistUnverifiedDevices() === null, the global settings should be used
135
+ // See Room#getBlacklistUnverifiedDevices
136
+ rustEncryptionSettings . onlyAllowTrustedDevices =
137
+ this . room . getBlacklistUnverifiedDevices ( ) ?? globalBlacklistUnverifiedDevices ;
138
+
139
+ const shareMessages : ToDeviceRequest [ ] = await this . olmMachine . shareRoomKey (
131
140
new RoomId ( this . room . roomId ) ,
132
141
userList ,
133
142
rustEncryptionSettings ,
@@ -156,9 +165,10 @@ export class RoomEncryptor {
156
165
* then encrypt the event using the session.
157
166
*
158
167
* @param event - Event to be encrypted.
168
+ * @param globalBlacklistUnverifiedDevices - When `true`, it will not send encrypted messages to unverified devices
159
169
*/
160
- public async encryptEvent ( event : MatrixEvent ) : Promise < void > {
161
- await this . ensureEncryptionSession ( ) ;
170
+ public async encryptEvent ( event : MatrixEvent , globalBlacklistUnverifiedDevices : boolean ) : Promise < void > {
171
+ await this . ensureEncryptionSession ( globalBlacklistUnverifiedDevices ) ;
162
172
163
173
const encryptedContent = await this . olmMachine . encryptRoomEvent (
164
174
new RoomId ( this . room . roomId ) ,
0 commit comments