You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Send and handle stable name for withheld codes (#2232)
since MSC2399 is finished FCP and it's in the spec, we can use the stable name now
This commit is contained in:
@@ -618,6 +618,9 @@ describe("megolm", function() {
|
|||||||
aliceTestClient.httpBackend.when(
|
aliceTestClient.httpBackend.when(
|
||||||
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
|
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
|
||||||
).respond(200, {});
|
).respond(200, {});
|
||||||
|
aliceTestClient.httpBackend.when(
|
||||||
|
'PUT', '/sendToDevice/m.room_key.withheld/',
|
||||||
|
).respond(200, {});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
|
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test'),
|
||||||
@@ -718,6 +721,9 @@ describe("megolm", function() {
|
|||||||
aliceTestClient.httpBackend.when(
|
aliceTestClient.httpBackend.when(
|
||||||
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
|
'PUT', '/sendToDevice/org.matrix.room_key.withheld/',
|
||||||
).respond(200, {});
|
).respond(200, {});
|
||||||
|
aliceTestClient.httpBackend.when(
|
||||||
|
'PUT', '/sendToDevice/m.room_key.withheld/',
|
||||||
|
).respond(200, {});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'),
|
aliceTestClient.client.sendTextMessage(ROOM_ID, 'test2'),
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ describe("MegolmDecryption", function() {
|
|||||||
let run = false;
|
let run = false;
|
||||||
aliceClient.sendToDevice = async (msgtype, contentMap) => {
|
aliceClient.sendToDevice = async (msgtype, contentMap) => {
|
||||||
run = true;
|
run = true;
|
||||||
expect(msgtype).toBe("org.matrix.room_key.withheld");
|
expect(msgtype).toMatch(/^(org.matrix|m).room_key.withheld$/);
|
||||||
delete contentMap["@bob:example.com"].bobdevice1.session_id;
|
delete contentMap["@bob:example.com"].bobdevice1.session_id;
|
||||||
delete contentMap["@bob:example.com"].bobdevice2.session_id;
|
delete contentMap["@bob:example.com"].bobdevice2.session_id;
|
||||||
expect(contentMap).toStrictEqual({
|
expect(contentMap).toStrictEqual({
|
||||||
@@ -572,7 +572,7 @@ describe("MegolmDecryption", function() {
|
|||||||
|
|
||||||
const sendPromise = new Promise((resolve, reject) => {
|
const sendPromise = new Promise((resolve, reject) => {
|
||||||
aliceClient.sendToDevice = async (msgtype, contentMap) => {
|
aliceClient.sendToDevice = async (msgtype, contentMap) => {
|
||||||
expect(msgtype).toBe("org.matrix.room_key.withheld");
|
expect(msgtype).toMatch(/^(org.matrix|m).room_key.withheld$/);
|
||||||
expect(contentMap).toStrictEqual({
|
expect(contentMap).toStrictEqual({
|
||||||
'@bob:example.com': {
|
'@bob:example.com': {
|
||||||
bobdevice: {
|
bobdevice: {
|
||||||
@@ -619,7 +619,7 @@ describe("MegolmDecryption", function() {
|
|||||||
content: {
|
content: {
|
||||||
algorithm: "m.megolm.v1.aes-sha2",
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
session_id: "session_id",
|
session_id: "session_id1",
|
||||||
sender_key: bobDevice.deviceCurve25519Key,
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
code: "m.blacklisted",
|
code: "m.blacklisted",
|
||||||
reason: "You have been blocked",
|
reason: "You have been blocked",
|
||||||
@@ -636,7 +636,34 @@ describe("MegolmDecryption", function() {
|
|||||||
ciphertext: "blablabla",
|
ciphertext: "blablabla",
|
||||||
device_id: "bobdevice",
|
device_id: "bobdevice",
|
||||||
sender_key: bobDevice.deviceCurve25519Key,
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
session_id: "session_id",
|
session_id: "session_id1",
|
||||||
|
},
|
||||||
|
}))).rejects.toThrow("The sender has blocked you.");
|
||||||
|
|
||||||
|
aliceClient.crypto.onToDeviceEvent(new MatrixEvent({
|
||||||
|
type: "m.room_key.withheld",
|
||||||
|
sender: "@bob:example.com",
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
|
room_id: roomId,
|
||||||
|
session_id: "session_id2",
|
||||||
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
|
code: "m.blacklisted",
|
||||||
|
reason: "You have been blocked",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
await expect(aliceClient.crypto.decryptEvent(new MatrixEvent({
|
||||||
|
type: "m.room.encrypted",
|
||||||
|
sender: "@bob:example.com",
|
||||||
|
event_id: "$event",
|
||||||
|
room_id: roomId,
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
|
ciphertext: "blablabla",
|
||||||
|
device_id: "bobdevice",
|
||||||
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
|
session_id: "session_id2",
|
||||||
},
|
},
|
||||||
}))).rejects.toThrow("The sender has blocked you.");
|
}))).rejects.toThrow("The sender has blocked you.");
|
||||||
});
|
});
|
||||||
@@ -665,7 +692,7 @@ describe("MegolmDecryption", function() {
|
|||||||
content: {
|
content: {
|
||||||
algorithm: "m.megolm.v1.aes-sha2",
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
session_id: "session_id",
|
session_id: "session_id1",
|
||||||
sender_key: bobDevice.deviceCurve25519Key,
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
code: "m.no_olm",
|
code: "m.no_olm",
|
||||||
reason: "Unable to establish a secure channel.",
|
reason: "Unable to establish a secure channel.",
|
||||||
@@ -686,7 +713,39 @@ describe("MegolmDecryption", function() {
|
|||||||
ciphertext: "blablabla",
|
ciphertext: "blablabla",
|
||||||
device_id: "bobdevice",
|
device_id: "bobdevice",
|
||||||
sender_key: bobDevice.deviceCurve25519Key,
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
session_id: "session_id",
|
session_id: "session_id1",
|
||||||
|
},
|
||||||
|
origin_server_ts: now,
|
||||||
|
}))).rejects.toThrow("The sender was unable to establish a secure channel.");
|
||||||
|
|
||||||
|
aliceClient.crypto.onToDeviceEvent(new MatrixEvent({
|
||||||
|
type: "m.room_key.withheld",
|
||||||
|
sender: "@bob:example.com",
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
|
room_id: roomId,
|
||||||
|
session_id: "session_id2",
|
||||||
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
|
code: "m.no_olm",
|
||||||
|
reason: "Unable to establish a secure channel.",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(aliceClient.crypto.decryptEvent(new MatrixEvent({
|
||||||
|
type: "m.room.encrypted",
|
||||||
|
sender: "@bob:example.com",
|
||||||
|
event_id: "$event",
|
||||||
|
room_id: roomId,
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
|
ciphertext: "blablabla",
|
||||||
|
device_id: "bobdevice",
|
||||||
|
sender_key: bobDevice.deviceCurve25519Key,
|
||||||
|
session_id: "session_id2",
|
||||||
},
|
},
|
||||||
origin_server_ts: now,
|
origin_server_ts: now,
|
||||||
}))).rejects.toThrow("The sender was unable to establish a secure channel.");
|
}))).rejects.toThrow("The sender was unable to establish a secure channel.");
|
||||||
|
|||||||
@@ -709,6 +709,7 @@ class MegolmEncryption extends EncryptionAlgorithm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.baseApis.sendToDevice("org.matrix.room_key.withheld", contentMap);
|
await this.baseApis.sendToDevice("org.matrix.room_key.withheld", contentMap);
|
||||||
|
await this.baseApis.sendToDevice("m.room_key.withheld", contentMap);
|
||||||
|
|
||||||
// record the fact that we notified these blocked devices
|
// record the fact that we notified these blocked devices
|
||||||
for (const userId of Object.keys(contentMap)) {
|
for (const userId of Object.keys(contentMap)) {
|
||||||
|
|||||||
@@ -3115,7 +3115,8 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
|||||||
this.secretStorage.onRequestReceived(event);
|
this.secretStorage.onRequestReceived(event);
|
||||||
} else if (event.getType() === "m.secret.send") {
|
} else if (event.getType() === "m.secret.send") {
|
||||||
this.secretStorage.onSecretReceived(event);
|
this.secretStorage.onSecretReceived(event);
|
||||||
} else if (event.getType() === "org.matrix.room_key.withheld") {
|
} else if (event.getType() === "m.room_key.withheld"
|
||||||
|
|| event.getType() === "org.matrix.room_key.withheld") {
|
||||||
this.onRoomKeyWithheldEvent(event);
|
this.onRoomKeyWithheldEvent(event);
|
||||||
} else if (event.getContent().transaction_id) {
|
} else if (event.getContent().transaction_id) {
|
||||||
this.onKeyVerificationMessage(event);
|
this.onKeyVerificationMessage(event);
|
||||||
|
|||||||
Reference in New Issue
Block a user