1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-10 07:22:27 +03:00

Apply prettier formatting

This commit is contained in:
Michael Weimann
2022-12-09 09:38:20 +01:00
parent 08a9073bd5
commit 349c2c2587
239 changed files with 22004 additions and 21928 deletions

View File

@@ -18,16 +18,11 @@ limitations under the License.
* Defines m.olm encryption/decryption
*/
import { logger } from '../../logger';
import { logger } from "../../logger";
import * as olmlib from "../olmlib";
import { DeviceInfo } from "../deviceinfo";
import {
DecryptionAlgorithm,
DecryptionError,
EncryptionAlgorithm,
registerAlgorithm,
} from "./base";
import { Room } from '../../models/room';
import { DecryptionAlgorithm, DecryptionError, EncryptionAlgorithm, registerAlgorithm } from "./base";
import { Room } from "../../models/room";
import { IContent, MatrixEvent } from "../../models/event";
import { IEncryptedContent, IEventDecryptionResult, IOlmEncryptedContent } from "../index";
import { IInboundSession } from "../OlmDevice";
@@ -65,13 +60,17 @@ class OlmEncryption extends EncryptionAlgorithm {
return Promise.resolve();
}
this.prepPromise = this.crypto.downloadKeys(roomMembers).then(() => {
return this.crypto.ensureOlmSessionsForUsers(roomMembers);
}).then(() => {
this.sessionPrepared = true;
}).finally(() => {
this.prepPromise = null;
});
this.prepPromise = this.crypto
.downloadKeys(roomMembers)
.then(() => {
return this.crypto.ensureOlmSessionsForUsers(roomMembers);
})
.then(() => {
this.sessionPrepared = true;
})
.finally(() => {
this.prepPromise = null;
});
return this.prepPromise;
}
@@ -89,7 +88,7 @@ class OlmEncryption extends EncryptionAlgorithm {
const members = await room.getEncryptionTargetMembers();
const users = members.map(function(u) {
const users = members.map(function (u) {
return u.userId;
});
@@ -126,8 +125,12 @@ class OlmEncryption extends EncryptionAlgorithm {
promises.push(
olmlib.encryptMessageForDevice(
encryptedContent.ciphertext,
this.userId, this.deviceId, this.olmDevice,
userId, deviceInfo, payloadFields,
this.userId,
this.deviceId,
this.olmDevice,
userId,
deviceInfo,
payloadFields,
),
);
}
@@ -155,17 +158,11 @@ class OlmDecryption extends DecryptionAlgorithm {
const ciphertext = content.ciphertext;
if (!ciphertext) {
throw new DecryptionError(
"OLM_MISSING_CIPHERTEXT",
"Missing ciphertext",
);
throw new DecryptionError("OLM_MISSING_CIPHERTEXT", "Missing ciphertext");
}
if (!(this.olmDevice.deviceCurve25519Key! in ciphertext)) {
throw new DecryptionError(
"OLM_NOT_INCLUDED_IN_RECIPIENTS",
"Not included in recipients",
);
throw new DecryptionError("OLM_NOT_INCLUDED_IN_RECIPIENTS", "Not included in recipients");
}
const message = ciphertext[this.olmDevice.deviceCurve25519Key!];
let payloadString: string;
@@ -173,13 +170,10 @@ class OlmDecryption extends DecryptionAlgorithm {
try {
payloadString = await this.decryptMessage(deviceKey, message);
} catch (e) {
throw new DecryptionError(
"OLM_BAD_ENCRYPTED_MESSAGE",
"Bad Encrypted Message", {
sender: deviceKey,
err: e as Error,
},
);
throw new DecryptionError("OLM_BAD_ENCRYPTED_MESSAGE", "Bad Encrypted Message", {
sender: deviceKey,
err: e as Error,
});
}
const payload = JSON.parse(payloadString);
@@ -187,20 +181,14 @@ class OlmDecryption extends DecryptionAlgorithm {
// check that we were the intended recipient, to avoid unknown-key attack
// https://github.com/vector-im/vector-web/issues/2483
if (payload.recipient != this.userId) {
throw new DecryptionError(
"OLM_BAD_RECIPIENT",
"Message was intented for " + payload.recipient,
);
throw new DecryptionError("OLM_BAD_RECIPIENT", "Message was intented for " + payload.recipient);
}
if (payload.recipient_keys.ed25519 != this.olmDevice.deviceEd25519Key) {
throw new DecryptionError(
"OLM_BAD_RECIPIENT_KEY",
"Message not intended for this device", {
intended: payload.recipient_keys.ed25519,
our_key: this.olmDevice.deviceEd25519Key!,
},
);
throw new DecryptionError("OLM_BAD_RECIPIENT_KEY", "Message not intended for this device", {
intended: payload.recipient_keys.ed25519,
our_key: this.olmDevice.deviceEd25519Key!,
});
}
// check that the device that encrypted the event belongs to the user
@@ -210,17 +198,11 @@ class OlmDecryption extends DecryptionAlgorithm {
// secret sharing, may be more strict and reject events that come from
// unknown devices.
await this.crypto.deviceList.downloadKeys([event.getSender()!], false);
const senderKeyUser = this.crypto.deviceList.getUserByIdentityKey(
olmlib.OLM_ALGORITHM,
deviceKey,
);
const senderKeyUser = this.crypto.deviceList.getUserByIdentityKey(olmlib.OLM_ALGORITHM, deviceKey);
if (senderKeyUser !== event.getSender() && senderKeyUser != undefined) {
throw new DecryptionError(
"OLM_BAD_SENDER",
"Message claimed to be from " + event.getSender(), {
real_sender: senderKeyUser,
},
);
throw new DecryptionError("OLM_BAD_SENDER", "Message claimed to be from " + event.getSender(), {
real_sender: senderKeyUser,
});
}
// check that the original sender matches what the homeserver told us, to
@@ -228,22 +210,16 @@ class OlmDecryption extends DecryptionAlgorithm {
// (this check is also provided via the sender's embedded ed25519 key,
// which is checked elsewhere).
if (payload.sender != event.getSender()) {
throw new DecryptionError(
"OLM_FORWARDED_MESSAGE",
"Message forwarded from " + payload.sender, {
reported_sender: event.getSender()!,
},
);
throw new DecryptionError("OLM_FORWARDED_MESSAGE", "Message forwarded from " + payload.sender, {
reported_sender: event.getSender()!,
});
}
// Olm events intended for a room have a room_id.
if (payload.room_id !== event.getRoomId()) {
throw new DecryptionError(
"OLM_BAD_ROOM",
"Message intended for room " + payload.room_id, {
reported_room: event.getRoomId() || "ROOM_ID_UNDEFINED",
},
);
throw new DecryptionError("OLM_BAD_ROOM", "Message intended for room " + payload.room_id, {
reported_room: event.getRoomId() || "ROOM_ID_UNDEFINED",
});
}
const claimedKeys = payload.keys || {};
@@ -288,16 +264,19 @@ class OlmDecryption extends DecryptionAlgorithm {
for (const sessionId of sessionIds) {
try {
const payload = await this.olmDevice.decryptMessage(
theirDeviceIdentityKey, sessionId, message.type, message.body,
);
logger.log(
"Decrypted Olm message from " + theirDeviceIdentityKey +
" with session " + sessionId,
theirDeviceIdentityKey,
sessionId,
message.type,
message.body,
);
logger.log("Decrypted Olm message from " + theirDeviceIdentityKey + " with session " + sessionId);
return payload;
} catch (e) {
const foundSession = await this.olmDevice.matchesSession(
theirDeviceIdentityKey, sessionId, message.type, message.body,
theirDeviceIdentityKey,
sessionId,
message.type,
message.body,
);
if (foundSession) {
@@ -305,7 +284,9 @@ class OlmDecryption extends DecryptionAlgorithm {
// session, so it should have worked.
throw new Error(
"Error decrypting prekey message with existing session id " +
sessionId + ": " + (<Error>e).message,
sessionId +
": " +
(<Error>e).message,
);
}
@@ -324,8 +305,7 @@ class OlmDecryption extends DecryptionAlgorithm {
}
throw new Error(
"Error decrypting non-prekey message with existing sessions: " +
JSON.stringify(decryptionErrors),
"Error decrypting non-prekey message with existing sessions: " + JSON.stringify(decryptionErrors),
);
}
@@ -334,21 +314,13 @@ class OlmDecryption extends DecryptionAlgorithm {
let res: IInboundSession;
try {
res = await this.olmDevice.createInboundSession(
theirDeviceIdentityKey, message.type, message.body,
);
res = await this.olmDevice.createInboundSession(theirDeviceIdentityKey, message.type, message.body);
} catch (e) {
decryptionErrors["(new)"] = (<Error>e).message;
throw new Error(
"Error decrypting prekey message: " +
JSON.stringify(decryptionErrors),
);
throw new Error("Error decrypting prekey message: " + JSON.stringify(decryptionErrors));
}
logger.log(
"created new inbound Olm session ID " +
res.session_id + " with " + theirDeviceIdentityKey,
);
logger.log("created new inbound Olm session ID " + res.session_id + " with " + theirDeviceIdentityKey);
return res.payload;
}
}