1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Olm-related cleanups

A couple of small refactors which fell out of the aborted stuff for upgrading
to secure Ed25519 keys, but are useful in their own right.

The main functional change here is to calculate the "algorithms" list from
DECRYPTION_CLASSES (and hence include megolm in the list).
This commit is contained in:
Richard van der Hoff
2016-09-02 11:33:50 +01:00
parent aca8b32e5b
commit 6baf9e1c37
3 changed files with 23 additions and 16 deletions

View File

@@ -46,14 +46,7 @@ function OlmDevice(sessionStore) {
var e2eKeys; var e2eKeys;
var account = new Olm.Account(); var account = new Olm.Account();
try { try {
var e2eAccount = this._sessionStore.getEndToEndAccount(); _initialise_account(this._sessionStore, this._pickleKey, account);
if (e2eAccount === null) {
account.create();
var pickled = account.pickle(this._pickleKey);
this._sessionStore.storeEndToEndAccount(pickled);
} else {
account.unpickle(this._pickleKey, e2eAccount);
}
e2eKeys = JSON.parse(account.identity_keys()); e2eKeys = JSON.parse(account.identity_keys());
} finally { } finally {
account.free(); account.free();
@@ -67,6 +60,17 @@ function OlmDevice(sessionStore) {
this._outboundGroupSessionStore = {}; this._outboundGroupSessionStore = {};
} }
function _initialise_account(sessionStore, pickleKey, account) {
var e2eAccount = sessionStore.getEndToEndAccount();
if (e2eAccount !== null) {
account.unpickle(pickleKey, e2eAccount);
return;
}
account.create();
var pickled = account.pickle(pickleKey);
sessionStore.storeEndToEndAccount(pickled);
}
/** /**
* extract our OlmAccount from the session store and call the given function * extract our OlmAccount from the session store and call the given function

View File

@@ -46,6 +46,7 @@ try {
var Crypto = require("./crypto"); var Crypto = require("./crypto");
CRYPTO_ENABLED = true; CRYPTO_ENABLED = true;
} catch (e) { } catch (e) {
console.error("olm load error", e);
// Olm not installed. // Olm not installed.
} }

View File

@@ -23,11 +23,10 @@ limitations under the License.
var anotherjson = require('another-json'); var anotherjson = require('another-json');
var q = require("q"); var q = require("q");
var utils = require("./utils");
var OlmDevice = require("./OlmDevice"); var OlmDevice = require("./OlmDevice");
var olmlib = require("./olmlib"); var olmlib = require("./olmlib");
var algorithms = require("./crypto-algorithms"); var algorithms = require("./crypto-algorithms");
var DeviceInfo = require("./crypto-deviceinfo"); var DeviceInfo = require("./crypto-deviceinfo");
var DeviceVerification = DeviceInfo.DeviceVerification; var DeviceVerification = DeviceInfo.DeviceVerification;
@@ -58,6 +57,10 @@ function Crypto(baseApis, sessionStore, userId, deviceId) {
// EncryptionAlgorithm instance for each room // EncryptionAlgorithm instance for each room
this._roomAlgorithms = {}; this._roomAlgorithms = {};
this._supportedAlgorithms = utils.keys(
algorithms.DECRYPTION_CLASSES
);
// build our device keys: these will later be uploaded // build our device keys: these will later be uploaded
this._deviceKeys = {}; this._deviceKeys = {};
this._deviceKeys["ed25519:" + this._deviceId] = this._deviceKeys["ed25519:" + this._deviceId] =
@@ -68,7 +71,7 @@ function Crypto(baseApis, sessionStore, userId, deviceId) {
// add our own deviceinfo to the sessionstore // add our own deviceinfo to the sessionstore
var deviceInfo = { var deviceInfo = {
keys: this._deviceKeys, keys: this._deviceKeys,
algorithms: [olmlib.OLM_ALGORITHM], algorithms: this._supportedAlgorithms,
verified: DeviceVerification.VERIFIED, verified: DeviceVerification.VERIFIED,
}; };
var myDevices = this._sessionStore.getEndToEndDevicesForUser( var myDevices = this._sessionStore.getEndToEndDevicesForUser(
@@ -121,7 +124,7 @@ function _uploadDeviceKeys(crypto) {
var deviceId = crypto._deviceId; var deviceId = crypto._deviceId;
var deviceKeys = { var deviceKeys = {
algorithms: [olmlib.OLM_ALGORITHM], algorithms: crypto._supportedAlgorithms,
device_id: deviceId, device_id: deviceId,
keys: crypto._deviceKeys, keys: crypto._deviceKeys,
user_id: userId, user_id: userId,
@@ -288,7 +291,7 @@ function _storeDeviceKeys(_olmDevice, userId, deviceId, userStore, deviceResult)
return false; return false;
} }
var unsigned = deviceResult.unsigned; var unsigned = deviceResult.unsigned || {};
var signatures = deviceResult.signatures || {}; var signatures = deviceResult.signatures || {};
var userSigs = signatures[userId] || {}; var userSigs = signatures[userId] || {};
var signature = userSigs[signKeyId]; var signature = userSigs[signKeyId];
@@ -332,13 +335,12 @@ function _storeDeviceKeys(_olmDevice, userId, deviceId, userStore, deviceResult)
userStore[deviceId] = deviceStore = new DeviceInfo(deviceId); userStore[deviceId] = deviceStore = new DeviceInfo(deviceId);
} }
deviceStore.keys = deviceResult.keys; deviceStore.keys = deviceResult.keys || {};
deviceStore.algorithms = deviceResult.algorithms; deviceStore.algorithms = deviceResult.algorithms || [];
deviceStore.unsigned = unsigned; deviceStore.unsigned = unsigned;
return true; return true;
} }
/** /**
* Get the stored device keys for a user id * Get the stored device keys for a user id
* *