You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-18 05:42:00 +03:00
Add the timestamp to decrypted events, update the copy of olm.js
This commit is contained in:
@@ -150,6 +150,9 @@ MatrixClient.prototype.uploadKeys = function(maxKeys, deferred) {
|
||||
deferred = deferred || q.defer();
|
||||
var path = "/keys/upload/" + this.deviceId;
|
||||
var pickled = this.sessionStore.getEndToEndAccount();
|
||||
if (!pickled) {
|
||||
throw new Error("End-to-end account not found");
|
||||
}
|
||||
var account = new Olm.Account();
|
||||
try {
|
||||
account.unpickle(this.accountKey, pickled);
|
||||
@@ -672,7 +675,12 @@ function _decryptMessage(client, event) {
|
||||
if (content.algorithm === OLM_ALGORITHM) {
|
||||
var sender = event.getSender();
|
||||
var deviceKey = content.sender_key;
|
||||
if (!client.deviceCurve25519Key in content.ciphertext) {
|
||||
var ciphertext = content.ciphertext;
|
||||
|
||||
if (!ciphertext) {
|
||||
return _badEncryptedMessage(event, "Missing ciphertext");
|
||||
}
|
||||
if (!(client.deviceCurve25519Key in content.ciphertext)) {
|
||||
return _badEncryptedMessage(event, "Not included in recipients");
|
||||
}
|
||||
var message = content.ciphertext[client.deviceCurve25519Key];
|
||||
@@ -683,8 +691,8 @@ function _decryptMessage(client, event) {
|
||||
var session = new Olm.Session();
|
||||
try {
|
||||
session.unpickle(client.accountKey, sessions[sessionId]);
|
||||
if (message.type == 0 && session.matches(message.body)) {
|
||||
foundSession = true;
|
||||
if (message.type == 0 && session.matches_inbound(message.body)) {
|
||||
foundSession = true;
|
||||
}
|
||||
payloadString = session.decrypt(message.type, message.body);
|
||||
var pickled = session.pickle(client.accountKey);
|
||||
@@ -693,6 +701,7 @@ function _decryptMessage(client, event) {
|
||||
);
|
||||
} catch(e) {
|
||||
// Failed to decrypt with an existing session.
|
||||
console.log("Failed to decrypt with an existing session: " + e.message);
|
||||
} finally {
|
||||
session.free();
|
||||
}
|
||||
@@ -725,11 +734,14 @@ function _decryptMessage(client, event) {
|
||||
if (payloadString !== null) {
|
||||
var payload = JSON.parse(payloadString);
|
||||
return new MatrixEvent({
|
||||
// TODO: Add rest of the event keys.
|
||||
// TODO: Add a key to indicate that the event was encrypted.
|
||||
// TODO: Check the sender user id matches the sender key.
|
||||
origin_server_ts: event.getTs(),
|
||||
room_id: payload.room_id,
|
||||
user_id: event.getSender(),
|
||||
event_id: event.getId(),
|
||||
type: payload.type,
|
||||
content: payload.content,
|
||||
user_id: event.getSender()
|
||||
});
|
||||
} else {
|
||||
return _badEncryptedMessage(event, "Bad Encrypted Message");
|
||||
@@ -741,6 +753,10 @@ function _badEncryptedMessage(event, reason) {
|
||||
return new MatrixEvent({
|
||||
type: "m.room.message",
|
||||
// TODO: Add rest of the event keys.
|
||||
origin_server_ts: event.getTs(),
|
||||
room_id: event.getRoomId(),
|
||||
user_id: event.getSender(),
|
||||
event_id: event.getId(),
|
||||
content: {
|
||||
msgtype: "m.bad.encrypted",
|
||||
body: reason,
|
||||
@@ -1667,6 +1683,11 @@ MatrixClient.prototype.startClient = function(historyLen) {
|
||||
// client is already running.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.sessionStore !== null) {
|
||||
this.uploadKeys(5);
|
||||
}
|
||||
|
||||
if (this.store.getSyncToken()) {
|
||||
// resume from where we left off.
|
||||
_pollForEvents(this);
|
||||
|
Reference in New Issue
Block a user