1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

use new terminology and field name from MSC

This commit is contained in:
Hubert Chathi
2021-03-15 22:49:43 -04:00
parent a489691151
commit 1c191b2278
5 changed files with 59 additions and 54 deletions

View File

@@ -2292,13 +2292,13 @@ MatrixClient.prototype.deleteKeysFromBackup = function(roomId, sessionId, versio
}; };
/** /**
* Share the decryption keys with the given users for the given messages. * Share shared-history decryption keys with the given users.
* *
* @param {string} roomId the room for which keys should be shared. * @param {string} roomId the room for which keys should be shared.
* @param {array} userIds a list of users to share with. The keys will be sent to * @param {array} userIds a list of users to share with. The keys will be sent to
* all of the user's current devices. * all of the user's current devices.
*/ */
MatrixClient.prototype.sendShareableKeys = async function(roomId, userIds) { MatrixClient.prototype.sendSharedHistoryKeys = async function(roomId, userIds) {
if (this._crypto === null) { if (this._crypto === null) {
throw new Error("End-to-end encryption disabled"); throw new Error("End-to-end encryption disabled");
} }
@@ -2317,8 +2317,8 @@ MatrixClient.prototype.sendShareableKeys = async function(roomId, userIds) {
} }
const alg = this._crypto._getRoomDecryptor(roomId, roomEncryption.algorithm); const alg = this._crypto._getRoomDecryptor(roomId, roomEncryption.algorithm);
if (alg.sendShareableInboundSessions) { if (alg.sendSharedHistoryInboundSessions) {
await alg.sendShareableInboundSessions(devicesByUser); await alg.sendSharedHistoryInboundSessions(devicesByUser);
} else { } else {
logger.warning("Algorithm does not support sharing previous keys", roomEncryption.algorithm); logger.warning("Algorithm does not support sharing previous keys", roomEncryption.algorithm);
} }

View File

@@ -1048,7 +1048,7 @@ OlmDevice.prototype.addInboundGroupSession = async function(
'readwrite', [ 'readwrite', [
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS,
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD, IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD,
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS,
], (txn) => { ], (txn) => {
/* if we already have this session, consider updating it */ /* if we already have this session, consider updating it */
this._getInboundGroupSession( this._getInboundGroupSession(
@@ -1106,8 +1106,8 @@ OlmDevice.prototype.addInboundGroupSession = async function(
senderKey, sessionId, sessionData, txn, senderKey, sessionId, sessionData, txn,
); );
if (!existingSession && extraSessionData.shareable) { if (!existingSession && extraSessionData.sharedHistory) {
this._cryptoStore.addShareableInboundGroupSession( this._cryptoStore.addSharedHistoryInboundGroupSession(
roomId, senderKey, sessionId, txn, roomId, senderKey, sessionId, txn,
); );
} }
@@ -1390,7 +1390,7 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
"forwarding_curve25519_key_chain": "forwarding_curve25519_key_chain":
sessionData.forwardingCurve25519KeyChain || [], sessionData.forwardingCurve25519KeyChain || [],
"sender_claimed_ed25519_key": senderEd25519Key, "sender_claimed_ed25519_key": senderEd25519Key,
"shareable": sessionData.shareable || false, "shared_history": sessionData.sharedHistory || false,
}; };
}, },
); );
@@ -1423,20 +1423,20 @@ OlmDevice.prototype.exportInboundGroupSession = function(
"session_key": session.export_session(messageIndex), "session_key": session.export_session(messageIndex),
"forwarding_curve25519_key_chain": session.forwardingCurve25519KeyChain || [], "forwarding_curve25519_key_chain": session.forwardingCurve25519KeyChain || [],
"first_known_index": session.first_known_index(), "first_known_index": session.first_known_index(),
"io.element.unstable.shareable": sessionData.shareable || false, "org.matrix.msc3061.shared_history": sessionData.sharedHistory || false,
}; };
}); });
}; };
OlmDevice.prototype.getShareableInboundGroupSessions = async function(roomId) { OlmDevice.prototype.getSharedHistoryInboundGroupSessions = async function(roomId) {
let result; let result;
await this._cryptoStore.doTxn( await this._cryptoStore.doTxn(
'readonly', [ 'readonly', [
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS,
], (txn) => { ], (txn) => {
result = this._cryptoStore.getShareableInboundGroupSessions(roomId, txn); result = this._cryptoStore.getSharedHistoryInboundGroupSessions(roomId, txn);
}, },
logger.withPrefix("[getShareableInboundGroupSessionsForRoom]"), logger.withPrefix("[getSharedHistoryInboundGroupSessionsForRoom]"),
); );
return result; return result;
}; };

