Return a function instead of a session in decryptWhisperMessage
This commit is contained in:
parent
3e648b0ea0
commit
30dd13e8e3
2 changed files with 20 additions and 10 deletions
|
@ -457,7 +457,7 @@ window.axolotl.protocol = function() {
|
||||||
/*************************
|
/*************************
|
||||||
*** Public crypto API ***
|
*** Public crypto API ***
|
||||||
*************************/
|
*************************/
|
||||||
// returns decrypted plaintext
|
// returns decrypted plaintext and a function that MUST BE CALLED SYNCHRONOUSLY if the message indicates session close
|
||||||
self.decryptWhisperMessage = function(encodedNumber, messageBytes, session, registrationId) {
|
self.decryptWhisperMessage = function(encodedNumber, messageBytes, session, registrationId) {
|
||||||
if (messageBytes[0] != String.fromCharCode((3 << 4) | 3))
|
if (messageBytes[0] != String.fromCharCode((3 << 4) | 3))
|
||||||
throw new Error("Bad version number on WhisperMessage");
|
throw new Error("Bad version number on WhisperMessage");
|
||||||
|
@ -507,7 +507,11 @@ window.axolotl.protocol = function() {
|
||||||
delete session['pendingPreKey'];
|
delete session['pendingPreKey'];
|
||||||
removeOldChains(session);
|
removeOldChains(session);
|
||||||
crypto_storage.saveSession(encodedNumber, session, registrationId);
|
crypto_storage.saveSession(encodedNumber, session, registrationId);
|
||||||
return [plaintext, session];
|
return [plaintext, function() {
|
||||||
|
closeSession(session, true);
|
||||||
|
removeOldChains(session);
|
||||||
|
crypto_storage.saveSession(encodedNumber, session, registrationId);
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,10 +39,20 @@
|
||||||
var decodeMessageContents = function(res) {
|
var decodeMessageContents = function(res) {
|
||||||
var finalMessage = textsecure.protobuf.PushMessageContent.decode(res[0]);
|
var finalMessage = textsecure.protobuf.PushMessageContent.decode(res[0]);
|
||||||
|
|
||||||
//TODO
|
if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
|
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
|
res[1]();
|
||||||
|
|
||||||
|
return finalMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decodeDeviceContents = function(res) {
|
||||||
|
var finalMessage = textsecure.protobuf.DeviceControl.decode(res[0]);
|
||||||
|
|
||||||
|
//TODO: Add END_SESSION flag for device control messages
|
||||||
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
axolotl.protocol.closeSession(res[1], true);*/
|
res[1]();*/
|
||||||
|
|
||||||
return finalMessage;
|
return finalMessage;
|
||||||
}
|
}
|
||||||
|
@ -67,14 +77,10 @@
|
||||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(function(res) {
|
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeDeviceContents);
|
||||||
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
|
||||||
});
|
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
return axolotl.protocol.decryptWhisperMessage(from, getString(proto.message)).then(function(res) {
|
return axolotl.protocol.decryptWhisperMessage(from, getString(proto.message)).then(decodeDeviceContents);
|
||||||
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
|
||||||
});
|
|
||||||
default:
|
default:
|
||||||
return new Promise(function(resolve, reject) { reject(new Error("Unknown message type")); });
|
return new Promise(function(resolve, reject) { reject(new Error("Unknown message type")); });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue