Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MSC4190 to provision devices for E2EE #48

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/appservice/Appservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export interface IAppserviceRegistration {
*/
"de.sorunome.msc2409.push_ephemeral"?: boolean;

/**
* ** Experimental **
*
* Should the AS use the new device management APIs. Optional.
* @see https://github.com/matrix-org/matrix-spec-proposals/pull/4190
*/
"io.element.msc4190"?: boolean;

// not interested in other options
}

Expand Down
16 changes: 13 additions & 3 deletions src/appservice/Intent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { randomUUID } from "crypto";

import {
DeviceKeyAlgorithm,
extractRequestError,
Expand Down Expand Up @@ -162,9 +164,17 @@ export class Intent {
}

if (!prepared) {
// XXX: We work around servers that don't support device_id impersonation
const accessToken = await Promise.resolve(storage?.readValue("accessToken"));
if (!accessToken) {
let accessToken;
if (this.options.registration["io.element.msc4190"]) {
// Generate a random device ID and create it
deviceId = randomUUID();
// Make sure the device is registered
await this.client.doRequest("PUT", `/_matrix/client/v3/devices/${deviceId}`, null, {});
this.makeClient(true);
this.client.impersonateUserId(this.userId, deviceId);
prepared = true;
} else if (!(accessToken = await Promise.resolve(storage?.readValue("accessToken")))) {
// XXX: We work around servers that don't support device_id impersonation
const loginBody = {
type: "m.login.application_service",
identifier: {
Expand Down
Loading