-
-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add getKeysProved and getKeysClaimed methods to MatrixEvent. #206
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -514,21 +514,23 @@ OlmDevice.prototype.getOutboundGroupSessionKey = function(sessionId) { | |
* store an InboundGroupSession in the session store | ||
* | ||
* @param {string} roomId | ||
* @param {string} senderKey | ||
* @param {string} senderCurve25519Key | ||
* @param {string} sessionId | ||
* @param {Olm.InboundGroupSession} session | ||
* @param {object} keysClaimed Other keys the sender claims. | ||
* @private | ||
*/ | ||
OlmDevice.prototype._saveInboundGroupSession = function( | ||
roomId, senderKey, sessionId, session | ||
roomId, senderCurve25519Key, sessionId, session, keysClaimed | ||
) { | ||
var r = { | ||
room_id: roomId, | ||
session: session.pickle(this._pickleKey), | ||
keysClaimed: keysClaimed, | ||
}; | ||
|
||
this._sessionStore.storeEndToEndInboundGroupSession( | ||
senderKey, sessionId, JSON.stringify(r) | ||
senderCurve25519Key, sessionId, JSON.stringify(r) | ||
); | ||
}; | ||
|
||
|
@@ -569,7 +571,12 @@ OlmDevice.prototype._getInboundGroupSession = function( | |
var session = new Olm.InboundGroupSession(); | ||
try { | ||
session.unpickle(this._pickleKey, r.session); | ||
return {sessionExists: true, result: func(session)}; | ||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The jsdoc is now a lie. |
||
sessionExists: true, | ||
result: func(session), | ||
keysProved: {curve25519: senderKey}, | ||
keysClaimed: r.keysClaimed || {}, | ||
}; | ||
} finally { | ||
session.free(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,17 @@ OlmEncryption.prototype.encryptMessage = function(room, eventType, content) { | |
room_id: room.roomId, | ||
type: eventType, | ||
content: content, | ||
// Include the ED25519 key so that the recipient knows what | ||
// device this message came from. | ||
// We don't need to include the curve25519 key since the | ||
// recipient will already know this from the olm headers. | ||
// When combined with the device keys retrieved from the | ||
// homeserver signed by the ed25519 key this proves that | ||
// the curve25519 key and the ed25519 key are owned by | ||
// the same device. | ||
keys: { | ||
"ed25519": self._olmDevice.deviceEd25519Key | ||
}, | ||
} | ||
); | ||
}); | ||
|
@@ -200,7 +211,13 @@ OlmDecryption.prototype.decryptEvent = function(event) { | |
// TODO: Check the sender user id matches the sender key. | ||
// TODO: check the room_id and fingerprint | ||
if (payloadString !== null) { | ||
return {result: JSON.parse(payloadString), sessionExists: true}; | ||
var payload = JSON.parse(payloadString); | ||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, the jsdoc is now a lie There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see also algorithms/base.js which has yet another copy of the jsdoc. sorry.) |
||
result: payload, | ||
sessionExists: true, | ||
keysProved: {curve25519: deviceKey}, | ||
keysClaimed: payload.keys || {} | ||
}; | ||
} else { | ||
throw new base.DecryptionError("Bad Encrypted Message"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -823,8 +823,11 @@ Crypto.prototype.decryptEvent = function(event) { | |
olmDevice: this._olmDevice, | ||
}); | ||
var r = alg.decryptEvent(event); | ||
var payload = r.result; | ||
payload.keysClaimed = r.keysClaimed; | ||
payload.keysProved = r.keysProved; | ||
if (r.sessionExists) { | ||
return r.result; | ||
return payload; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jsdoc needs an update |
||
} else { | ||
// We've got a message for a session we don't have. | ||
// Maybe the sender forgot to tell us about the session. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -233,12 +233,28 @@ module.exports.MatrixEvent.prototype = { | |
return Boolean(this._clearEvent.type); | ||
}, | ||
|
||
/** | ||
* The curve25519 key that sent this event | ||
* @return {string} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/string/string?/ |
||
*/ | ||
getSenderKey: function() { | ||
if (!this.isEncrypted()) { | ||
return null; | ||
} | ||
var c = this.getWireContent(); | ||
return c.sender_key; | ||
return this.getKeysProved().curve25519 || null; | ||
}, | ||
|
||
/** | ||
* The keys that must have been owned by the sender of this encrypted event. | ||
* @return {object} | ||
*/ | ||
getKeysProved: function() { | ||
return this._clearEvent.keysProved || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not happy with messing about with the contents of |
||
}, | ||
|
||
/** | ||
* The additional keys the sender of this encrypted event claims to possess | ||
* @return {object} | ||
*/ | ||
getKeysClaimed: function() { | ||
return this._clearEvent.keysClaimed || {}; | ||
}, | ||
|
||
getUnsigned: function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addInboundGroupSession
ordecryptGroupMessage
.