diff --git a/src/client.js b/src/client.js index 1ba3c4604..72c57d60c 100644 --- a/src/client.js +++ b/src/client.js @@ -946,6 +946,35 @@ MatrixClient.prototype.getGlobalBlacklistUnverifiedDevices = function() { 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 + * symmetry 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 * diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index 911f2311d..42cee48ba 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -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. // 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 payloadJson = { diff --git a/src/crypto/index.js b/src/crypto/index.js index 879bd706d..f47d8877e 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -177,6 +177,7 @@ export default function Crypto(baseApis, sessionStore, userId, deviceId, this._deviceKeys = {}; this._globalBlacklistUnverifiedDevices = false; + this._globalErrorOnUnknownDevices = true; this._outgoingRoomKeyRequestManager = new OutgoingRoomKeyRequestManager( baseApis, this._deviceId, this._cryptoStore, @@ -1210,6 +1211,29 @@ Crypto.prototype.getGlobalBlacklistUnverifiedDevices = function() { 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. * @return {object} A promise that will resolve when the keys are uploaded.