Skip to content

Commit 1c191b2

Browse files
committed
use new terminology and field name from MSC
1 parent a489691 commit 1c191b2

File tree

5 files changed

+59
-54
lines changed

5 files changed

+59
-54
lines changed

src/client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,13 +2292,13 @@ MatrixClient.prototype.deleteKeysFromBackup = function(roomId, sessionId, versio
22922292
};
22932293

22942294
/**
2295-
* Share the decryption keys with the given users for the given messages.
2295+
* Share shared-history decryption keys with the given users.
22962296
*
22972297
* @param {string} roomId the room for which keys should be shared.
22982298
* @param {array} userIds a list of users to share with. The keys will be sent to
22992299
* all of the user's current devices.
23002300
*/
2301-
MatrixClient.prototype.sendShareableKeys = async function(roomId, userIds) {
2301+
MatrixClient.prototype.sendSharedHistoryKeys = async function(roomId, userIds) {
23022302
if (this._crypto === null) {
23032303
throw new Error("End-to-end encryption disabled");
23042304
}
@@ -2317,8 +2317,8 @@ MatrixClient.prototype.sendShareableKeys = async function(roomId, userIds) {
23172317
}
23182318

23192319
const alg = this._crypto._getRoomDecryptor(roomId, roomEncryption.algorithm);
2320-
if (alg.sendShareableInboundSessions) {
2321-
await alg.sendShareableInboundSessions(devicesByUser);
2320+
if (alg.sendSharedHistoryInboundSessions) {
2321+
await alg.sendSharedHistoryInboundSessions(devicesByUser);
23222322
} else {
23232323
logger.warning("Algorithm does not support sharing previous keys", roomEncryption.algorithm);
23242324
}

src/crypto/OlmDevice.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ OlmDevice.prototype.addInboundGroupSession = async function(
10481048
'readwrite', [
10491049
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS,
10501050
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD,
1051-
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS,
1051+
IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS,
10521052
], (txn) => {
10531053
/* if we already have this session, consider updating it */
10541054
this._getInboundGroupSession(
@@ -1106,8 +1106,8 @@ OlmDevice.prototype.addInboundGroupSession = async function(
11061106
senderKey, sessionId, sessionData, txn,
11071107
);
11081108

1109-
if (!existingSession && extraSessionData.shareable) {
1110-
this._cryptoStore.addShareableInboundGroupSession(
1109+
if (!existingSession && extraSessionData.sharedHistory) {
1110+
this._cryptoStore.addSharedHistoryInboundGroupSession(
11111111
roomId, senderKey, sessionId, txn,
11121112
);
11131113
}
@@ -1390,7 +1390,7 @@ OlmDevice.prototype.getInboundGroupSessionKey = async function(
13901390
"forwarding_curve25519_key_chain":
13911391
sessionData.forwardingCurve25519KeyChain || [],
13921392
"sender_claimed_ed25519_key": senderEd25519Key,
1393-
"shareable": sessionData.shareable || false,
1393+
"shared_history": sessionData.sharedHistory || false,
13941394
};
13951395
},
13961396
);
@@ -1423,20 +1423,20 @@ OlmDevice.prototype.exportInboundGroupSession = function(
14231423
"session_key": session.export_session(messageIndex),
14241424
"forwarding_curve25519_key_chain": session.forwardingCurve25519KeyChain || [],
14251425
"first_known_index": session.first_known_index(),
1426-
"io.element.unstable.shareable": sessionData.shareable || false,
1426+
"org.matrix.msc3061.shared_history": sessionData.sharedHistory || false,
14271427
};
14281428
});
14291429
};
14301430

1431-
OlmDevice.prototype.getShareableInboundGroupSessions = async function(roomId) {
1431+
OlmDevice.prototype.getSharedHistoryInboundGroupSessions = async function(roomId) {
14321432
let result;
14331433
await this._cryptoStore.doTxn(
14341434
'readonly', [
1435-
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS,
1435+
IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS,
14361436
], (txn) => {
1437-
result = this._cryptoStore.getShareableInboundGroupSessions(roomId, txn);
1437+
result = this._cryptoStore.getSharedHistoryInboundGroupSessions(roomId, txn);
14381438
},
1439-
logger.withPrefix("[getShareableInboundGroupSessionsForRoom]"),
1439+
logger.withPrefix("[getSharedHistoryInboundGroupSessionsForRoom]"),
14401440
);
14411441
return result;
14421442
};

src/crypto/algorithms/megolm.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ import {
3737
import {WITHHELD_MESSAGES} from '../OlmDevice';
3838

3939
// determine whether the key can be shared with invitees
40-
function isRoomKeyShareable(room) {
40+
function isRoomSharedHistory(room) {
4141
const visibilityEvent = room.currentState &&
4242
room.currentState.getStateEvents("m.room.history_visibility", "");
4343
// NOTE: if the room visibility is unset, it would normally default to
4444
// "world_readable".
4545
// (https://spec.matrix.org/unstable/client-server-api/#server-behaviour-5)
46-
// But we will be paranoid here, and treat it as a situation where the key
47-
// should not be shareable
46+
// But we will be paranoid here, and treat it as a situation where the room
47+
// is not shared-history
4848
const visibility = visibilityEvent && visibilityEvent.getContent() &&
4949
visibilityEvent.getContent().history_visibility;
5050
return ["world_readable", "shared"].includes(visibility);
@@ -55,8 +55,8 @@ function isRoomKeyShareable(room) {
5555
* @constructor
5656
*
5757
* @param {string} sessionId
58-
* @param {boolean} shareable whether the session can be freely shared with other
59-
* group members, according to the room history visibility settings
58+
* @param {boolean} sharedHistory whether the session can be freely shared with
59+
* other group members, according to the room history visibility settings
6060
*
6161
* @property {string} sessionId
6262
* @property {Number} useCount number of times this session has been used
@@ -66,13 +66,13 @@ function isRoomKeyShareable(room) {
6666
* devices with which we have shared the session key
6767
* userId -> {deviceId -> msgindex}
6868
*/
69-
function OutboundSessionInfo(sessionId, shareable = false) {
69+
function OutboundSessionInfo(sessionId, sharedHistory = false) {
7070
this.sessionId = sessionId;
7171
this.useCount = 0;
7272
this.creationTime = new Date().getTime();
7373
this.sharedWithDevices = {};
7474
this.blockedDevicesNotified = {};
75-
this.shareable = shareable;
75+
this.sharedHistory = sharedHistory;
7676
}
7777

7878

@@ -222,10 +222,10 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
222222
const prepareSession = async (oldSession) => {
223223
session = oldSession;
224224

225-
const shareable = isRoomKeyShareable(room);
225+
const sharedHistory = isRoomSharedHistory(room);
226226

227227
// history visibility changed
228-
if (session && shareable !== session.shareable) {
228+
if (session && sharedHistory !== session.sharedHistory) {
229229
session = null;
230230
}
231231

@@ -244,7 +244,7 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
244244

245245
if (!session) {
246246
logger.log(`Starting new megolm session for room ${this._roomId}`);
247-
session = await this._prepareNewSession(shareable);
247+
session = await this._prepareNewSession(sharedHistory);
248248
logger.log(`Started new megolm session ${session.sessionId} ` +
249249
`for room ${this._roomId}`);
250250
this._outboundSessions[session.sessionId] = session;
@@ -280,7 +280,7 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
280280
"session_id": session.sessionId,
281281
"session_key": key.key,
282282
"chain_index": key.chain_index,
283-
"io.element.unstable.shareable": shareable,
283+
"org.matrix.msc3061.shared_history": sharedHistory,
284284
},
285285
};
286286
const [devicesWithoutSession, olmSessions] = await olmlib.getExistingOlmSessions(
@@ -400,18 +400,18 @@ MegolmEncryption.prototype._ensureOutboundSession = async function(
400400
/**
401401
* @private
402402
*
403-
* @param {boolean} shareable
403+
* @param {boolean} sharedHistory
404404
*
405405
* @return {module:crypto/algorithms/megolm.OutboundSessionInfo} session
406406
*/
407-
MegolmEncryption.prototype._prepareNewSession = async function(shareable) {
407+
MegolmEncryption.prototype._prepareNewSession = async function(sharedHistory) {
408408
const sessionId = this._olmDevice.createOutboundGroupSession();
409409
const key = this._olmDevice.getOutboundGroupSessionKey(sessionId);
410410

411411
await this._olmDevice.addInboundGroupSession(
412412
this._roomId, this._olmDevice.deviceCurve25519Key, [], sessionId,
413413
key.key, {ed25519: this._olmDevice.deviceEd25519Key}, false,
414-
{shareable: shareable},
414+
{sharedHistory: sharedHistory},
415415
);
416416

417417
// don't wait for it to complete
@@ -420,7 +420,7 @@ MegolmEncryption.prototype._prepareNewSession = async function(shareable) {
420420
sessionId, key.key,
421421
);
422422

423-
return new OutboundSessionInfo(sessionId, shareable);
423+
return new OutboundSessionInfo(sessionId, sharedHistory);
424424
};
425425

426426
/**
@@ -709,7 +709,7 @@ MegolmEncryption.prototype.reshareKeyWithDevice = async function(
709709
"sender_key": senderKey,
710710
"sender_claimed_ed25519_key": key.sender_claimed_ed25519_key,
711711
"forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain,
712-
"io.element.unstable.shareable": key.shareable || false,
712+
"org.matrix.msc3061.shared_history": key.shared_history || false,
713713
},
714714
};
715715

@@ -1401,8 +1401,8 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
14011401
}
14021402

14031403
const extraSessionData = {};
1404-
if (content["io.element.unstable.shareable"]) {
1405-
extraSessionData.shareable = true;
1404+
if (content["org.matrix.msc3061.shared_history"]) {
1405+
extraSessionData.sharedHistory = true;
14061406
}
14071407
return this._olmDevice.addInboundGroupSession(
14081408
content.room_id, senderKey, forwardingKeyChain, sessionId,
@@ -1615,7 +1615,7 @@ MegolmDecryption.prototype._buildKeyForwardingMessage = async function(
16151615
"session_key": key.key,
16161616
"chain_index": key.chain_index,
16171617
"forwarding_curve25519_key_chain": key.forwarding_curve25519_key_chain,
1618-
"io.element.unstable.shareable": key.shareable || false,
1618+
"org.matrix.msc3061.shared_history": key.shared_history || false,
16191619
},
16201620
};
16211621
};
@@ -1633,8 +1633,8 @@ MegolmDecryption.prototype.importRoomKey = function(session, opts = {}) {
16331633
if (opts.untrusted) {
16341634
extraSessionData.untrusted = true;
16351635
}
1636-
if (session["io.element.unstable.shareable"]) {
1637-
extraSessionData.shareable = true;
1636+
if (session["org.matrix.msc3061.shared_history"]) {
1637+
extraSessionData.sharedHistory = true;
16381638
}
16391639
return this._olmDevice.addInboundGroupSession(
16401640
session.room_id,
@@ -1723,18 +1723,19 @@ MegolmDecryption.prototype.retryDecryptionFromSender = async function(senderKey)
17231723
return !this._pendingEvents[senderKey];
17241724
};
17251725

1726-
MegolmDecryption.prototype.sendShareableInboundSessions = async function(devicesByUser) {
1726+
MegolmDecryption.prototype.sendSharedHistoryInboundSessions = async function(devicesByUser) {
17271727
await olmlib.ensureOlmSessionsForDevices(
17281728
this._olmDevice, this._baseApis, devicesByUser,
17291729
);
17301730

1731-
logger.log("sendShareableInboundSessions to users", Object.keys(devicesByUser));
1731+
logger.log("sendSharedHistoryInboundSessions to users", Object.keys(devicesByUser));
17321732

1733-
const shareableSessions = await this._olmDevice.getShareableInboundGroupSessions(
1734-
this._roomId,
1735-
);
1736-
logger.log("shareable sessions", shareableSessions);
1737-
for (const [senderKey, sessionId] of shareableSessions) {
1733+
const sharedHistorySessions =
1734+
await this._olmDevice.getSharedHistoryInboundGroupSessions(
1735+
this._roomId,
1736+
);
1737+
logger.log("shared-history sessions", sharedHistorySessions);
1738+
for (const [senderKey, sessionId] of sharedHistorySessions) {
17381739
const payload = await this._buildKeyForwardingMessage(
17391740
this._roomId, senderKey, sessionId,
17401741
);

src/crypto/store/indexeddb-crypto-store-backend.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,13 @@ export class Backend {
758758
}));
759759
}
760760

761-
addShareableInboundGroupSession(roomId, senderKey, sessionId, txn) {
761+
addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId, txn) {
762762
if (!txn) {
763-
txn = this._db.transaction("shareable_inbound_group_sessions", "readwrite");
763+
txn = this._db.transaction(
764+
"shared_history_inbound_group_sessions", "readwrite",
765+
);
764766
}
765-
const objectStore = txn.objectStore("shareable_inbound_group_sessions");
767+
const objectStore = txn.objectStore("shared_history_inbound_group_sessions");
766768
const req = objectStore.get([roomId]);
767769
req.onsuccess = () => {
768770
const {sessions} = req.result || {sessions: []};
@@ -771,11 +773,13 @@ export class Backend {
771773
};
772774
}
773775

774-
getShareableInboundGroupSessions(roomId, txn) {
776+
getSharedHistoryInboundGroupSessions(roomId, txn) {
775777
if (!txn) {
776-
txn = this._db.transaction("shareable_inbound_group_sessions", "readonly");
778+
txn = this._db.transaction(
779+
"shared_history_inbound_group_sessions", "readonly",
780+
);
777781
}
778-
const objectStore = txn.objectStore("shareable_inbound_group_sessions");
782+
const objectStore = txn.objectStore("shared_history_inbound_group_sessions");
779783
const req = objectStore.get([roomId]);
780784
return new Promise((resolve, reject) => {
781785
req.onsuccess = () => {
@@ -856,7 +860,7 @@ export function upgradeDatabase(db, oldVersion) {
856860
});
857861
}
858862
if (oldVersion < 10) {
859-
db.createObjectStore("shareable_inbound_group_sessions", {
863+
db.createObjectStore("shared_history_inbound_group_sessions", {
860864
keyPath: ["roomId"],
861865
});
862866
}

src/crypto/store/indexeddb-crypto-store.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,14 @@ export class IndexedDBCryptoStore {
584584

585585
/* FIXME: jsdoc
586586
*/
587-
addShareableInboundGroupSession(roomId, senderKey, sessionId, txn) {
588-
return this._backend.addShareableInboundGroupSession(
587+
addSharedHistoryInboundGroupSession(roomId, senderKey, sessionId, txn) {
588+
return this._backend.addSharedHistoryInboundGroupSession(
589589
roomId, senderKey, sessionId, txn,
590590
);
591591
}
592592

593-
getShareableInboundGroupSessions(roomId, txn) {
594-
return this._backend.getShareableInboundGroupSessions(roomId, txn);
593+
getSharedHistoryInboundGroupSessions(roomId, txn) {
594+
return this._backend.getSharedHistoryInboundGroupSessions(roomId, txn);
595595
}
596596

597597
/**
@@ -626,8 +626,8 @@ IndexedDBCryptoStore.STORE_SESSIONS = 'sessions';
626626
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS = 'inbound_group_sessions';
627627
IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS_WITHHELD
628628
= 'inbound_group_sessions_withheld';
629-
IndexedDBCryptoStore.STORE_SHAREABLE_INBOUND_GROUP_SESSIONS
630-
= 'shareable_inbound_group_sessions';
629+
IndexedDBCryptoStore.STORE_SHARED_HISTORY_INBOUND_GROUP_SESSIONS
630+
= 'shared_history_inbound_group_sessions';
631631
IndexedDBCryptoStore.STORE_DEVICE_DATA = 'device_data';
632632
IndexedDBCryptoStore.STORE_ROOMS = 'rooms';
633633
IndexedDBCryptoStore.STORE_BACKUP = 'sessions_needing_backup';

0 commit comments

Comments
 (0)