From ae2a37cd7297cf80fa314b1d96d640d967a55a62 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 10 Mar 2023 20:37:31 -0500 Subject: [PATCH 1/4] initial work on DMLS support --- .../views/dialogs/CreateRoomDialog.tsx | 20 +++++++++++++++++++ src/createRoom.ts | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.tsx b/src/components/views/dialogs/CreateRoomDialog.tsx index b15fb800d26..d927bbf8337 100644 --- a/src/components/views/dialogs/CreateRoomDialog.tsx +++ b/src/components/views/dialogs/CreateRoomDialog.tsx @@ -48,6 +48,7 @@ interface IState { joinRule: JoinRule; isPublic: boolean; isEncrypted: boolean; + useMls: boolean; name: string; topic: string; alias: string; @@ -107,6 +108,7 @@ export default class CreateRoomDialog extends React.Component { } else { // If we cannot change encryption we pass `true` for safety, the server should automatically do this for us. opts.encryption = this.state.canChangeEncryption ? this.state.isEncrypted : true; + opts.useMls = this.state.useMls; } if (this.state.topic) { @@ -188,6 +190,10 @@ export default class CreateRoomDialog extends React.Component { this.setState({ isEncrypted }); }; + private onUseMlsChange = (useMls: boolean): void => { + this.setState({ useMls }); + }; + private onAliasChange = (alias: string): void => { this.setState({ alias }); }; @@ -311,6 +317,19 @@ export default class CreateRoomDialog extends React.Component { ); } + let mlsSection: JSX.Element; + if (this.state.isEncrypted) { + mlsSection = ( + + +

Experimental! Don't do it!

+
+ ); + } let federateLabel = _t( "You might enable this if the room will only be used for collaborating with internal " + @@ -374,6 +393,7 @@ export default class CreateRoomDialog extends React.Component { {this.state.detailsOpen ? _t("Hide advanced") : _t("Show advanced")} + {mlsSection} { type: "m.room.encryption", state_key: "", content: { - algorithm: "m.megolm.v1.aes-sha2", + algorithm: opts.useMls ? "org.matrix.msc2883.v0.mls.dhkemx25519-aes128gcm-sha256-ed25519" : "m.megolm.v1.aes-sha2", }, }); } @@ -315,6 +316,11 @@ export default async function createRoom(opts: IOpts): Promise { if (opts.dmUserId) await Rooms.setDMRoom(roomId, opts.dmUserId); }) + .then(() => { + if (opts.encryption && opts.useMls) { + client.crypto.mlsProvider.createGroup(roomId); + } + }) .then(() => { if (opts.parentSpace) { return SpaceStore.instance.addRoomToSpace( From 51e1c8efaae9d85837b65231a2e72b8329aece8c Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Mon, 27 Mar 2023 16:58:17 -0400 Subject: [PATCH 2/4] update to new API and pass in invitees --- src/createRoom.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 43e811b6d41..5956d90b508 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -316,9 +316,12 @@ export default async function createRoom(opts: IOpts): Promise { if (opts.dmUserId) await Rooms.setDMRoom(roomId, opts.dmUserId); }) - .then(() => { + .then(async () => { if (opts.encryption && opts.useMls) { - client.crypto.mlsProvider.createGroup(roomId); + return await client.crypto.mlsProvider.createGroup( + await room, + createOpts.invite || [], + ); } }) .then(() => { From bfe3cb5b440c4cb2350d862d0737699b25d2dbb7 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 5 Jul 2023 16:27:05 -0400 Subject: [PATCH 3/4] update string to agree with latest MSC --- src/createRoom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 5956d90b508..34db0240234 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -209,7 +209,7 @@ export default async function createRoom(opts: IOpts): Promise { type: "m.room.encryption", state_key: "", content: { - algorithm: opts.useMls ? "org.matrix.msc2883.v0.mls.dhkemx25519-aes128gcm-sha256-ed25519" : "m.megolm.v1.aes-sha2", + algorithm: opts.useMls ? "org.matrix.msc2883.v0.dmls.dhkemx25519-aes128gcm-sha256-ed25519" : "m.megolm.v1.aes-sha2", }, }); } From 69fccb27136463f626fd98819bae9a0f8072e735 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 30 Aug 2023 09:52:50 -0400 Subject: [PATCH 4/4] use algorithm name from js-sdk, and add a missing property --- src/components/views/dialogs/CreateRoomDialog.tsx | 1 + src/createRoom.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.tsx b/src/components/views/dialogs/CreateRoomDialog.tsx index d927bbf8337..277b2ecf074 100644 --- a/src/components/views/dialogs/CreateRoomDialog.tsx +++ b/src/components/views/dialogs/CreateRoomDialog.tsx @@ -78,6 +78,7 @@ export default class CreateRoomDialog extends React.Component { this.state = { isPublic: this.props.defaultPublic || false, isEncrypted: this.props.defaultEncrypted ?? privateShouldBeEncrypted(), + useMls: false, joinRule, name: this.props.defaultName || "", topic: "", diff --git a/src/createRoom.ts b/src/createRoom.ts index 34db0240234..30729ca8f8c 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -16,6 +16,7 @@ limitations under the License. */ import { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client"; +import { MLS_ALGORITHM } from "matrix-js-sdk/src/crypto/algorithms/dmls"; import { Room } from "matrix-js-sdk/src/models/room"; import { EventType, RoomCreateTypeField, RoomType } from "matrix-js-sdk/src/@types/event"; import { ICreateRoomOpts } from "matrix-js-sdk/src/@types/requests"; @@ -209,7 +210,7 @@ export default async function createRoom(opts: IOpts): Promise { type: "m.room.encryption", state_key: "", content: { - algorithm: opts.useMls ? "org.matrix.msc2883.v0.dmls.dhkemx25519-aes128gcm-sha256-ed25519" : "m.megolm.v1.aes-sha2", + algorithm: opts.useMls ? MLS_ALGORITHM.name : "m.megolm.v1.aes-sha2", }, }); }