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