1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

save public part of cross-signing keys

This commit is contained in:
Hubert Chathi
2019-06-27 23:37:57 -04:00
parent 1cae5e8b97
commit 4356603665
5 changed files with 47 additions and 40 deletions

View File

@@ -280,6 +280,17 @@ Crypto.prototype.init = async function() {
); );
this._deviceList.saveIfDirty(); this._deviceList.saveIfDirty();
} }
await this._cryptoStore.doTxn(
'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT],
(txn) => {
this._cryptoStore.getCrossSigningKeys(txn, (keys) => {
if (keys) {
this._crossSigningInfo.setKeys(keys);
}
});
},
);
// make sure we are keeping track of our own devices // make sure we are keeping track of our own devices
// (this is important for key backups & things) // (this is important for key backups & things)
this._deviceList.startTrackingDeviceList(this._userId); this._deviceList.startTrackingDeviceList(this._userId);
@@ -298,6 +309,14 @@ Crypto.prototype.init = async function() {
*/ */
Crypto.prototype.resetCrossSigningKeys = async function(authDict, level) { Crypto.prototype.resetCrossSigningKeys = async function(authDict, level) {
await this._crossSigningInfo.resetKeys(level); await this._crossSigningInfo.resetKeys(level);
await this._cryptoStore.doTxn(
'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT],
(txn) => {
this._cryptoStore.storeCrossSigningKeys(txn, this._crossSigningInfo.keys);
},
);
// send keys to server
const keys = {}; const keys = {};
for (const [name, key] of Object.entries(this._crossSigningInfo.keys)) { for (const [name, key] of Object.entries(this._crossSigningInfo.keys)) {
keys[name + "_key"] = key; keys[name + "_key"] = key;
@@ -305,6 +324,7 @@ Crypto.prototype.resetCrossSigningKeys = async function(authDict, level) {
await this._baseApis.uploadDeviceSigningKeys(authDict || {}, keys); await this._baseApis.uploadDeviceSigningKeys(authDict || {}, keys);
this._baseApis.emit("cross-signing.keysChanged", {}); this._baseApis.emit("cross-signing.keysChanged", {});
// sign the current device with the new key, and upload to the server
const device = this._deviceList.getStoredDevice(this._userId, this._deviceId); const device = this._deviceList.getStoredDevice(this._userId, this._deviceId);
const signedDevice = await this._crossSigningInfo.signDevice(this._userId, device); const signedDevice = await this._crossSigningInfo.signDevice(this._userId, device);
await this._baseApis.uploadKeySignatures({ await this._baseApis.uploadKeySignatures({
@@ -465,7 +485,12 @@ Crypto.prototype.checkOwnCrossSigningTrust = async function() {
const oldUserSigningId = this._crossSigningInfo.getId("user_signing"); const oldUserSigningId = this._crossSigningInfo.getId("user_signing");
this._crossSigningInfo.setKeys(newCrossSigning.keys); this._crossSigningInfo.setKeys(newCrossSigning.keys);
// FIXME: save it ... somewhere? await this._cryptoStore.doTxn(
'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT],
(txn) => {
this._cryptoStore.storeCrossSigningKeys(txn, this._crossSigningInfo.keys);
},
);
if (oldSelfSigningId !== newCrossSigning.getId("self_signing")) { if (oldSelfSigningId !== newCrossSigning.getId("self_signing")) {
logger.info("Got new self-signing key", newCrossSigning.getId("self_signing")); logger.info("Got new self-signing key", newCrossSigning.getId("self_signing"));
@@ -820,24 +845,6 @@ Crypto.prototype.uploadDeviceKeys = function() {
let accountKeys; let accountKeys;
return crypto._signObject(deviceKeys).then(() => { return crypto._signObject(deviceKeys).then(() => {
return this._cryptoStore.doTxn(
'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT],
(txn) => {
this._cryptoStore.getAccountKeys(txn, keys => {
accountKeys = keys;
});
},
);
}).then(() => {
if (accountKeys && accountKeys.self_signing_key_seed) {
// if we have an SSK, sign the key with the SSK too
pkSign(
deviceKeys,
Buffer.from(accountKeys.self_signing_key_seed, 'base64'),
userId,
);
}
return crypto._baseApis.uploadKeysRequest({ return crypto._baseApis.uploadKeysRequest({
device_keys: deviceKeys, device_keys: deviceKeys,
}, { }, {

View File

@@ -332,9 +332,9 @@ export class Backend {
objectStore.put(newData, "-"); objectStore.put(newData, "-");
} }
getAccountKeys(txn, func) { getCrossSigningKeys(txn, func) {
const objectStore = txn.objectStore("account"); const objectStore = txn.objectStore("account");
const getReq = objectStore.get("keys"); const getReq = objectStore.get("crossSigningKeys");
getReq.onsuccess = function() { getReq.onsuccess = function() {
try { try {
func(getReq.result || null); func(getReq.result || null);
@@ -344,9 +344,9 @@ export class Backend {
}; };
} }
storeAccountKeys(txn, keys) { storeCrossSigningKeys(txn, keys) {
const objectStore = txn.objectStore("account"); const objectStore = txn.objectStore("account");
objectStore.put(keys, "keys"); objectStore.put(keys, "crossSigningKeys");
} }
// Olm Sessions // Olm Sessions

View File

@@ -302,25 +302,25 @@ export default class IndexedDBCryptoStore {
} }
/** /**
* Get the account keys for cross-signing (eg. self-signing key, * Get the public part of the cross-signing keys (eg. self-signing key,
* user signing key). * user signing key).
* *
* @param {*} txn An active transaction. See doTxn(). * @param {*} txn An active transaction. See doTxn().
* @param {function(string)} func Called with the account keys object: * @param {function(string)} func Called with the account keys object:
* { key_type: base64 encoded seed } where key type = user_signing_key_seed or self_signing_key_seed * { key_type: base64 encoded seed } where key type = user_signing_key_seed or self_signing_key_seed
*/ */
getAccountKeys(txn, func) { getCrossSigningKeys(txn, func) {
this._backendPromise.value().getAccountKeys(txn, func); this._backendPromise.value().getCrossSigningKeys(txn, func);
} }
/** /**
* Write the account keys back to the store * Write the cross-siging keys back to the store
* *
* @param {*} txn An active transaction. See doTxn(). * @param {*} txn An active transaction. See doTxn().
* @param {string} keys Account keys object as getAccountKeys() * @param {string} keys keys object as getCrossSigningKeys()
*/ */
storeAccountKeys(txn, keys) { storeCrossSigningKeys(txn, keys) {
this._backendPromise.value().storeAccountKeys(txn, keys); this._backendPromise.value().storeCrossSigningKeys(txn, keys);
} }
// Olm sessions // Olm sessions

View File

@@ -31,7 +31,7 @@ import MemoryCryptoStore from './memory-crypto-store.js';
const E2E_PREFIX = "crypto."; const E2E_PREFIX = "crypto.";
const KEY_END_TO_END_ACCOUNT = E2E_PREFIX + "account"; const KEY_END_TO_END_ACCOUNT = E2E_PREFIX + "account";
const KEY_END_TO_END_ACCOUNT_KEYS = E2E_PREFIX + "account_keys"; const KEY_CROSS_SIGNING_KEYS = E2E_PREFIX + "cross_signing_keys";
const KEY_DEVICE_DATA = E2E_PREFIX + "device_data"; const KEY_DEVICE_DATA = E2E_PREFIX + "device_data";
const KEY_INBOUND_SESSION_PREFIX = E2E_PREFIX + "inboundgroupsessions/"; const KEY_INBOUND_SESSION_PREFIX = E2E_PREFIX + "inboundgroupsessions/";
const KEY_ROOMS_PREFIX = E2E_PREFIX + "rooms/"; const KEY_ROOMS_PREFIX = E2E_PREFIX + "rooms/";
@@ -285,14 +285,14 @@ export default class LocalStorageCryptoStore extends MemoryCryptoStore {
); );
} }
getAccountKeys(txn, func) { getCrossSigningKeys(txn, func) {
const keys = getJsonItem(this.store, KEY_END_TO_END_ACCOUNT_KEYS); const keys = getJsonItem(this.store, KEY_CROSS_SIGNING_KEYS);
func(keys); func(keys);
} }
storeAccountKeys(txn, keys) { storeCrossSigningKeys(txn, keys) {
setJsonItem( setJsonItem(
this.store, KEY_END_TO_END_ACCOUNT_KEYS, keys, this.store, KEY_CROSS_SIGNING_KEYS, keys,
); );
} }

View File

@@ -33,7 +33,7 @@ export default class MemoryCryptoStore {
constructor() { constructor() {
this._outgoingRoomKeyRequests = []; this._outgoingRoomKeyRequests = [];
this._account = null; this._account = null;
this._accountKeys = null; this._crossSigningKeys = null;
// Map of {devicekey -> {sessionId -> session pickle}} // Map of {devicekey -> {sessionId -> session pickle}}
this._sessions = {}; this._sessions = {};
@@ -235,12 +235,12 @@ export default class MemoryCryptoStore {
this._account = newData; this._account = newData;
} }
getAccountKeys(txn, func) { getCrossSigningKeys(txn, func) {
func(this._accountKeys); func(this._crossSigningKeys);
} }
storeAccountKeys(txn, keys) { storeCrossSigningKeys(txn, keys) {
this._accountKeys = keys; this._crossSigningKeys = keys;
} }
// Olm Sessions // Olm Sessions