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

Add MatrixClient.getEventSenderDeviceInfo()

- a function to get information about the device which sent an event
This commit is contained in:
Richard van der Hoff
2016-09-20 15:31:10 +01:00
parent 6e31319294
commit 78a0aa5d47
2 changed files with 31 additions and 24 deletions

View File

@@ -401,6 +401,21 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
client.emit("deviceVerificationChanged", userId, deviceId);
}
/**
* Get e2e information on the device that sent an event
*
* @param {MatrixEvent} event event to be checked
*
* @return {module:crypto/deviceinfo?}
*/
MatrixClient.prototype.getEventSenderDeviceInfo = function(event) {
if (!this._crypto) {
return null;
}
return this._crypto.getEventSenderDeviceInfo(event);
};
/**
* Check if the sender of an event is verified
*
@@ -410,21 +425,11 @@ function _setDeviceVerification(client, userId, deviceId, verified, blocked) {
* {@link module:client~MatrixClient#setDeviceVerified|setDeviceVerified}.
*/
MatrixClient.prototype.isEventSenderVerified = function(event) {
if (!this._crypto) {
var device = this.getEventSenderDeviceInfo(event);
if (!device) {
return false;
}
var sender_key = event.getSenderKey();
if (!sender_key) {
return false;
}
var algorithm = event.getWireContent().algorithm;
return this._crypto.isSenderKeyVerified(
event.getSender(), algorithm, sender_key
);
return device.isVerified();
};
/**

View File

@@ -611,15 +611,19 @@ Crypto.prototype.getOlmSessionsForUser = function(userId) {
/**
* Identify a device by curve25519 identity key and determine its verification state
* Get the device which sent an event
*
* @param {string} userId owner of the device
* @param {string} algorithm encryption algorithm
* @param {string} sender_key curve25519 key to match
* @param {module:models/event.MatrixEvent} event event to be checked
*
* @return {boolean} true if the device is verified
* @return {module:crypto/deviceinfo?}
*/
Crypto.prototype.isSenderKeyVerified = function(userId, algorithm, sender_key) {
Crypto.prototype.getEventSenderDeviceInfo = function(event) {
var sender_key = event.getSenderKey();
var algorithm = event.getWireContent().algorithm;
if (!sender_key || !algorithm) {
return null;
}
// sender_key is the curve25519 public key of the device, that the event
// purports to have been sent from. It's assumed that, by the time we get here,
@@ -633,11 +637,9 @@ Crypto.prototype.isSenderKeyVerified = function(userId, algorithm, sender_key) {
// So, all we need to do here is look up the device by sender and
// curve25519 key and determine the state of the verification flag.
var device = this.getDeviceByIdentityKey(userId, algorithm, sender_key);
if (!device) {
return false;
}
return device.verified == DeviceVerification.VERIFIED;
return this.getDeviceByIdentityKey(
event.getSender(), algorithm, sender_key
);
};