Skip to content

Commit 76d0c1a

Browse files
committed
Add isEncryptedDisabledForUnverifiedDevices properties to event
1 parent 6df6fb6 commit 76d0c1a

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

spec/unit/models/event.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ describe("MatrixEvent", () => {
126126
expect(encryptedEvent.isEncrypted()).toBeTruthy();
127127
expect(encryptedEvent.isBeingDecrypted()).toBeFalsy();
128128
expect(encryptedEvent.isDecryptionFailure()).toBeTruthy();
129-
expect(encryptedEvent.isEncryptedDisabledForUnverifiedDevices()).toBeFalsy();
129+
expect(encryptedEvent.isEncryptedDisabledForUnverifiedDevices).toBeFalsy();
130130
expect(encryptedEvent.getContent()).toEqual({
131131
msgtype: "m.bad.encrypted",
132132
body: "** Unable to decrypt: Error: test error **",
133-
reason: "Error: test error",
134133
});
135134
});
136135

@@ -145,11 +144,10 @@ describe("MatrixEvent", () => {
145144
expect(encryptedEvent.isEncrypted()).toBeTruthy();
146145
expect(encryptedEvent.isBeingDecrypted()).toBeFalsy();
147146
expect(encryptedEvent.isDecryptionFailure()).toBeTruthy();
148-
expect(encryptedEvent.isEncryptedDisabledForUnverifiedDevices()).toBeTruthy();
147+
expect(encryptedEvent.isEncryptedDisabledForUnverifiedDevices).toBeTruthy();
149148
expect(encryptedEvent.getContent()).toEqual({
150149
msgtype: "m.bad.encrypted",
151150
body: "** Unable to decrypt: DecryptionError: The sender has disabled encrypting to unverified devices. **",
152-
reason: "DecryptionError: The sender has disabled encrypting to unverified devices.",
153151
});
154152
});
155153

src/@types/crypto.ts

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export interface IEventDecryptionResult {
4444
*/
4545
claimedEd25519Key?: string;
4646
untrusted?: boolean;
47+
/**
48+
* The sender doesn't authorize the unverified devices to decrypt his messages
49+
*/
50+
isEncryptedDisabledForUnverifiedDevices?: boolean;
4751
}
4852

4953
interface Extensible {

src/models/event.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
324324
*/
325325
public verificationRequest?: VerificationRequest;
326326

327+
/*
328+
* True if this event is an encrypted event which we failed to decrypt, the receiver's device is unverified and
329+
* the sender has disabled encrypting to unverified devices.
330+
*/
331+
public isEncryptedDisabledForUnverifiedDevices = false;
332+
327333
private readonly reEmitter: TypedReEmitter<MatrixEventEmittedEvents, MatrixEventHandlerMap>;
328334

329335
/**
@@ -704,22 +710,6 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
704710
return this.clearEvent?.content?.msgtype === "m.bad.encrypted";
705711
}
706712

707-
/**
708-
* Check if this event is an encrypted event which we failed to decrypt, the receiver's device is unverified and
709-
* the sender has disabled encrypting to unverified devices.
710-
*
711-
* (This implies that we might retry decryption at some point in the future)
712-
*
713-
* @returns boolean
714-
*/
715-
public isEncryptedDisabledForUnverifiedDevices(): boolean {
716-
return (
717-
this.isDecryptionFailure() &&
718-
this.clearEvent?.content?.reason ===
719-
"DecryptionError: The sender has disabled encrypting to unverified devices."
720-
);
721-
}
722-
723713
public shouldAttemptDecryption(): boolean {
724714
if (this.isRedacted()) return false;
725715
if (this.isBeingDecrypted()) return false;
@@ -913,9 +903,10 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
913903
content: {
914904
msgtype: "m.bad.encrypted",
915905
body: "** Unable to decrypt: " + reason + " **",
916-
reason,
917906
},
918907
},
908+
isEncryptedDisabledForUnverifiedDevices:
909+
reason === "DecryptionError: The sender has disabled encrypting to unverified devices.",
919910
};
920911
}
921912

@@ -937,6 +928,8 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
937928
this.claimedEd25519Key = decryptionResult.claimedEd25519Key ?? null;
938929
this.forwardingCurve25519KeyChain = decryptionResult.forwardingCurve25519KeyChain || [];
939930
this.untrusted = decryptionResult.untrusted || false;
931+
this.isEncryptedDisabledForUnverifiedDevices =
932+
decryptionResult.isEncryptedDisabledForUnverifiedDevices || false;
940933
this.invalidateExtensibleEvent();
941934
}
942935

0 commit comments

Comments
 (0)