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

WIP: online incremental megolm backups #595

Merged
merged 3 commits into from
Nov 21, 2018
Merged
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
6 changes: 6 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,12 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED;
* });
*/

/**
* Fires when we want to suggest to the user that they restore their megolm keys
* from backup or by cross-signing the device.
*
* @event module:client~MatrixClient#"crypto.suggestKeyRestore"
*/

// EventEmitter JSDocs

Expand Down
21 changes: 21 additions & 0 deletions src/crypto/OlmDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ function OlmDevice(sessionStore, cryptoStore) {
this.deviceEd25519Key = null;
this._maxOneTimeKeys = null;

// track whether this device's megolm keys are being backed up incrementally
// to the server or not.
// XXX: this should probably have a single source of truth from OlmAccount
this.backupKey = null;

// track which of our other devices (if any) have cross-signed this device
// XXX: this should probably have a single source of truth in the /devices
// API store or whatever we use to track our self-signed devices.
this.crossSelfSigs = [];

// track whether we have already suggested to the user that they should
// restore their keys from backup or by cross-signing the device.
// We use this to avoid repeatedly emitting the suggestion event.
// XXX: persist this somewhere!
this.suggestedKeyRestore = false;

// we don't bother stashing outboundgroupsessions in the sessionstore -
// instead we keep them here.
this._outboundGroupSessionStore = {};
Expand Down Expand Up @@ -921,6 +937,11 @@ OlmDevice.prototype.addInboundGroupSession = async function(
this._cryptoStore.addEndToEndInboundGroupSession(
senderKey, sessionId, sessionData, txn,
);

if (this.backupKey) {
// get olm::Account::generate_backup_encryption_secret
// save sessionData (pickled with this secret) to the server
}
} finally {
session.free();
}
Expand Down
9 changes: 9 additions & 0 deletions src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,15 @@ SyncApi.prototype._processSyncResponse = async function(
async function processRoomEvent(e) {
client.emit("event", e);
if (e.isState() && e.getType() == "m.room.encryption" && self.opts.crypto) {

// XXX: get device
if (!device.getSuggestedKeyRestore() &&
!device.backupKey && !device.selfCrossSigs.length)
{
client.emit("crypto.suggestKeyRestore");
device.setSuggestedKeyRestore(true);
}

await self.opts.crypto.onCryptoEvent(e);
}
}
Expand Down