1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Add an option to ignore unverified devices

Hopefully all necessary information is on the docstring.

Default behaviour remains unchanged.
This commit is contained in:
David Baker
2020-01-13 17:37:38 +00:00
parent efadf374d6
commit ee51357dbc
3 changed files with 56 additions and 1 deletions

View File

@@ -946,6 +946,35 @@ MatrixClient.prototype.getGlobalBlacklistUnverifiedDevices = function() {
return this._crypto.getGlobalBlacklistUnverifiedDevices(); return this._crypto.getGlobalBlacklistUnverifiedDevices();
}; };
/**
* Set whether sendMessage in a room with unknown and unverified devices
* should throw an error and not send them message. This has 'Global' for
* symmertry with setGlobalBlacklistUnverifiedDevices but there is currently
* no room-level equivalent for this setting.
*
* This API is currently UNSTABLE and may change or be removed without notice.
*
* @param {boolean} value whether error on unknown devices
*/
MatrixClient.prototype.setGlobalErrorOnUnknownDevices = function(value) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
this._crypto.setGlobalErrorOnUnknownDevices(value);
};
/**
* @return {boolean} whether to error on unknown devices
*
* This API is currently UNSTABLE and may change or be removed without notice.
*/
MatrixClient.prototype.getGlobalErrorOnUnknownDevices = function() {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
return this._crypto.getGlobalErrorOnUnknownDevices();
};
/** /**
* Add methods that call the corresponding method in this._crypto * Add methods that call the corresponding method in this._crypto
* *

View File

@@ -736,7 +736,9 @@ MegolmEncryption.prototype.encryptMessage = async function(room, eventType, cont
// 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.
// if so, warn the user so they can verify or ignore. // if so, warn the user so they can verify or ignore.
self._checkForUnknownDevices(devicesInRoom); if (this._crypto.getGlobalErrorOnUnknownDevices()) {
self._checkForUnknownDevices(devicesInRoom);
}
const session = await self._ensureOutboundSession(devicesInRoom, blocked); const session = await self._ensureOutboundSession(devicesInRoom, blocked);
const payloadJson = { const payloadJson = {

View File

@@ -176,6 +176,7 @@ export default function Crypto(baseApis, sessionStore, userId, deviceId,
this._deviceKeys = {}; this._deviceKeys = {};
this._globalBlacklistUnverifiedDevices = false; this._globalBlacklistUnverifiedDevices = false;
this._globalErrorOnUnknownDevices = true;
this._outgoingRoomKeyRequestManager = new OutgoingRoomKeyRequestManager( this._outgoingRoomKeyRequestManager = new OutgoingRoomKeyRequestManager(
baseApis, this._deviceId, this._cryptoStore, baseApis, this._deviceId, this._cryptoStore,
@@ -1190,6 +1191,29 @@ Crypto.prototype.getGlobalBlacklistUnverifiedDevices = function() {
return this._globalBlacklistUnverifiedDevices; return this._globalBlacklistUnverifiedDevices;
}; };
/**
* Set whether sendMessage in a room with unknown and unverified devices
* should throw an error and not send them message. This has 'Global' for
* symmertry with setGlobalBlacklistUnverifiedDevices but there is currently
* no room-level equivalent for this setting.
*
* This API is currently UNSTABLE and may change or be removed without notice.
*
* @param {boolean} value whether error on unknown devices
*/
Crypto.prototype.setGlobalErrorOnUnknownDevices = function(value) {
this._globalErrorOnUnknownDevices = value;
};
/**
* @return {boolean} whether to error on unknown devices
*
* This API is currently UNSTABLE and may change or be removed without notice.
*/
Crypto.prototype.getGlobalErrorOnUnknownDevices = function() {
return this._globalErrorOnUnknownDevices;
};
/** /**
* Upload the device keys to the homeserver. * Upload the device keys to the homeserver.
* @return {object} A promise that will resolve when the keys are uploaded. * @return {object} A promise that will resolve when the keys are uploaded.