Skip to content

Commit

Permalink
Merge pull request #1136 from vector-im/make-otk-upload-optional
Browse files Browse the repository at this point in the history
Make it possible to disable OTK upload
  • Loading branch information
MidhunSureshR authored Aug 22, 2023
2 parents f6690cb + d3f24e2 commit e0ed058
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/matrix/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,17 @@ export class Client {
/** Method to start client after registration or with given access token.
* To start the client after registering, use `startWithAuthData(registration.authData)`.
* `homeserver` won't be resolved or normalized using this method,
* use `lookupHomeserver` first if needed (not needed after registration) */
async startWithAuthData({accessToken, deviceId, userId, homeserver}) {
* use `lookupHomeserver` first if needed (not needed after registration)
*
* Setting isReadOnly to false disables OTK uploads.
* Only do this if you're sure that you will never send encrypted messages.
* */
async startWithAuthData({accessToken, deviceId, userId, homeserver, isReadOnly = false}) {
await this._platform.logger.run("startWithAuthData", async (log) => {
await this._createSessionAfterAuth({accessToken, deviceId, userId, homeserver}, true, log);
if (isReadOnly) {
log.set("isReadonly (Disabled OTK Upload)", true);
}
await this._createSessionAfterAuth({accessToken, deviceId, userId, homeserver}, true, isReadOnly, log);
});
}

Expand Down Expand Up @@ -197,11 +204,11 @@ export class Client {
}
return;
}
await this._createSessionAfterAuth(sessionInfo, inspectAccountSetup, log);
await this._createSessionAfterAuth(sessionInfo, inspectAccountSetup, false, log);
});
}

async _createSessionAfterAuth({deviceId, userId, accessToken, homeserver}, inspectAccountSetup, log) {
async _createSessionAfterAuth({deviceId, userId, accessToken, homeserver}, inspectAccountSetup, isReadOnly, log) {
const id = this.createNewSessionId();
const lastUsed = this._platform.clock.now();
const sessionInfo = {
Expand All @@ -212,6 +219,7 @@ export class Client {
homeserver,
accessToken,
lastUsed,
isReadOnly,
};
let dehydratedDevice;
if (inspectAccountSetup) {
Expand Down Expand Up @@ -260,6 +268,7 @@ export class Client {
deviceId: sessionInfo.deviceId,
userId: sessionInfo.userId,
homeserver: sessionInfo.homeServer,
isReadOnly: sessionInfo.isReadOnly,
};
const olm = await this._olmPromise;
let olmWorker = null;
Expand Down
8 changes: 5 additions & 3 deletions src/matrix/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ export class Session {
log.set("keys", this._e2eeAccount.identityKeys);
await this._setupEncryption();
}
await this._e2eeAccount.generateOTKsIfNeeded(this._storage, log);
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, false, log));
if (!this._sessionInfo.isReadOnly) {
await this._e2eeAccount.generateOTKsIfNeeded(this._storage, log);
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, false, log));
}
await this._createCrossSigning();
}
}
Expand Down Expand Up @@ -828,7 +830,7 @@ export class Session {
// to-device messages, to help us avoid throwing away one-time-keys that we
// are about to receive messages for
// (https://github.com/vector-im/riot-web/issues/2782).
if (this._e2eeAccount && !isCatchupSync) {
if (this._e2eeAccount && !isCatchupSync && !this._sessionInfo.isReadOnly) {
const needsToUploadOTKs = await this._e2eeAccount.generateOTKsIfNeeded(this._storage, log);
if (needsToUploadOTKs) {
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, false, log));
Expand Down
9 changes: 9 additions & 0 deletions src/matrix/sessioninfo/localstorage/SessionInfoStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ interface ISessionInfo {
homeServer: string; // deprecate this over time
accessToken: string;
lastUsed: number;
/**
* If true, then this session will not be used for sending
* encrypted messages.
* OTK uploads will be disabled when this is true.
*
* Encrypted messages can still be decrypted and key backups
* can also be restored.
*/
isReadOnly: boolean;
}

// todo: this should probably be in platform/types?
Expand Down

0 comments on commit e0ed058

Please sign in to comment.