You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Replace console.log with loglevel logger. Fixes #332
Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
@@ -24,6 +24,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../logger';
|
||||||
import DeviceInfo from './deviceinfo';
|
import DeviceInfo from './deviceinfo';
|
||||||
import olmlib from './olmlib';
|
import olmlib from './olmlib';
|
||||||
import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
|
import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
|
||||||
@@ -110,7 +111,7 @@ export default class DeviceList {
|
|||||||
'readwrite', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
|
'readwrite', [IndexedDBCryptoStore.STORE_DEVICE_DATA], (txn) => {
|
||||||
this._cryptoStore.getEndToEndDeviceData(txn, (deviceData) => {
|
this._cryptoStore.getEndToEndDeviceData(txn, (deviceData) => {
|
||||||
if (deviceData === null) {
|
if (deviceData === null) {
|
||||||
console.log("Migrating e2e device data...");
|
logger.log("Migrating e2e device data...");
|
||||||
this._devices = this._sessionStore.getAllEndToEndDevices() || {};
|
this._devices = this._sessionStore.getAllEndToEndDevices() || {};
|
||||||
this._deviceTrackingStatus = (
|
this._deviceTrackingStatus = (
|
||||||
this._sessionStore.getEndToEndDeviceTrackingStatus() || {}
|
this._sessionStore.getEndToEndDeviceTrackingStatus() || {}
|
||||||
@@ -190,7 +191,7 @@ export default class DeviceList {
|
|||||||
const resolveSavePromise = this._resolveSavePromise;
|
const resolveSavePromise = this._resolveSavePromise;
|
||||||
this._savePromiseTime = targetTime;
|
this._savePromiseTime = targetTime;
|
||||||
this._saveTimer = setTimeout(() => {
|
this._saveTimer = setTimeout(() => {
|
||||||
console.log('Saving device tracking data at token ' + this._syncToken);
|
logger.log('Saving device tracking data at token ' + this._syncToken);
|
||||||
// null out savePromise now (after the delay but before the write),
|
// null out savePromise now (after the delay but before the write),
|
||||||
// otherwise we could return the existing promise when the save has
|
// otherwise we could return the existing promise when the save has
|
||||||
// actually already happened. Likewise for the dirty flag.
|
// actually already happened. Likewise for the dirty flag.
|
||||||
@@ -258,7 +259,7 @@ export default class DeviceList {
|
|||||||
if (this._keyDownloadsInProgressByUser[u]) {
|
if (this._keyDownloadsInProgressByUser[u]) {
|
||||||
// already a key download in progress/queued for this user; its results
|
// already a key download in progress/queued for this user; its results
|
||||||
// will be good enough for us.
|
// will be good enough for us.
|
||||||
console.log(
|
logger.log(
|
||||||
`downloadKeys: already have a download in progress for ` +
|
`downloadKeys: already have a download in progress for ` +
|
||||||
`${u}: awaiting its result`,
|
`${u}: awaiting its result`,
|
||||||
);
|
);
|
||||||
@@ -269,13 +270,13 @@ export default class DeviceList {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (usersToDownload.length != 0) {
|
if (usersToDownload.length != 0) {
|
||||||
console.log("downloadKeys: downloading for", usersToDownload);
|
logger.log("downloadKeys: downloading for", usersToDownload);
|
||||||
const downloadPromise = this._doKeyDownload(usersToDownload);
|
const downloadPromise = this._doKeyDownload(usersToDownload);
|
||||||
promises.push(downloadPromise);
|
promises.push(downloadPromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promises.length === 0) {
|
if (promises.length === 0) {
|
||||||
console.log("downloadKeys: already have all necessary keys");
|
logger.log("downloadKeys: already have all necessary keys");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return Promise.all(promises).then(() => {
|
||||||
@@ -433,7 +434,7 @@ export default class DeviceList {
|
|||||||
throw new Error('userId must be a string; was '+userId);
|
throw new Error('userId must be a string; was '+userId);
|
||||||
}
|
}
|
||||||
if (!this._deviceTrackingStatus[userId]) {
|
if (!this._deviceTrackingStatus[userId]) {
|
||||||
console.log('Now tracking device list for ' + userId);
|
logger.log('Now tracking device list for ' + userId);
|
||||||
this._deviceTrackingStatus[userId] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
this._deviceTrackingStatus[userId] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
||||||
}
|
}
|
||||||
// we don't yet persist the tracking status, since there may be a lot
|
// we don't yet persist the tracking status, since there may be a lot
|
||||||
@@ -452,7 +453,7 @@ export default class DeviceList {
|
|||||||
*/
|
*/
|
||||||
stopTrackingDeviceList(userId) {
|
stopTrackingDeviceList(userId) {
|
||||||
if (this._deviceTrackingStatus[userId]) {
|
if (this._deviceTrackingStatus[userId]) {
|
||||||
console.log('No longer tracking device list for ' + userId);
|
logger.log('No longer tracking device list for ' + userId);
|
||||||
this._deviceTrackingStatus[userId] = TRACKING_STATUS_NOT_TRACKED;
|
this._deviceTrackingStatus[userId] = TRACKING_STATUS_NOT_TRACKED;
|
||||||
|
|
||||||
// we don't yet persist the tracking status, since there may be a lot
|
// we don't yet persist the tracking status, since there may be a lot
|
||||||
@@ -487,7 +488,7 @@ export default class DeviceList {
|
|||||||
*/
|
*/
|
||||||
invalidateUserDeviceList(userId) {
|
invalidateUserDeviceList(userId) {
|
||||||
if (this._deviceTrackingStatus[userId]) {
|
if (this._deviceTrackingStatus[userId]) {
|
||||||
console.log("Marking device list outdated for", userId);
|
logger.log("Marking device list outdated for", userId);
|
||||||
this._deviceTrackingStatus[userId] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
this._deviceTrackingStatus[userId] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
||||||
|
|
||||||
// we don't yet persist the tracking status, since there may be a lot
|
// we don't yet persist the tracking status, since there may be a lot
|
||||||
@@ -550,7 +551,7 @@ export default class DeviceList {
|
|||||||
).then(() => {
|
).then(() => {
|
||||||
finished(true);
|
finished(true);
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
console.error(
|
logger.error(
|
||||||
'Error downloading keys for ' + users + ":", e,
|
'Error downloading keys for ' + users + ":", e,
|
||||||
);
|
);
|
||||||
finished(false);
|
finished(false);
|
||||||
@@ -573,7 +574,7 @@ export default class DeviceList {
|
|||||||
// since we started this request. If that happens, we should
|
// since we started this request. If that happens, we should
|
||||||
// ignore the completion of the first one.
|
// ignore the completion of the first one.
|
||||||
if (this._keyDownloadsInProgressByUser[u] !== prom) {
|
if (this._keyDownloadsInProgressByUser[u] !== prom) {
|
||||||
console.log('Another update in the queue for', u,
|
logger.log('Another update in the queue for', u,
|
||||||
'- not marking up-to-date');
|
'- not marking up-to-date');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -584,7 +585,7 @@ export default class DeviceList {
|
|||||||
// we didn't get any new invalidations since this download started:
|
// we didn't get any new invalidations since this download started:
|
||||||
// this user's device list is now up to date.
|
// this user's device list is now up to date.
|
||||||
this._deviceTrackingStatus[u] = TRACKING_STATUS_UP_TO_DATE;
|
this._deviceTrackingStatus[u] = TRACKING_STATUS_UP_TO_DATE;
|
||||||
console.log("Device list for", u, "now up to date");
|
logger.log("Device list for", u, "now up to date");
|
||||||
} else {
|
} else {
|
||||||
this._deviceTrackingStatus[u] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
this._deviceTrackingStatus[u] = TRACKING_STATUS_PENDING_DOWNLOAD;
|
||||||
}
|
}
|
||||||
@@ -659,7 +660,7 @@ class DeviceListUpdateSerialiser {
|
|||||||
|
|
||||||
if (this._downloadInProgress) {
|
if (this._downloadInProgress) {
|
||||||
// just queue up these users
|
// just queue up these users
|
||||||
console.log('Queued key download for', users);
|
logger.log('Queued key download for', users);
|
||||||
return this._queuedQueryDeferred.promise;
|
return this._queuedQueryDeferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +680,7 @@ class DeviceListUpdateSerialiser {
|
|||||||
const deferred = this._queuedQueryDeferred;
|
const deferred = this._queuedQueryDeferred;
|
||||||
this._queuedQueryDeferred = null;
|
this._queuedQueryDeferred = null;
|
||||||
|
|
||||||
console.log('Starting key download for', downloadUsers);
|
logger.log('Starting key download for', downloadUsers);
|
||||||
this._downloadInProgress = true;
|
this._downloadInProgress = true;
|
||||||
|
|
||||||
const opts = {};
|
const opts = {};
|
||||||
@@ -706,7 +707,7 @@ class DeviceListUpdateSerialiser {
|
|||||||
|
|
||||||
return prom;
|
return prom;
|
||||||
}).done(() => {
|
}).done(() => {
|
||||||
console.log('Completed key download for ' + downloadUsers);
|
logger.log('Completed key download for ' + downloadUsers);
|
||||||
|
|
||||||
this._downloadInProgress = false;
|
this._downloadInProgress = false;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
@@ -716,7 +717,7 @@ class DeviceListUpdateSerialiser {
|
|||||||
this._doQueuedQueries();
|
this._doQueuedQueries();
|
||||||
}
|
}
|
||||||
}, (e) => {
|
}, (e) => {
|
||||||
console.warn('Error downloading keys for ' + downloadUsers + ':', e);
|
logger.warn('Error downloading keys for ' + downloadUsers + ':', e);
|
||||||
this._downloadInProgress = false;
|
this._downloadInProgress = false;
|
||||||
deferred.reject(e);
|
deferred.reject(e);
|
||||||
});
|
});
|
||||||
@@ -725,7 +726,7 @@ class DeviceListUpdateSerialiser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _processQueryResponseForUser(userId, response) {
|
async _processQueryResponseForUser(userId, response) {
|
||||||
console.log('got keys for ' + userId + ':', response);
|
logger.log('got keys for ' + userId + ':', response);
|
||||||
|
|
||||||
// map from deviceid -> deviceinfo for this user
|
// map from deviceid -> deviceinfo for this user
|
||||||
const userStore = {};
|
const userStore = {};
|
||||||
@@ -763,7 +764,7 @@ async function _updateStoredDeviceKeysForUser(_olmDevice, userId, userStore,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(deviceId in userResult)) {
|
if (!(deviceId in userResult)) {
|
||||||
console.log("Device " + userId + ":" + deviceId +
|
logger.log("Device " + userId + ":" + deviceId +
|
||||||
" has been removed");
|
" has been removed");
|
||||||
delete userStore[deviceId];
|
delete userStore[deviceId];
|
||||||
updated = true;
|
updated = true;
|
||||||
@@ -780,12 +781,12 @@ async function _updateStoredDeviceKeysForUser(_olmDevice, userId, userStore,
|
|||||||
// check that the user_id and device_id in the response object are
|
// check that the user_id and device_id in the response object are
|
||||||
// correct
|
// correct
|
||||||
if (deviceResult.user_id !== userId) {
|
if (deviceResult.user_id !== userId) {
|
||||||
console.warn("Mismatched user_id " + deviceResult.user_id +
|
logger.warn("Mismatched user_id " + deviceResult.user_id +
|
||||||
" in keys from " + userId + ":" + deviceId);
|
" in keys from " + userId + ":" + deviceId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (deviceResult.device_id !== deviceId) {
|
if (deviceResult.device_id !== deviceId) {
|
||||||
console.warn("Mismatched device_id " + deviceResult.device_id +
|
logger.warn("Mismatched device_id " + deviceResult.device_id +
|
||||||
" in keys from " + userId + ":" + deviceId);
|
" in keys from " + userId + ":" + deviceId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -815,7 +816,7 @@ async function _storeDeviceKeys(_olmDevice, userStore, deviceResult) {
|
|||||||
const signKeyId = "ed25519:" + deviceId;
|
const signKeyId = "ed25519:" + deviceId;
|
||||||
const signKey = deviceResult.keys[signKeyId];
|
const signKey = deviceResult.keys[signKeyId];
|
||||||
if (!signKey) {
|
if (!signKey) {
|
||||||
console.warn("Device " + userId + ":" + deviceId +
|
logger.warn("Device " + userId + ":" + deviceId +
|
||||||
" has no ed25519 key");
|
" has no ed25519 key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -825,7 +826,7 @@ async function _storeDeviceKeys(_olmDevice, userStore, deviceResult) {
|
|||||||
try {
|
try {
|
||||||
await olmlib.verifySignature(_olmDevice, deviceResult, userId, deviceId, signKey);
|
await olmlib.verifySignature(_olmDevice, deviceResult, userId, deviceId, signKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Unable to verify signature on device " +
|
logger.warn("Unable to verify signature on device " +
|
||||||
userId + ":" + deviceId + ":" + e);
|
userId + ":" + deviceId + ":" + e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -842,7 +843,7 @@ async function _storeDeviceKeys(_olmDevice, userStore, deviceResult) {
|
|||||||
// best off sticking with the original keys.
|
// best off sticking with the original keys.
|
||||||
//
|
//
|
||||||
// Should we warn the user about it somehow?
|
// Should we warn the user about it somehow?
|
||||||
console.warn("Ed25519 key for device " + userId + ":" +
|
logger.warn("Ed25519 key for device " + userId + ":" +
|
||||||
deviceId + " has changed");
|
deviceId + " has changed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import logger from '../logger';
|
||||||
import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
|
import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,7 +174,7 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
// Migrate from sessionStore
|
// Migrate from sessionStore
|
||||||
pickledAccount = this._sessionStore.getEndToEndAccount();
|
pickledAccount = this._sessionStore.getEndToEndAccount();
|
||||||
if (pickledAccount !== null) {
|
if (pickledAccount !== null) {
|
||||||
console.log("Migrating account from session store");
|
logger.log("Migrating account from session store");
|
||||||
this._cryptoStore.storeAccount(txn, pickledAccount);
|
this._cryptoStore.storeAccount(txn, pickledAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,7 +196,7 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
// has run against the same localstorage and created some spurious sessions.
|
// has run against the same localstorage and created some spurious sessions.
|
||||||
this._cryptoStore.countEndToEndSessions(txn, (count) => {
|
this._cryptoStore.countEndToEndSessions(txn, (count) => {
|
||||||
if (count) {
|
if (count) {
|
||||||
console.log("Crypto store already has sessions: not migrating");
|
logger.log("Crypto store already has sessions: not migrating");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let numSessions = 0;
|
let numSessions = 0;
|
||||||
@@ -207,7 +208,7 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(
|
logger.log(
|
||||||
"Migrating " + numSessions + " sessions from session store",
|
"Migrating " + numSessions + " sessions from session store",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -236,14 +237,14 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
), txn,
|
), txn,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
"Failed to migrate session " + s.senderKey + "/" +
|
"Failed to migrate session " + s.senderKey + "/" +
|
||||||
s.sessionId + ": " + e.stack || e,
|
s.sessionId + ": " + e.stack || e,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
++numIbSessions;
|
++numIbSessions;
|
||||||
}
|
}
|
||||||
console.log(
|
logger.log(
|
||||||
"Migrated " + numIbSessions +
|
"Migrated " + numIbSessions +
|
||||||
" inbound group sessions from session store",
|
" inbound group sessions from session store",
|
||||||
);
|
);
|
||||||
@@ -889,7 +890,7 @@ OlmDevice.prototype.addInboundGroupSession = async function(
|
|||||||
roomId, senderKey, sessionId, txn,
|
roomId, senderKey, sessionId, txn,
|
||||||
(existingSession, existingSessionData) => {
|
(existingSession, existingSessionData) => {
|
||||||
if (existingSession) {
|
if (existingSession) {
|
||||||
console.log(
|
logger.log(
|
||||||
"Update for megolm session " + senderKey + "/" + sessionId,
|
"Update for megolm session " + senderKey + "/" + sessionId,
|
||||||
);
|
);
|
||||||
// for now we just ignore updates. TODO: implement something here
|
// for now we just ignore updates. TODO: implement something here
|
||||||
@@ -1034,7 +1035,7 @@ OlmDevice.prototype.hasInboundSessionKeys = async function(roomId, senderKey, se
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (roomId !== sessionData.room_id) {
|
if (roomId !== sessionData.room_id) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`requested keys for inbound group session ${senderKey}|` +
|
`requested keys for inbound group session ${senderKey}|` +
|
||||||
`${sessionId}, with incorrect room_id ` +
|
`${sessionId}, with incorrect room_id ` +
|
||||||
`(expected ${sessionData.room_id}, ` +
|
`(expected ${sessionData.room_id}, ` +
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../logger';
|
||||||
import utils from '../utils';
|
import utils from '../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,7 +109,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
* Called when the client is stopped. Stops any running background processes.
|
* Called when the client is stopped. Stops any running background processes.
|
||||||
*/
|
*/
|
||||||
stop() {
|
stop() {
|
||||||
console.log('stopping OutgoingRoomKeyRequestManager');
|
logger.log('stopping OutgoingRoomKeyRequestManager');
|
||||||
// stop the timer on the next run
|
// stop the timer on the next run
|
||||||
this._clientRunning = false;
|
this._clientRunning = false;
|
||||||
}
|
}
|
||||||
@@ -173,7 +174,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
// may have seen it, so we still need to send a cancellation
|
// may have seen it, so we still need to send a cancellation
|
||||||
// in that case :/
|
// in that case :/
|
||||||
|
|
||||||
console.log(
|
logger.log(
|
||||||
'deleting unnecessary room key request for ' +
|
'deleting unnecessary room key request for ' +
|
||||||
stringifyRequestBody(requestBody),
|
stringifyRequestBody(requestBody),
|
||||||
);
|
);
|
||||||
@@ -201,7 +202,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
// the request cancelled. There is no point in
|
// the request cancelled. There is no point in
|
||||||
// sending another cancellation since the other tab
|
// sending another cancellation since the other tab
|
||||||
// will do it.
|
// will do it.
|
||||||
console.log(
|
logger.log(
|
||||||
'Tried to cancel room key request for ' +
|
'Tried to cancel room key request for ' +
|
||||||
stringifyRequestBody(requestBody) +
|
stringifyRequestBody(requestBody) +
|
||||||
' but it was already cancelled in another tab',
|
' but it was already cancelled in another tab',
|
||||||
@@ -222,7 +223,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
updatedReq,
|
updatedReq,
|
||||||
andResend,
|
andResend,
|
||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
console.error(
|
logger.error(
|
||||||
"Error sending room key request cancellation;"
|
"Error sending room key request cancellation;"
|
||||||
+ " will retry later.", e,
|
+ " will retry later.", e,
|
||||||
);
|
);
|
||||||
@@ -261,7 +262,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
// this should only happen if there is an indexeddb error,
|
// this should only happen if there is an indexeddb error,
|
||||||
// in which case we're a bit stuffed anyway.
|
// in which case we're a bit stuffed anyway.
|
||||||
console.warn(
|
logger.warn(
|
||||||
`error in OutgoingRoomKeyRequestManager: ${e}`,
|
`error in OutgoingRoomKeyRequestManager: ${e}`,
|
||||||
);
|
);
|
||||||
}).done();
|
}).done();
|
||||||
@@ -282,7 +283,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Looking for queued outgoing room key requests");
|
logger.log("Looking for queued outgoing room key requests");
|
||||||
|
|
||||||
return this._cryptoStore.getOutgoingRoomKeyRequestByState([
|
return this._cryptoStore.getOutgoingRoomKeyRequestByState([
|
||||||
ROOM_KEY_REQUEST_STATES.CANCELLATION_PENDING,
|
ROOM_KEY_REQUEST_STATES.CANCELLATION_PENDING,
|
||||||
@@ -290,7 +291,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
ROOM_KEY_REQUEST_STATES.UNSENT,
|
ROOM_KEY_REQUEST_STATES.UNSENT,
|
||||||
]).then((req) => {
|
]).then((req) => {
|
||||||
if (!req) {
|
if (!req) {
|
||||||
console.log("No more outgoing room key requests");
|
logger.log("No more outgoing room key requests");
|
||||||
this._sendOutgoingRoomKeyRequestsTimer = null;
|
this._sendOutgoingRoomKeyRequestsTimer = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -312,7 +313,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
// go around the loop again
|
// go around the loop again
|
||||||
return this._sendOutgoingRoomKeyRequests();
|
return this._sendOutgoingRoomKeyRequests();
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error("Error sending room key request; will retry later.", e);
|
logger.error("Error sending room key request; will retry later.", e);
|
||||||
this._sendOutgoingRoomKeyRequestsTimer = null;
|
this._sendOutgoingRoomKeyRequestsTimer = null;
|
||||||
this._startTimer();
|
this._startTimer();
|
||||||
}).done();
|
}).done();
|
||||||
@@ -321,7 +322,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
|
|
||||||
// given a RoomKeyRequest, send it and update the request record
|
// given a RoomKeyRequest, send it and update the request record
|
||||||
_sendOutgoingRoomKeyRequest(req) {
|
_sendOutgoingRoomKeyRequest(req) {
|
||||||
console.log(
|
logger.log(
|
||||||
`Requesting keys for ${stringifyRequestBody(req.requestBody)}` +
|
`Requesting keys for ${stringifyRequestBody(req.requestBody)}` +
|
||||||
` from ${stringifyRecipientList(req.recipients)}` +
|
` from ${stringifyRecipientList(req.recipients)}` +
|
||||||
`(id ${req.requestId})`,
|
`(id ${req.requestId})`,
|
||||||
@@ -347,7 +348,7 @@ export default class OutgoingRoomKeyRequestManager {
|
|||||||
// Given a RoomKeyRequest, cancel it and delete the request record unless
|
// Given a RoomKeyRequest, cancel it and delete the request record unless
|
||||||
// andResend is set, in which case transition to UNSENT.
|
// andResend is set, in which case transition to UNSENT.
|
||||||
_sendOutgoingRoomKeyRequestCancellation(req, andResend) {
|
_sendOutgoingRoomKeyRequestCancellation(req, andResend) {
|
||||||
console.log(
|
logger.log(
|
||||||
`Sending cancellation for key request for ` +
|
`Sending cancellation for key request for ` +
|
||||||
`${stringifyRequestBody(req.requestBody)} to ` +
|
`${stringifyRequestBody(req.requestBody)} to ` +
|
||||||
`${stringifyRecipientList(req.recipients)} ` +
|
`${stringifyRecipientList(req.recipients)} ` +
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
const logger = require("../../logger");
|
||||||
const utils = require("../../utils");
|
const utils = require("../../utils");
|
||||||
const olmlib = require("../olmlib");
|
const olmlib = require("../olmlib");
|
||||||
const base = require("./base");
|
const base = require("./base");
|
||||||
@@ -65,7 +66,7 @@ OutboundSessionInfo.prototype.needsRotation = function(
|
|||||||
if (this.useCount >= rotationPeriodMsgs ||
|
if (this.useCount >= rotationPeriodMsgs ||
|
||||||
sessionLifetime >= rotationPeriodMs
|
sessionLifetime >= rotationPeriodMs
|
||||||
) {
|
) {
|
||||||
console.log(
|
logger.log(
|
||||||
"Rotating megolm session after " + this.useCount +
|
"Rotating megolm session after " + this.useCount +
|
||||||
" messages, " + sessionLifetime + "ms",
|
" messages, " + sessionLifetime + "ms",
|
||||||
);
|
);
|
||||||
@@ -103,7 +104,7 @@ OutboundSessionInfo.prototype.sharedWithTooManyDevices = function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!devicesInRoom.hasOwnProperty(userId)) {
|
if (!devicesInRoom.hasOwnProperty(userId)) {
|
||||||
console.log("Starting new session because we shared with " + userId);
|
logger.log("Starting new session because we shared with " + userId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ OutboundSessionInfo.prototype.sharedWithTooManyDevices = function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!devicesInRoom[userId].hasOwnProperty(deviceId)) {
|
if (!devicesInRoom[userId].hasOwnProperty(deviceId)) {
|
||||||
console.log(
|
logger.log(
|
||||||
"Starting new session because we shared with " +
|
"Starting new session because we shared with " +
|
||||||
userId + ":" + deviceId,
|
userId + ":" + deviceId,
|
||||||
);
|
);
|
||||||
@@ -182,7 +183,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
|
|||||||
if (session && session.needsRotation(self._sessionRotationPeriodMsgs,
|
if (session && session.needsRotation(self._sessionRotationPeriodMsgs,
|
||||||
self._sessionRotationPeriodMs)
|
self._sessionRotationPeriodMs)
|
||||||
) {
|
) {
|
||||||
console.log("Starting new megolm session because we need to rotate.");
|
logger.log("Starting new megolm session because we need to rotate.");
|
||||||
session = null;
|
session = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
console.log(`Starting new megolm session for room ${self._roomId}`);
|
logger.log(`Starting new megolm session for room ${self._roomId}`);
|
||||||
session = await self._prepareNewSession();
|
session = await self._prepareNewSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +320,7 @@ MegolmEncryption.prototype._splitUserDeviceMap = function(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
logger.log(
|
||||||
"share keys with device " + userId + ":" + deviceId,
|
"share keys with device " + userId + ":" + deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -441,10 +442,10 @@ MegolmEncryption.prototype._shareKeyWithDevices = async function(session, device
|
|||||||
await this._encryptAndSendKeysToDevices(
|
await this._encryptAndSendKeysToDevices(
|
||||||
session, key.chain_index, userDeviceMaps[i], payload,
|
session, key.chain_index, userDeviceMaps[i], payload,
|
||||||
);
|
);
|
||||||
console.log(`Completed megolm keyshare in ${this._roomId} `
|
logger.log(`Completed megolm keyshare in ${this._roomId} `
|
||||||
+ `(slice ${i + 1}/${userDeviceMaps.length})`);
|
+ `(slice ${i + 1}/${userDeviceMaps.length})`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`megolm keyshare in ${this._roomId} `
|
logger.log(`megolm keyshare in ${this._roomId} `
|
||||||
+ `(slice ${i + 1}/${userDeviceMaps.length}) failed`);
|
+ `(slice ${i + 1}/${userDeviceMaps.length}) failed`);
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
@@ -463,7 +464,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = async function(session, device
|
|||||||
*/
|
*/
|
||||||
MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) {
|
MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) {
|
||||||
const self = this;
|
const self = this;
|
||||||
console.log(`Starting to encrypt event for ${this._roomId}`);
|
logger.log(`Starting to encrypt event for ${this._roomId}`);
|
||||||
|
|
||||||
return this._getDevicesInRoom(room).then(function(devicesInRoom) {
|
return this._getDevicesInRoom(room).then(function(devicesInRoom) {
|
||||||
// check if any of these devices are not yet known to the user.
|
// check if any of these devices are not yet known to the user.
|
||||||
@@ -782,12 +783,12 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
|||||||
!sessionId ||
|
!sessionId ||
|
||||||
!content.session_key
|
!content.session_key
|
||||||
) {
|
) {
|
||||||
console.error("key event is missing fields");
|
logger.error("key event is missing fields");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!senderKey) {
|
if (!senderKey) {
|
||||||
console.error("key event has no sender key (not encrypted?)");
|
logger.error("key event has no sender key (not encrypted?)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,13 +805,13 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
|||||||
|
|
||||||
senderKey = content.sender_key;
|
senderKey = content.sender_key;
|
||||||
if (!senderKey) {
|
if (!senderKey) {
|
||||||
console.error("forwarded_room_key event is missing sender_key field");
|
logger.error("forwarded_room_key event is missing sender_key field");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ed25519Key = content.sender_claimed_ed25519_key;
|
const ed25519Key = content.sender_claimed_ed25519_key;
|
||||||
if (!ed25519Key) {
|
if (!ed25519Key) {
|
||||||
console.error(
|
logger.error(
|
||||||
`forwarded_room_key_event is missing sender_claimed_ed25519_key field`,
|
`forwarded_room_key_event is missing sender_claimed_ed25519_key field`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@@ -823,7 +824,7 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
|||||||
keysClaimed = event.getKeysClaimed();
|
keysClaimed = event.getKeysClaimed();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Adding key for megolm session ${senderKey}|${sessionId}`);
|
logger.log(`Adding key for megolm session ${senderKey}|${sessionId}`);
|
||||||
this._olmDevice.addInboundGroupSession(
|
this._olmDevice.addInboundGroupSession(
|
||||||
content.room_id, senderKey, forwardingKeyChain, sessionId,
|
content.room_id, senderKey, forwardingKeyChain, sessionId,
|
||||||
content.session_key, keysClaimed,
|
content.session_key, keysClaimed,
|
||||||
@@ -840,7 +841,7 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
|||||||
// have another go at decrypting events sent with this session.
|
// have another go at decrypting events sent with this session.
|
||||||
this._retryDecryption(senderKey, sessionId);
|
this._retryDecryption(senderKey, sessionId);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error(`Error handling m.room_key_event: ${e}`);
|
logger.error(`Error handling m.room_key_event: ${e}`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -882,7 +883,7 @@ MegolmDecryption.prototype.shareKeysWithDevice = function(keyRequest) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
logger.log(
|
||||||
"sharing keys for session " + body.sender_key + "|"
|
"sharing keys for session " + body.sender_key + "|"
|
||||||
+ body.session_id + " with device "
|
+ body.session_id + " with device "
|
||||||
+ userId + ":" + deviceId,
|
+ userId + ":" + deviceId,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
const logger = require("../../logger");
|
||||||
const utils = require("../../utils");
|
const utils = require("../../utils");
|
||||||
const olmlib = require("../olmlib");
|
const olmlib = require("../olmlib");
|
||||||
const DeviceInfo = require("../deviceinfo");
|
const DeviceInfo = require("../deviceinfo");
|
||||||
@@ -273,7 +274,7 @@ OlmDecryption.prototype._decryptMessage = async function(
|
|||||||
const payload = await this._olmDevice.decryptMessage(
|
const payload = await this._olmDevice.decryptMessage(
|
||||||
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
theirDeviceIdentityKey, sessionId, message.type, message.body,
|
||||||
);
|
);
|
||||||
console.log(
|
logger.log(
|
||||||
"Decrypted Olm message from " + theirDeviceIdentityKey +
|
"Decrypted Olm message from " + theirDeviceIdentityKey +
|
||||||
" with session " + sessionId,
|
" with session " + sessionId,
|
||||||
);
|
);
|
||||||
@@ -328,7 +329,7 @@ OlmDecryption.prototype._decryptMessage = async function(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
logger.log(
|
||||||
"created new inbound Olm session ID " +
|
"created new inbound Olm session ID " +
|
||||||
res.session_id + " with " + theirDeviceIdentityKey,
|
res.session_id + " with " + theirDeviceIdentityKey,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ const anotherjson = require('another-json');
|
|||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import {EventEmitter} from 'events';
|
import {EventEmitter} from 'events';
|
||||||
|
|
||||||
|
const logger = require("../logger");
|
||||||
const utils = require("../utils");
|
const utils = require("../utils");
|
||||||
const OlmDevice = require("./OlmDevice");
|
const OlmDevice = require("./OlmDevice");
|
||||||
const olmlib = require("./olmlib");
|
const olmlib = require("./olmlib");
|
||||||
@@ -196,7 +197,7 @@ Crypto.prototype.registerEventHandlers = function(eventEmitter) {
|
|||||||
try {
|
try {
|
||||||
crypto._onRoomMembership(event, member, oldMembership);
|
crypto._onRoomMembership(event, member, oldMembership);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error handling membership change:", e);
|
logger.error("Error handling membership change:", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -381,7 +382,7 @@ function _maybeUploadOneTimeKeys(crypto) {
|
|||||||
// create any more keys.
|
// create any more keys.
|
||||||
return uploadLoop(keyCount);
|
return uploadLoop(keyCount);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error("Error uploading one-time keys", e.stack || e);
|
logger.error("Error uploading one-time keys", e.stack || e);
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
// reset _oneTimeKeyCount to prevent start uploading based on old data.
|
// reset _oneTimeKeyCount to prevent start uploading based on old data.
|
||||||
// it will be set again on the next /sync-response
|
// it will be set again on the next /sync-response
|
||||||
@@ -606,13 +607,13 @@ Crypto.prototype.getEventSenderDeviceInfo = function(event) {
|
|||||||
|
|
||||||
const claimedKey = event.getClaimedEd25519Key();
|
const claimedKey = event.getClaimedEd25519Key();
|
||||||
if (!claimedKey) {
|
if (!claimedKey) {
|
||||||
console.warn("Event " + event.getId() + " claims no ed25519 key: " +
|
logger.warn("Event " + event.getId() + " claims no ed25519 key: " +
|
||||||
"cannot verify sending device");
|
"cannot verify sending device");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (claimedKey !== device.getFingerprint()) {
|
if (claimedKey !== device.getFingerprint()) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
"Event " + event.getId() + " claims ed25519 key " + claimedKey +
|
"Event " + event.getId() + " claims ed25519 key " + claimedKey +
|
||||||
"but sender device has key " + device.getFingerprint());
|
"but sender device has key " + device.getFingerprint());
|
||||||
return null;
|
return null;
|
||||||
@@ -658,7 +659,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
|
|||||||
const existingConfig = this._roomList.getRoomEncryption(roomId);
|
const existingConfig = this._roomList.getRoomEncryption(roomId);
|
||||||
if (existingConfig) {
|
if (existingConfig) {
|
||||||
if (JSON.stringify(existingConfig) != JSON.stringify(config)) {
|
if (JSON.stringify(existingConfig) != JSON.stringify(config)) {
|
||||||
console.error("Ignoring m.room.encryption event which requests " +
|
logger.error("Ignoring m.room.encryption event which requests " +
|
||||||
"a change of config in " + roomId);
|
"a change of config in " + roomId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -705,7 +706,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this._lazyLoadMembers) {
|
if (!this._lazyLoadMembers) {
|
||||||
console.log("Enabling encryption in " + roomId + "; " +
|
logger.log("Enabling encryption in " + roomId + "; " +
|
||||||
"starting to track device lists for all users therein");
|
"starting to track device lists for all users therein");
|
||||||
|
|
||||||
await this.trackRoomDevices(roomId);
|
await this.trackRoomDevices(roomId);
|
||||||
@@ -717,7 +718,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
|
|||||||
this._deviceList.refreshOutdatedDeviceLists();
|
this._deviceList.refreshOutdatedDeviceLists();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Enabling encryption in " + roomId);
|
logger.log("Enabling encryption in " + roomId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -738,7 +739,7 @@ Crypto.prototype.trackRoomDevices = function(roomId) {
|
|||||||
if (!room) {
|
if (!room) {
|
||||||
throw new Error(`Unable to start tracking devices in unknown room ${roomId}`);
|
throw new Error(`Unable to start tracking devices in unknown room ${roomId}`);
|
||||||
}
|
}
|
||||||
console.log(`Starting to track devices for room ${roomId} ...`);
|
logger.log(`Starting to track devices for room ${roomId} ...`);
|
||||||
const members = await room.getEncryptionTargetMembers();
|
const members = await room.getEncryptionTargetMembers();
|
||||||
members.forEach((m) => {
|
members.forEach((m) => {
|
||||||
this._deviceList.startTrackingDeviceList(m.userId);
|
this._deviceList.startTrackingDeviceList(m.userId);
|
||||||
@@ -834,7 +835,7 @@ Crypto.prototype.importRoomKeys = function(keys) {
|
|||||||
return Promise.map(
|
return Promise.map(
|
||||||
keys, (key) => {
|
keys, (key) => {
|
||||||
if (!key.room_id || !key.algorithm) {
|
if (!key.room_id || !key.algorithm) {
|
||||||
console.warn("ignoring room key entry with missing fields", key);
|
logger.warn("ignoring room key entry with missing fields", key);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -963,7 +964,7 @@ Crypto.prototype.requestRoomKey = function(requestBody, recipients) {
|
|||||||
requestBody, recipients,
|
requestBody, recipients,
|
||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
// this normally means we couldn't talk to the store
|
// this normally means we couldn't talk to the store
|
||||||
console.error(
|
logger.error(
|
||||||
'Error requesting key for event', e,
|
'Error requesting key for event', e,
|
||||||
);
|
);
|
||||||
}).done();
|
}).done();
|
||||||
@@ -980,7 +981,7 @@ Crypto.prototype.requestRoomKey = function(requestBody, recipients) {
|
|||||||
Crypto.prototype.cancelRoomKeyRequest = function(requestBody, andResend) {
|
Crypto.prototype.cancelRoomKeyRequest = function(requestBody, andResend) {
|
||||||
this._outgoingRoomKeyRequestManager.cancelRoomKeyRequest(requestBody, andResend)
|
this._outgoingRoomKeyRequestManager.cancelRoomKeyRequest(requestBody, andResend)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.warn("Error clearing pending room key requests", e);
|
logger.warn("Error clearing pending room key requests", e);
|
||||||
}).done();
|
}).done();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -998,7 +999,7 @@ Crypto.prototype.onCryptoEvent = async function(event) {
|
|||||||
// finished processing the sync, in onSyncCompleted.
|
// finished processing the sync, in onSyncCompleted.
|
||||||
await this.setRoomEncryption(roomId, content, true);
|
await this.setRoomEncryption(roomId, content, true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error configuring encryption in room " + roomId +
|
logger.error("Error configuring encryption in room " + roomId +
|
||||||
":", e);
|
":", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1014,7 +1015,7 @@ Crypto.prototype.onSyncWillProcess = async function(syncData) {
|
|||||||
// scratch, so mark everything as untracked. onCryptoEvent will
|
// scratch, so mark everything as untracked. onCryptoEvent will
|
||||||
// be called for all e2e rooms during the processing of the sync,
|
// be called for all e2e rooms during the processing of the sync,
|
||||||
// at which point we'll start tracking all the users of that room.
|
// at which point we'll start tracking all the users of that room.
|
||||||
console.log("Initial sync performed - resetting device tracking state");
|
logger.log("Initial sync performed - resetting device tracking state");
|
||||||
this._deviceList.stopTrackingAllDeviceLists();
|
this._deviceList.stopTrackingAllDeviceLists();
|
||||||
this._roomDeviceTrackingState = {};
|
this._roomDeviceTrackingState = {};
|
||||||
}
|
}
|
||||||
@@ -1132,7 +1133,7 @@ Crypto.prototype._onToDeviceEvent = function(event) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error handling toDeviceEvent:", e);
|
logger.error("Error handling toDeviceEvent:", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1146,7 +1147,7 @@ Crypto.prototype._onRoomKeyEvent = function(event) {
|
|||||||
const content = event.getContent();
|
const content = event.getContent();
|
||||||
|
|
||||||
if (!content.room_id || !content.algorithm) {
|
if (!content.room_id || !content.algorithm) {
|
||||||
console.error("key event is missing fields");
|
logger.error("key event is missing fields");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1184,12 +1185,12 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) {
|
|||||||
// by calling _trackRoomDevices
|
// by calling _trackRoomDevices
|
||||||
if (this._roomDeviceTrackingState[roomId]) {
|
if (this._roomDeviceTrackingState[roomId]) {
|
||||||
if (member.membership == 'join') {
|
if (member.membership == 'join') {
|
||||||
console.log('Join event for ' + member.userId + ' in ' + roomId);
|
logger.log('Join event for ' + member.userId + ' in ' + roomId);
|
||||||
// make sure we are tracking the deviceList for this user
|
// make sure we are tracking the deviceList for this user
|
||||||
this._deviceList.startTrackingDeviceList(member.userId);
|
this._deviceList.startTrackingDeviceList(member.userId);
|
||||||
} else if (member.membership == 'invite' &&
|
} else if (member.membership == 'invite' &&
|
||||||
this._clientStore.getRoom(roomId).shouldEncryptForInvitedMembers()) {
|
this._clientStore.getRoom(roomId).shouldEncryptForInvitedMembers()) {
|
||||||
console.log('Invite event for ' + member.userId + ' in ' + roomId);
|
logger.log('Invite event for ' + member.userId + ' in ' + roomId);
|
||||||
this._deviceList.startTrackingDeviceList(member.userId);
|
this._deviceList.startTrackingDeviceList(member.userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1256,7 +1257,7 @@ Crypto.prototype._processReceivedRoomKeyRequests = async function() {
|
|||||||
this._processReceivedRoomKeyRequestCancellation(cancellation),
|
this._processReceivedRoomKeyRequestCancellation(cancellation),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Error processing room key requsts: ${e}`);
|
logger.error(`Error processing room key requsts: ${e}`);
|
||||||
} finally {
|
} finally {
|
||||||
this._processingRoomKeyRequests = false;
|
this._processingRoomKeyRequests = false;
|
||||||
}
|
}
|
||||||
@@ -1275,13 +1276,13 @@ Crypto.prototype._processReceivedRoomKeyRequest = async function(req) {
|
|||||||
const roomId = body.room_id;
|
const roomId = body.room_id;
|
||||||
const alg = body.algorithm;
|
const alg = body.algorithm;
|
||||||
|
|
||||||
console.log(`m.room_key_request from ${userId}:${deviceId}` +
|
logger.log(`m.room_key_request from ${userId}:${deviceId}` +
|
||||||
` for ${roomId} / ${body.session_id} (id ${req.requestId})`);
|
` for ${roomId} / ${body.session_id} (id ${req.requestId})`);
|
||||||
|
|
||||||
if (userId !== this._userId) {
|
if (userId !== this._userId) {
|
||||||
// TODO: determine if we sent this device the keys already: in
|
// TODO: determine if we sent this device the keys already: in
|
||||||
// which case we can do so again.
|
// which case we can do so again.
|
||||||
console.log("Ignoring room key request from other user for now");
|
logger.log("Ignoring room key request from other user for now");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1291,18 +1292,18 @@ Crypto.prototype._processReceivedRoomKeyRequest = async function(req) {
|
|||||||
// if we don't have a decryptor for this room/alg, we don't have
|
// if we don't have a decryptor for this room/alg, we don't have
|
||||||
// the keys for the requested events, and can drop the requests.
|
// the keys for the requested events, and can drop the requests.
|
||||||
if (!this._roomDecryptors[roomId]) {
|
if (!this._roomDecryptors[roomId]) {
|
||||||
console.log(`room key request for unencrypted room ${roomId}`);
|
logger.log(`room key request for unencrypted room ${roomId}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const decryptor = this._roomDecryptors[roomId][alg];
|
const decryptor = this._roomDecryptors[roomId][alg];
|
||||||
if (!decryptor) {
|
if (!decryptor) {
|
||||||
console.log(`room key request for unknown alg ${alg} in room ${roomId}`);
|
logger.log(`room key request for unknown alg ${alg} in room ${roomId}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await decryptor.hasKeysForKeyRequest(req)) {
|
if (!await decryptor.hasKeysForKeyRequest(req)) {
|
||||||
console.log(
|
logger.log(
|
||||||
`room key request for unknown session ${roomId} / ` +
|
`room key request for unknown session ${roomId} / ` +
|
||||||
body.session_id,
|
body.session_id,
|
||||||
);
|
);
|
||||||
@@ -1316,7 +1317,7 @@ Crypto.prototype._processReceivedRoomKeyRequest = async function(req) {
|
|||||||
// if the device is is verified already, share the keys
|
// if the device is is verified already, share the keys
|
||||||
const device = this._deviceList.getStoredDevice(userId, deviceId);
|
const device = this._deviceList.getStoredDevice(userId, deviceId);
|
||||||
if (device && device.isVerified()) {
|
if (device && device.isVerified()) {
|
||||||
console.log('device is already verified: sharing keys');
|
logger.log('device is already verified: sharing keys');
|
||||||
req.share();
|
req.share();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1333,7 +1334,7 @@ Crypto.prototype._processReceivedRoomKeyRequest = async function(req) {
|
|||||||
Crypto.prototype._processReceivedRoomKeyRequestCancellation = async function(
|
Crypto.prototype._processReceivedRoomKeyRequestCancellation = async function(
|
||||||
cancellation,
|
cancellation,
|
||||||
) {
|
) {
|
||||||
console.log(
|
logger.log(
|
||||||
`m.room_key_request cancellation for ${cancellation.userId}:` +
|
`m.room_key_request cancellation for ${cancellation.userId}:` +
|
||||||
`${cancellation.deviceId} (id ${cancellation.requestId})`,
|
`${cancellation.deviceId} (id ${cancellation.requestId})`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ limitations under the License.
|
|||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
const anotherjson = require('another-json');
|
const anotherjson = require('another-json');
|
||||||
|
|
||||||
|
const logger = require("../logger");
|
||||||
const utils = require("../utils");
|
const utils = require("../utils");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +66,7 @@ module.exports.encryptMessageForDevice = async function(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
logger.log(
|
||||||
"Using sessionid " + sessionId + " for device " +
|
"Using sessionid " + sessionId + " for device " +
|
||||||
recipientUserId + ":" + recipientDevice.deviceId,
|
recipientUserId + ":" + recipientDevice.deviceId,
|
||||||
);
|
);
|
||||||
@@ -190,7 +191,7 @@ module.exports.ensureOlmSessionsForDevices = async function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!oneTimeKey) {
|
if (!oneTimeKey) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
"No one-time keys (alg=" + oneTimeKeyAlgorithm +
|
"No one-time keys (alg=" + oneTimeKeyAlgorithm +
|
||||||
") for device " + userId + ":" + deviceId,
|
") for device " + userId + ":" + deviceId,
|
||||||
);
|
);
|
||||||
@@ -219,7 +220,7 @@ async function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceIn
|
|||||||
deviceInfo.getFingerprint(),
|
deviceInfo.getFingerprint(),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
logger.error(
|
||||||
"Unable to verify signature on one-time key for device " +
|
"Unable to verify signature on one-time key for device " +
|
||||||
userId + ":" + deviceId + ":", e,
|
userId + ":" + deviceId + ":", e,
|
||||||
);
|
);
|
||||||
@@ -233,12 +234,12 @@ async function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceIn
|
|||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// possibly a bad key
|
// possibly a bad key
|
||||||
console.error("Error starting session with device " +
|
logger.error("Error starting session with device " +
|
||||||
userId + ":" + deviceId + ": " + e);
|
userId + ":" + deviceId + ": " + e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Started new sessionid " + sid +
|
logger.log("Started new sessionid " + sid +
|
||||||
" for device " + userId + ":" + deviceId);
|
" for device " + userId + ":" + deviceId);
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../../logger';
|
||||||
import utils from '../../utils';
|
import utils from '../../utils';
|
||||||
|
|
||||||
export const VERSION = 6;
|
export const VERSION = 6;
|
||||||
@@ -38,7 +40,7 @@ export class Backend {
|
|||||||
// attempts to delete the database will block (and subsequent
|
// attempts to delete the database will block (and subsequent
|
||||||
// attempts to re-create it will also block).
|
// attempts to re-create it will also block).
|
||||||
db.onversionchange = (ev) => {
|
db.onversionchange = (ev) => {
|
||||||
console.log(`versionchange for indexeddb ${this._dbName}: closing`);
|
logger.log(`versionchange for indexeddb ${this._dbName}: closing`);
|
||||||
db.close();
|
db.close();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -64,7 +66,7 @@ export class Backend {
|
|||||||
this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => {
|
this._getOutgoingRoomKeyRequest(txn, requestBody, (existing) => {
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// this entry matches the request - return it.
|
// this entry matches the request - return it.
|
||||||
console.log(
|
logger.log(
|
||||||
`already have key request outstanding for ` +
|
`already have key request outstanding for ` +
|
||||||
`${requestBody.room_id} / ${requestBody.session_id}: ` +
|
`${requestBody.room_id} / ${requestBody.session_id}: ` +
|
||||||
`not sending another`,
|
`not sending another`,
|
||||||
@@ -75,7 +77,7 @@ export class Backend {
|
|||||||
|
|
||||||
// we got to the end of the list without finding a match
|
// we got to the end of the list without finding a match
|
||||||
// - add the new request.
|
// - add the new request.
|
||||||
console.log(
|
logger.log(
|
||||||
`enqueueing key request for ${requestBody.room_id} / ` +
|
`enqueueing key request for ${requestBody.room_id} / ` +
|
||||||
requestBody.session_id,
|
requestBody.session_id,
|
||||||
);
|
);
|
||||||
@@ -226,7 +228,7 @@ export class Backend {
|
|||||||
}
|
}
|
||||||
const data = cursor.value;
|
const data = cursor.value;
|
||||||
if (data.state != expectedState) {
|
if (data.state != expectedState) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`Cannot update room key request from ${expectedState} ` +
|
`Cannot update room key request from ${expectedState} ` +
|
||||||
`as it was already updated to ${data.state}`,
|
`as it was already updated to ${data.state}`,
|
||||||
);
|
);
|
||||||
@@ -264,7 +266,7 @@ export class Backend {
|
|||||||
}
|
}
|
||||||
const data = cursor.value;
|
const data = cursor.value;
|
||||||
if (data.state != expectedState) {
|
if (data.state != expectedState) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`Cannot delete room key request in state ${data.state} `
|
`Cannot delete room key request in state ${data.state} `
|
||||||
+ `(expected ${expectedState})`,
|
+ `(expected ${expectedState})`,
|
||||||
);
|
);
|
||||||
@@ -400,7 +402,7 @@ export class Backend {
|
|||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
// ...and this stops it from aborting the transaction
|
// ...and this stops it from aborting the transaction
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
console.log(
|
logger.log(
|
||||||
"Ignoring duplicate inbound group session: " +
|
"Ignoring duplicate inbound group session: " +
|
||||||
senderCurve25519Key + " / " + sessionId,
|
senderCurve25519Key + " / " + sessionId,
|
||||||
);
|
);
|
||||||
@@ -471,7 +473,7 @@ export class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function upgradeDatabase(db, oldVersion) {
|
export function upgradeDatabase(db, oldVersion) {
|
||||||
console.log(
|
logger.log(
|
||||||
`Upgrading IndexedDBCryptoStore from version ${oldVersion}`
|
`Upgrading IndexedDBCryptoStore from version ${oldVersion}`
|
||||||
+ ` to ${VERSION}`,
|
+ ` to ${VERSION}`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../../logger';
|
||||||
import LocalStorageCryptoStore from './localStorage-crypto-store';
|
import LocalStorageCryptoStore from './localStorage-crypto-store';
|
||||||
import MemoryCryptoStore from './memory-crypto-store';
|
import MemoryCryptoStore from './memory-crypto-store';
|
||||||
import * as IndexedDBCryptoStoreBackend from './indexeddb-crypto-store-backend';
|
import * as IndexedDBCryptoStoreBackend from './indexeddb-crypto-store-backend';
|
||||||
@@ -64,7 +65,7 @@ export default class IndexedDBCryptoStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`connecting to indexeddb ${this._dbName}`);
|
logger.log(`connecting to indexeddb ${this._dbName}`);
|
||||||
|
|
||||||
const req = this._indexedDB.open(
|
const req = this._indexedDB.open(
|
||||||
this._dbName, IndexedDBCryptoStoreBackend.VERSION,
|
this._dbName, IndexedDBCryptoStoreBackend.VERSION,
|
||||||
@@ -77,7 +78,7 @@ export default class IndexedDBCryptoStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
req.onblocked = () => {
|
req.onblocked = () => {
|
||||||
console.log(
|
logger.log(
|
||||||
`can't yet open IndexedDBCryptoStore because it is open elsewhere`,
|
`can't yet open IndexedDBCryptoStore because it is open elsewhere`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -89,7 +90,7 @@ export default class IndexedDBCryptoStore {
|
|||||||
req.onsuccess = (r) => {
|
req.onsuccess = (r) => {
|
||||||
const db = r.target.result;
|
const db = r.target.result;
|
||||||
|
|
||||||
console.log(`connected to indexeddb ${this._dbName}`);
|
logger.log(`connected to indexeddb ${this._dbName}`);
|
||||||
resolve(new IndexedDBCryptoStoreBackend.Backend(db));
|
resolve(new IndexedDBCryptoStoreBackend.Backend(db));
|
||||||
};
|
};
|
||||||
}).then((backend) => {
|
}).then((backend) => {
|
||||||
@@ -106,13 +107,13 @@ export default class IndexedDBCryptoStore {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`unable to connect to indexeddb ${this._dbName}` +
|
`unable to connect to indexeddb ${this._dbName}` +
|
||||||
`: falling back to localStorage store: ${e}`,
|
`: falling back to localStorage store: ${e}`,
|
||||||
);
|
);
|
||||||
return new LocalStorageCryptoStore(global.localStorage);
|
return new LocalStorageCryptoStore(global.localStorage);
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`unable to open localStorage: falling back to in-memory store: ${e}`,
|
`unable to open localStorage: falling back to in-memory store: ${e}`,
|
||||||
);
|
);
|
||||||
return new MemoryCryptoStore();
|
return new MemoryCryptoStore();
|
||||||
@@ -133,11 +134,11 @@ export default class IndexedDBCryptoStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Removing indexeddb instance: ${this._dbName}`);
|
logger.log(`Removing indexeddb instance: ${this._dbName}`);
|
||||||
const req = this._indexedDB.deleteDatabase(this._dbName);
|
const req = this._indexedDB.deleteDatabase(this._dbName);
|
||||||
|
|
||||||
req.onblocked = () => {
|
req.onblocked = () => {
|
||||||
console.log(
|
logger.log(
|
||||||
`can't yet delete IndexedDBCryptoStore because it is open elsewhere`,
|
`can't yet delete IndexedDBCryptoStore because it is open elsewhere`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -147,14 +148,14 @@ export default class IndexedDBCryptoStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
req.onsuccess = () => {
|
req.onsuccess = () => {
|
||||||
console.log(`Removed indexeddb instance: ${this._dbName}`);
|
logger.log(`Removed indexeddb instance: ${this._dbName}`);
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
// in firefox, with indexedDB disabled, this fails with a
|
// in firefox, with indexedDB disabled, this fails with a
|
||||||
// DOMError. We treat this as non-fatal, so that people can
|
// DOMError. We treat this as non-fatal, so that people can
|
||||||
// still use the app.
|
// still use the app.
|
||||||
console.warn(`unable to delete IndexedDBCryptoStore: ${e}`);
|
logger.warn(`unable to delete IndexedDBCryptoStore: ${e}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../../logger';
|
||||||
import MemoryCryptoStore from './memory-crypto-store.js';
|
import MemoryCryptoStore from './memory-crypto-store.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,8 +201,8 @@ function getJsonItem(store, key) {
|
|||||||
// JSON.parse(null) === null, so this returns null.
|
// JSON.parse(null) === null, so this returns null.
|
||||||
return JSON.parse(store.getItem(key));
|
return JSON.parse(store.getItem(key));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error: Failed to get key %s: %s", key, e.stack || e);
|
logger.log("Error: Failed to get key %s: %s", key, e.stack || e);
|
||||||
console.log(e.stack);
|
logger.log(e.stack);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
|
import logger from '../../logger';
|
||||||
import utils from '../../utils';
|
import utils from '../../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +72,7 @@ export default class MemoryCryptoStore {
|
|||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// this entry matches the request - return it.
|
// this entry matches the request - return it.
|
||||||
console.log(
|
logger.log(
|
||||||
`already have key request outstanding for ` +
|
`already have key request outstanding for ` +
|
||||||
`${requestBody.room_id} / ${requestBody.session_id}: ` +
|
`${requestBody.room_id} / ${requestBody.session_id}: ` +
|
||||||
`not sending another`,
|
`not sending another`,
|
||||||
@@ -81,7 +82,7 @@ export default class MemoryCryptoStore {
|
|||||||
|
|
||||||
// we got to the end of the list without finding a match
|
// we got to the end of the list without finding a match
|
||||||
// - add the new request.
|
// - add the new request.
|
||||||
console.log(
|
logger.log(
|
||||||
`enqueueing key request for ${requestBody.room_id} / ` +
|
`enqueueing key request for ${requestBody.room_id} / ` +
|
||||||
requestBody.session_id,
|
requestBody.session_id,
|
||||||
);
|
);
|
||||||
@@ -163,7 +164,7 @@ export default class MemoryCryptoStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.state != expectedState) {
|
if (req.state != expectedState) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`Cannot update room key request from ${expectedState} ` +
|
`Cannot update room key request from ${expectedState} ` +
|
||||||
`as it was already updated to ${req.state}`,
|
`as it was already updated to ${req.state}`,
|
||||||
);
|
);
|
||||||
@@ -194,7 +195,7 @@ export default class MemoryCryptoStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.state != expectedState) {
|
if (req.state != expectedState) {
|
||||||
console.warn(
|
logger.warn(
|
||||||
`Cannot delete room key request in state ${req.state} `
|
`Cannot delete room key request in state ${req.state} `
|
||||||
+ `(expected ${expectedState})`,
|
+ `(expected ${expectedState})`,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user