Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a58e7a34e7 | |||
| 7a481beec6 | |||
| d51fad2de4 | |||
| c66755a756 | |||
| 886ad03505 | |||
| ba33ef0a68 | |||
| fe97dc3ece | |||
| 04a3aaee35 | |||
| fef03cda9b | |||
| 3292fde41b | |||
| 38cf25ac5a | |||
| 62c344b633 | |||
| 75ce2729f9 | |||
| 6669554867 | |||
| d3294da37c | |||
| 9b56bf25cf | |||
| e1a33d8a7b | |||
| 47a1224c13 | |||
| 5c57d81e94 | |||
| edefd3ec88 | |||
| f15098efde | |||
| 365bb772bc | |||
| 5ee6ada973 | |||
| ee0fa0e687 | |||
| 0d41f6aafc | |||
| 91b6499815 | |||
| 7cd1166a47 | |||
| f76cb677ff | |||
| 05e7f4e6f7 |
@@ -1,3 +1,20 @@
|
||||
Changes in [5.0.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v5.0.1) (2020-02-19)
|
||||
================================================================================================
|
||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v5.0.0...v5.0.1)
|
||||
|
||||
* add method for new /aliases endpoint
|
||||
[\#1219](https://github.com/matrix-org/matrix-js-sdk/pull/1219)
|
||||
* method for checking if other party supports verification method
|
||||
[\#1213](https://github.com/matrix-org/matrix-js-sdk/pull/1213)
|
||||
* add local echo state for accepting or declining a verif req
|
||||
[\#1210](https://github.com/matrix-org/matrix-js-sdk/pull/1210)
|
||||
* make logging compatible with rageshakes
|
||||
[\#1214](https://github.com/matrix-org/matrix-js-sdk/pull/1214)
|
||||
* Find existing requests when starting a new verification request
|
||||
[\#1209](https://github.com/matrix-org/matrix-js-sdk/pull/1209)
|
||||
* log MAC calculation during SAS
|
||||
[\#1211](https://github.com/matrix-org/matrix-js-sdk/pull/1211)
|
||||
|
||||
Changes in [5.0.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v5.0.0) (2020-02-17)
|
||||
================================================================================================
|
||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v5.0.0-rc.1...v5.0.0)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "matrix-js-sdk",
|
||||
"version": "5.0.0",
|
||||
"version": "5.0.1",
|
||||
"description": "Matrix Client-Server SDK for Javascript",
|
||||
"scripts": {
|
||||
"prepare": "yarn build",
|
||||
|
||||
@@ -1119,6 +1119,21 @@ MatrixBaseApis.prototype.deleteAlias = function(alias, callback) {
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} roomId
|
||||
* @param {module:client.callback} callback Optional.
|
||||
* @return {Promise} Resolves: an object with an `aliases` property, containing an array of local aliases
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
*/
|
||||
MatrixBaseApis.prototype.unstableGetLocalAliases =
|
||||
function(roomId, callback) {
|
||||
const path = utils.encodeUri("/rooms/$roomId/aliases",
|
||||
{$roomId: roomId});
|
||||
const prefix = PREFIX_UNSTABLE + "/org.matrix.msc2432";
|
||||
return this._http.authedRequest(callback, "GET", path,
|
||||
null, null, { prefix });
|
||||
};
|
||||
|
||||
/**
|
||||
* Get room info for the given alias.
|
||||
* @param {string} alias The room alias to resolve.
|
||||
|
||||
@@ -918,6 +918,20 @@ MatrixClient.prototype.requestVerificationDM = function(userId, roomId) {
|
||||
return this._crypto.requestVerificationDM(userId, roomId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds a DM verification request that is already in progress for the given room id
|
||||
*
|
||||
* @param {string} roomId the room to use for verification
|
||||
*
|
||||
* @returns {module:crypto/verification/request/VerificationRequest?} the VerificationRequest that is in progress, if any
|
||||
*/
|
||||
MatrixClient.prototype.findVerificationRequestDMInProgress = function(roomId) {
|
||||
if (this._crypto === null) {
|
||||
throw new Error("End-to-end encryption disabled");
|
||||
}
|
||||
return this._crypto.findVerificationRequestDMInProgress(roomId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Request a key verification from another user.
|
||||
*
|
||||
@@ -4783,6 +4797,19 @@ MatrixClient.prototype.doesServerSupportSeparateAddAndBind = async function() {
|
||||
|| (unstableFeatures && unstableFeatures["m.separate_add_and_bind"]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Query the server to see if it lists support for an unstable feature
|
||||
* in the /versions response
|
||||
* @param {string} feature the feature name
|
||||
* @return {Promise<boolean>} true if the feature is supported
|
||||
*/
|
||||
MatrixClient.prototype.doesServerSupportUnstableFeature = async function(feature) {
|
||||
const response = await this.getVersions();
|
||||
if (!response) return false;
|
||||
const unstableFeatures = response["unstable_features"];
|
||||
return unstableFeatures && !!unstableFeatures[feature];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get if lazy loading members is being used.
|
||||
* @return {boolean} Whether or not members are lazy loaded by this client
|
||||
|
||||
@@ -1619,7 +1619,16 @@ Crypto.prototype.setDeviceVerification = async function(
|
||||
return deviceObj;
|
||||
};
|
||||
|
||||
Crypto.prototype.findVerificationRequestDMInProgress = function(roomId) {
|
||||
return this._inRoomVerificationRequests.findRequestInProgress(roomId);
|
||||
};
|
||||
|
||||
Crypto.prototype.requestVerificationDM = function(userId, roomId) {
|
||||
const existingRequest = this._inRoomVerificationRequests.
|
||||
findRequestInProgress(roomId);
|
||||
if (existingRequest) {
|
||||
return Promise.resolve(existingRequest);
|
||||
}
|
||||
const channel = new InRoomChannel(this._baseApis, roomId, userId);
|
||||
return this._requestVerificationWithChannel(
|
||||
userId,
|
||||
@@ -1632,6 +1641,11 @@ Crypto.prototype.requestVerification = function(userId, devices) {
|
||||
if (!devices) {
|
||||
devices = Object.keys(this._deviceList.getRawStoredDevicesForUser(userId));
|
||||
}
|
||||
const existingRequest = this._toDeviceVerificationRequests
|
||||
.findRequestInProgress(userId, devices);
|
||||
if (existingRequest) {
|
||||
return Promise.resolve(existingRequest);
|
||||
}
|
||||
const channel = new ToDeviceChannel(this._baseApis, userId, devices);
|
||||
return this._requestVerificationWithChannel(
|
||||
userId,
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
newUnknownMethodError,
|
||||
newUserCancelledError,
|
||||
} from './Error';
|
||||
import {logger} from '../../logger';
|
||||
|
||||
const START_TYPE = "m.key.verification.start";
|
||||
|
||||
@@ -165,6 +166,15 @@ const macMethods = {
|
||||
"hmac-sha256": "calculate_mac_long_kdf",
|
||||
};
|
||||
|
||||
function calculateMAC(olmSAS, method) {
|
||||
return function(...args) {
|
||||
const macFunction = olmSAS[macMethods[method]];
|
||||
const mac = macFunction.apply(olmSAS, args);
|
||||
logger.log("SAS calculateMAC:", method, args, mac);
|
||||
return mac;
|
||||
};
|
||||
}
|
||||
|
||||
/* lists of algorithms/methods that are supported. The key agreement, hashes,
|
||||
* and MAC lists should be sorted in order of preference (most preferred
|
||||
* first).
|
||||
@@ -306,7 +316,7 @@ export class SAS extends Base {
|
||||
+ this._channel.transactionId;
|
||||
const sasBytes = olmSAS.generate_bytes(sasInfo, 6);
|
||||
const verifySAS = new Promise((resolve, reject) => {
|
||||
this.emit("show_sas", {
|
||||
this.sasEvent = {
|
||||
sas: generateSas(sasBytes, sasMethods),
|
||||
confirm: () => {
|
||||
this._sendMAC(olmSAS, macMethod);
|
||||
@@ -314,7 +324,8 @@ export class SAS extends Base {
|
||||
},
|
||||
cancel: () => reject(newUserCancelledError()),
|
||||
mismatch: () => reject(newMismatchedSASError()),
|
||||
});
|
||||
};
|
||||
this.emit("show_sas", this.sasEvent);
|
||||
});
|
||||
|
||||
|
||||
@@ -390,7 +401,7 @@ export class SAS extends Base {
|
||||
+ this._channel.transactionId;
|
||||
const sasBytes = olmSAS.generate_bytes(sasInfo, 6);
|
||||
const verifySAS = new Promise((resolve, reject) => {
|
||||
this.emit("show_sas", {
|
||||
this.sasEvent = {
|
||||
sas: generateSas(sasBytes, sasMethods),
|
||||
confirm: () => {
|
||||
this._sendMAC(olmSAS, macMethod);
|
||||
@@ -398,7 +409,8 @@ export class SAS extends Base {
|
||||
},
|
||||
cancel: () => reject(newUserCancelledError()),
|
||||
mismatch: () => reject(newMismatchedSASError()),
|
||||
});
|
||||
};
|
||||
this.emit("show_sas", this.sasEvent);
|
||||
});
|
||||
|
||||
|
||||
@@ -429,7 +441,7 @@ export class SAS extends Base {
|
||||
+ this._channel.transactionId;
|
||||
|
||||
const deviceKeyId = `ed25519:${this._baseApis.deviceId}`;
|
||||
mac[deviceKeyId] = olmSAS[macMethods[method]](
|
||||
mac[deviceKeyId] = calculateMAC(olmSAS, method)(
|
||||
this._baseApis.getDeviceEd25519Key(),
|
||||
baseInfo + deviceKeyId,
|
||||
);
|
||||
@@ -438,14 +450,14 @@ export class SAS extends Base {
|
||||
const crossSigningId = this._baseApis.getCrossSigningId();
|
||||
if (crossSigningId) {
|
||||
const crossSigningKeyId = `ed25519:${crossSigningId}`;
|
||||
mac[crossSigningKeyId] = olmSAS[macMethods[method]](
|
||||
mac[crossSigningKeyId] = calculateMAC(olmSAS, method)(
|
||||
crossSigningId,
|
||||
baseInfo + crossSigningKeyId,
|
||||
);
|
||||
keyList.push(crossSigningKeyId);
|
||||
}
|
||||
|
||||
const keys = olmSAS[macMethods[method]](
|
||||
const keys = calculateMAC(olmSAS, method)(
|
||||
keyList.sort().join(","),
|
||||
baseInfo + "KEY_IDS",
|
||||
);
|
||||
@@ -458,7 +470,7 @@ export class SAS extends Base {
|
||||
+ this._baseApis.getUserId() + this._baseApis.deviceId
|
||||
+ this._channel.transactionId;
|
||||
|
||||
if (content.keys !== olmSAS[macMethods[method]](
|
||||
if (content.keys !== calculateMAC(olmSAS, method)(
|
||||
Object.keys(content.mac).sort().join(","),
|
||||
baseInfo + "KEY_IDS",
|
||||
)) {
|
||||
@@ -466,7 +478,7 @@ export class SAS extends Base {
|
||||
}
|
||||
|
||||
await this._verifyKeys(this.userId, content.mac, (keyId, device, keyInfo) => {
|
||||
if (keyInfo !== olmSAS[macMethods[method]](
|
||||
if (keyInfo !== calculateMAC(olmSAS, method)(
|
||||
device.keys[keyId],
|
||||
baseInfo + keyId,
|
||||
)) {
|
||||
|
||||
@@ -305,7 +305,6 @@ export class InRoomRequests {
|
||||
getRequest(event) {
|
||||
const roomId = event.getRoomId();
|
||||
const txnId = InRoomChannel.getTransactionId(event);
|
||||
// console.log(`looking for request in room ${roomId} with txnId ${txnId} for an ${event.getType()} from ${event.getSender()}...`);
|
||||
return this._getRequestByTxnId(roomId, txnId);
|
||||
}
|
||||
|
||||
@@ -351,4 +350,15 @@ export class InRoomRequests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
findRequestInProgress(roomId) {
|
||||
const requestsByTxnId = this._requestsByRoomId.get(roomId);
|
||||
if (requestsByTxnId) {
|
||||
for (const request of requestsByTxnId.values()) {
|
||||
if (request.pending) {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,20 @@ export class ToDeviceChannel {
|
||||
this._deviceId = deviceId;
|
||||
}
|
||||
|
||||
isToDevices(devices) {
|
||||
if (devices.length === this._devices.length) {
|
||||
for (const device of devices) {
|
||||
const d = this._devices.find(d => d.deviceId === device.deviceId);
|
||||
if (!d) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get deviceId() {
|
||||
return this._deviceId;
|
||||
}
|
||||
@@ -335,4 +349,15 @@ export class ToDeviceRequests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
findRequestInProgress(userId, devices) {
|
||||
const requestsByTxnId = this._requestsByUserId.get(userId);
|
||||
if (requestsByTxnId) {
|
||||
for (const request of requestsByTxnId.values()) {
|
||||
if (request.pending && request.channel.isToDevices(devices)) {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ export class VerificationRequest extends EventEmitter {
|
||||
this._observeOnly = false;
|
||||
this._timeoutTimer = null;
|
||||
this._sharedSecret = null; // used for QR codes
|
||||
this._accepting = false;
|
||||
this._declining = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,10 +181,50 @@ export class VerificationRequest extends EventEmitter {
|
||||
return this._verifier;
|
||||
}
|
||||
|
||||
get canAccept() {
|
||||
return this.phase < PHASE_READY && !this._accepting && !this._declining;
|
||||
}
|
||||
|
||||
get accepting() {
|
||||
return this._accepting;
|
||||
}
|
||||
|
||||
get declining() {
|
||||
return this._declining;
|
||||
}
|
||||
|
||||
/** whether this request has sent it's initial event and needs more events to complete */
|
||||
get pending() {
|
||||
return this._phase !== PHASE_DONE
|
||||
&& this._phase !== PHASE_CANCELLED;
|
||||
return !this.observeOnly &&
|
||||
this._phase !== PHASE_DONE &&
|
||||
this._phase !== PHASE_CANCELLED;
|
||||
}
|
||||
|
||||
/** Checks whether the other party supports a given verification method.
|
||||
* This is useful when setting up the QR code UI, as it is somewhat asymmetrical:
|
||||
* if the other party supports SCAN_QR, we should show a QR code in the UI, and vice versa.
|
||||
* For methods that need to be supported by both ends, use the `methods` property.
|
||||
* @param {string} method the method to check
|
||||
* @return {bool} whether or not the other party said the supported the method */
|
||||
otherPartySupportsMethod(method) {
|
||||
if (!this.ready && !this.started) {
|
||||
return false;
|
||||
}
|
||||
const theirMethodEvent = this._eventsByThem.get(REQUEST_TYPE) ||
|
||||
this._eventsByThem.get(READY_TYPE);
|
||||
if (!theirMethodEvent) {
|
||||
return false;
|
||||
}
|
||||
const content = theirMethodEvent.getContent();
|
||||
if (!content) {
|
||||
return false;
|
||||
}
|
||||
const {methods} = content;
|
||||
if (!Array.isArray(methods)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return methods.includes(method);
|
||||
}
|
||||
|
||||
/** Whether this request was initiated by the syncing user.
|
||||
@@ -342,6 +384,8 @@ export class VerificationRequest extends EventEmitter {
|
||||
*/
|
||||
async cancel({reason = "User declined", code = "m.user"} = {}) {
|
||||
if (!this.observeOnly && this._phase !== PHASE_CANCELLED) {
|
||||
this._declining = true;
|
||||
this.emit("change");
|
||||
if (this._verifier) {
|
||||
return this._verifier.cancel(errorFactory(code, reason)());
|
||||
} else {
|
||||
@@ -358,6 +402,8 @@ export class VerificationRequest extends EventEmitter {
|
||||
async accept() {
|
||||
if (!this.observeOnly && this.phase === PHASE_REQUESTED && !this.initiatedByMe) {
|
||||
const methods = [...this._verificationMethods.keys()];
|
||||
this._accepting = true;
|
||||
this.emit("change");
|
||||
await this.channel.send(READY_TYPE, {methods});
|
||||
this._generateSharedSecret();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,25 @@ import log from "loglevel";
|
||||
// Part of #332 is introducing a logging library in the first place.
|
||||
const DEFAULT_NAMESPACE = "matrix";
|
||||
|
||||
// because rageshakes in react-sdk hijack the console log, also at module load time,
|
||||
// initializing the logger here races with the initialization of rageshakes.
|
||||
// to avoid the issue, we override the methodFactory of loglevel that binds to the
|
||||
// console methods at initialization time by a factory that looks up the console methods
|
||||
// when logging so we always get the current value of console methods.
|
||||
log.methodFactory = function(methodName, logLevel, loggerName) {
|
||||
return function(...args) {
|
||||
const supportedByConsole = methodName === "error" ||
|
||||
methodName === "warn" ||
|
||||
methodName === "trace" ||
|
||||
methodName === "info";
|
||||
if (supportedByConsole) {
|
||||
return console[methodName](...args);
|
||||
} else {
|
||||
return console.log(...args);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Drop-in replacement for <code>console</code> using {@link https://www.npmjs.com/package/loglevel|loglevel}.
|
||||
* Can be tailored down to specific use cases if needed.
|
||||
|
||||
Reference in New Issue
Block a user