View File

@@ -37,14 +37,14 @@ import {
import {WITHHELD_MESSAGES} from '../OlmDevice'; import {WITHHELD_MESSAGES} from '../OlmDevice';
// determine whether the key can be shared with invitees // determine whether the key can be shared with invitees
function isRoomKeyShareable(room) { function isRoomSharedHistory(room) {
const visibilityEvent = room.currentState && const visibilityEvent = room.currentState &&
room.currentState.getStateEvents("m.room.history_visibility", ""); room.currentState.getStateEvents("m.room.history_visibility", "");
// NOTE: if the room visibility is unset, it would normally default to // NOTE: if the room visibility is unset, it would normally default to
// "world_readable". // "world_readable".
// (https://spec.matrix.org/unstable/client-server-api/#server-behaviour-5) // (https://spec.matrix.org/unstable/client-server-api/#server-behaviour-5)
// But we will be paranoid here, and treat it as a situation where the key // But we will be paranoid here, and treat it as a situation where the room
// should not be shareable // is not shared-history
const visibility = visibilityEvent && visibilityEvent.getContent() && const visibility = visibilityEvent && visibilityEvent.getContent() &&
visibilityEvent.getContent().history_visibility; visibilityEvent.getContent().history_visibility;
return ["world_readable", "shared"].includes(visibility); return ["world_readable", "shared"].includes(visibility);
@@ -55,8 +55,8 @@ function isRoomKeyShareable(room) {
* @constructor * @constructor
* *
* @param {string} sessionId * @param {string} sessionId
* @param {boolean} shareable whether the session can be freely shared with other * @param {boolean} sharedHistory whether the session can be freely shared with
* group members, according to the room history visibility settings * other group members, according to the room history visibility settings
* *
* @property {string} sessionId * @property {string} sessionId
* @property {Number} useCount number of times this session has been used * @property {Number} useCount number of times this session has been used
@@ -66,13 +66,13 @@ function isRoomKeyShareable(room) {
* devices with which we have shared the session key * devices with which we have shared the session key
* userId -> {deviceId -> msgindex} * userId -> {deviceId -> msgindex}
*/ */
function OutboundSessionInfo(sessionId, shareable = false) { function OutboundSessionInfo(sessionId, sharedHistory = false) {
this.sessionId = sessionId; this.sessionId = sessionId;
this.useCount = 0; this.useCount = 0;
this.creationTime = new Date().getTime(); this.creationTime = new Date().getTime();
this.sharedWithDevices = {}; this.sharedWithDevices = {};
this.blockedDevicesNotified = {}; this.blockedDevicesNotified = {};
this.shareable = shareable; this.sharedHistory = sharedHistory;
} }
@@ -222,10 +222,10 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
const prepareSession = async (oldSession) => { const prepareSession = async (oldSession) => {
session = oldSession; session = oldSession;
const shareable = isRoomKeyShareable(room); const sharedHistory = isRoomSharedHistory(room);
// history visibility changed // history visibility changed
if (session && shareable !== session.shareable) { if (session && sharedHistory !== session.sharedHistory) {
session = null; session = null;
} }
@@ -244,7 +244,7 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
if (!session) { if (!session) {
logger.log(`Starting new megolm session for room ${this._roomId}`); logger.log(`Starting new megolm session for room ${this._roomId}`);
session = await this._prepareNewSession(shareable); session = await this._prepareNewSession(sharedHistory);
logger.log(`Started new megolm session ${session.sessionId} ` + logger.log(`Started new megolm session ${session.sessionId} ` +
`for room ${this._roomId}`); `for room ${this._roomId}`);
this._outboundSessions[session.sessionId] = session; this._outboundSessions[session.sessionId] = session;
@@ -280,7 +280,7 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
"session_id": session.sessionId, "session_id": session.sessionId,
"session_key": key.key, "session_key": key.key,
"chain_index": key.chain_index, "chain_index": key.chain_index,
"io.element.unstable.shareable": shareable, "org.matrix.msc3061.shared_history": sharedHistory,
}, },
}; };
const [devicesWithoutSession, olmSessions] = await olmlib.getExistingOlmSessions( const [devicesWithoutSession, olmSessions] = await olmlib.getExistingOlmSessions(
@@ -400,18 +400,18 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
/** /**
* @private * @private
* *
* @param {boolean} shareable * @param {boolean} sharedHistory
* *
* @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session * @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session
*/ */
MegolmEncryption.prototype._prepareNewSession = async function(shareable) { MegolmEncryption.prototype._prepareNewSession = async function(sharedHistory) {
const sessionId = this._olmDevice.createOutboundGroupSession(); const sessionId = this._olmDevice.createOutboundGroupSession();
const key = this._olmDevice.getOutboundGroupSessionKey(sessionId); const key = this._olmDevice.getOutboundGroupSessionKey(sessionId);
await this._olmDevice.addInboundGroupSession( await this._olmDevice.addInboundGroupSession(
this._roomId, this._olmDevice.deviceCurve25519Key, [], sessionId, this._roomId, this._olmDevice.deviceCurve25519Key, [], sessionId,
key.key, {ed25519: this._olmDevice.deviceEd25519Key}, false, key.key, {ed25519: this._olmDevice.deviceEd25519Key}, false,
{shareable: shareable}, {sharedHistory: sharedHistory},
); );
// don't wait for it to complete // don't wait for it to complete
@@ -420,7 +420,7 @@ MegolmEncryption.prototype._prepareNewSession = async function(shareable) {
sessionId, key.key, sessionId, key.key,
); );
return new OutboundSessionInfo(sessionId, shareable); return new OutboundSessionInfo(sessionId, sharedHistory);
}; };
/** /**
@@ -709,7 +709,7 @@ MegolmEncryption.prototype.reshareKeyWithDevice = async function(
"sender_key": senderKey, "sender_key": senderKey,
"sender_claimed_ed25519_key": key.sender_claimed_ed25519_key, "sender_claimed_ed25519_key": key.sender_claimed_ed25519_key,
"forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain, "forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain,
"io.element.unstable.shareable": key.shareable || false, "org.matrix.msc3061.shared_history": key.shared_history || false,
}, },
}; };
@@ -1401,8 +1401,8 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
} }
const extraSessionData = {}; const extraSessionData = {};
if (content["io.element.unstable.shareable"]) { if (content["org.matrix.msc3061.shared_history"]) {
extraSessionData.shareable = true; extraSessionData.sharedHistory = true;
} }
return this._olmDevice.addInboundGroupSession( return this._olmDevice.addInboundGroupSession(
content.room_id, senderKey, forwardingKeyChain, sessionId, content.room_id, senderKey, forwardingKeyChain, sessionId,
@@ -1615,7 +1615,7 @@ MegolmDecryption.prototype._buildKeyForwardingMessage = async function(
"session_key": key.key, "session_key": key.key,
"chain_index": key.chain_index, "chain_index": key.chain_index,
"forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain, "forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain,
"io.element.unstable.shareable": key.shareable || false, "org.matrix.msc3061.shared_history": key.shared_history || false,
}, },
}; };
}; };
@@ -1633,8 +1633,8 @@ MegolmDecryption.prototype.importRoomKey = function(session, opts = {}) {
if (opts.untrusted) { if (opts.untrusted) {
extraSessionData.untrusted = true; extraSessionData.untrusted = true;
} }
if (session["io.element.unstable.shareable"]) { if (session["org.matrix.msc3061.shared_history"]) {
extraSessionData.shareable = true; extraSessionData.sharedHistory = true;
} }
return this._olmDevice.addInboundGroupSession( return this._olmDevice.addInboundGroupSession(
session.room_id, session.room_id,
@@ -1723,18 +1723,19 @@ MegolmDecryption.prototype.retryDecryptionFromSender = async function(senderKey)
return !this._pendingEvents[senderKey]; return !this._pendingEvents[senderKey];
}; };
MegolmDecryption.prototype.sendShareableInboundSessions = async function(devicesByUser) { MegolmDecryption.prototype.sendSharedHistoryInboundSessions = async function(devicesByUser) {
await olmlib.ensureOlmSessionsForDevices( await olmlib.ensureOlmSessionsForDevices(
this._olmDevice, this._baseApis, devicesByUser, this._olmDevice, this._baseApis, devicesByUser,
); );
logger.log("sendShareableInboundSessions to users", Object.keys(devicesByUser)); logger.log("sendSharedHistoryInboundSessions to users", Object.keys(devicesByUser));
const shareableSessions = await this._olmDevice.getShareableInboundGroupSessions( const sharedHistorySessions =
await this._olmDevice.getSharedHistoryInboundGroupSessions(
this._roomId, this._roomId,
); );
logger.log("shareable sessions", shareableSessions); logger.log("shared-history sessions", sharedHistorySessions);
for (const [senderKey, sessionId] of shareableSessions) { for (const [senderKey, sessionId] of sharedHistorySessions) {
const payload = await this._buildKeyForwardingMessage( const payload = await this._buildKeyForwardingMessage(
this._roomId, senderKey, sessionId, this._roomId, senderKey, sessionId,
); );

View File

@@ -758,11 +758,13 @@ export class Backend {
})); }));
} }
addShareableInboundGroupSession(roomId, senderKey, sessionId, txn) { addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId, txn) {
if (!txn) { if (!txn) {
txn = this._db.transaction("shareable_inbound_group_sessions", "readwrite"); txn = this._db.transaction(
"shared_history_inbound_group_sessions", "readwrite",
);
} }
const objectStore = txn.objectStore("shareable_inbound_group_sessions"); const objectStore = txn.objectStore("shared_history_inbound_group_sessions");
const req = objectStore.get([roomId]); const req = objectStore.get([roomId]);
req.onsuccess = () => { req.onsuccess = () => {
const {sessions} = req.result || {sessions: []}; const {sessions} = req.result || {sessions: []};
@@ -771,11 +773,13 @@ export class Backend {
}; };
} }
getShareableInboundGroupSessions(roomId, txn) { getSharedHistoryInboundGroupSessions(roomId, txn) {
if (!txn) { if (!txn) {
txn = this._db.transaction("shareable_inbound_group_sessions", "readonly"); txn = this._db.transaction(
"shared_history_inbound_group_sessions", "readonly",
);
} }
const objectStore = txn.objectStore("shareable_inbound_group_sessions"); const objectStore = txn.objectStore("shared_history_inbound_group_sessions");
const req = objectStore.get([roomId]); const req = objectStore.get([roomId]);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
req.onsuccess = () => { req.onsuccess = () => {
@@ -856,7 +860,7 @@ export function upgradeDatabase(db, oldVersion) {
}); });
} }
if (oldVersion < 10) { if (oldVersion < 10) {
db.createObjectStore("shareable_inbound_group_sessions", { db.createObjectStore("shared_history_inbound_group_sessions", {
keyPath: ["roomId"], keyPath: ["roomId"],
}); });
} }

View File

@@ -584,14 +584,14 @@ export class IndexedDBCryptoStore {
/* FIXME: jsdoc /* FIXME: jsdoc
*/ */
addShareableInboundGroupSession(roomId, senderKey, sessionId, txn) { addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId, txn) {
return this._backend.addShareableInboundGroupSession( return this._backend.addSharedHistoryInboundGroupSession(
roomId, senderKey, sessionId, txn, roomId, senderKey, sessionId, txn,
); );
} }
getShareableInboundGroupSessions(roomId, txn) { getSharedHistoryInboundGroupSessions(roomId, txn) {
return this._backend.getShareableInboundGroupSessions(roomId, txn); return this._backend.getSharedHistoryInboundGroupSessions(roomId, txn);
} }
/** /**
@@ -626,8 +626,8 @@ IndexedDBCryptoStore.STORE_SESSIONS = 'sessions';
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS = 'inbound_group_sessions'; IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS = 'inbound_group_sessions';
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD
= 'inbound_group_sessions_withheld'; = 'inbound_group_sessions_withheld';
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS
= 'shareable_inbound_group_sessions'; = 'shared_history_inbound_group_sessions';
IndexedDBCryptoStore.STORE_DEVICE_DATA = 'device_data'; IndexedDBCryptoStore.STORE_DEVICE_DATA = 'device_data';
IndexedDBCryptoStore.STORE_ROOMS = 'rooms'; IndexedDBCryptoStore.STORE_ROOMS = 'rooms';
IndexedDBCryptoStore.STORE_BACKUP = 'sessions_needing_backup'; IndexedDBCryptoStore.STORE_BACKUP = 'sessions_needing_backup';