Move protocol protobufs to libaxolotl/, handling DeviceControl
This commit is contained in:
parent
66cf5b08db
commit
184b1ec89c
8 changed files with 102 additions and 67 deletions
|
@ -23,4 +23,49 @@
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
window.textsecure = window.textsecure || {};
|
||||
window.textsecure.protocol_wrapper = {
|
||||
handleIncomingPushMessageProto: function(proto) {
|
||||
var decodeContents = function(res) {
|
||||
var finalMessage = textsecure.protobuf.PushMessageContent.decode(res[0]);
|
||||
|
||||
//TODO
|
||||
/*if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||
textsecure.protocol.closeSession(res[1], true);*/
|
||||
|
||||
return finalMessage;
|
||||
}
|
||||
|
||||
switch(proto.type) {
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.PLAINTEXT:
|
||||
return Promise.resolve(textsecure.protobuf.PushMessageContent.decode(proto.message));
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.CIPHERTEXT:
|
||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||
return textsecure.protocol.decryptWhisperMessage(from, getString(proto.message)).then(decodeContents);
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE:
|
||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||
throw new Error("Bad version byte");
|
||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||
return textsecure.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeContents);
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
||||
return Promise.resolve(null);
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.PREKEY_BUNDLE_DEVICE_CONTROL:
|
||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||
throw new Error("Bad version byte");
|
||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||
return textsecure.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(function(res) {
|
||||
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
||||
});
|
||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.DEVICE_CONTROL:
|
||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||
return textsecure.protocol.decryptWhisperMessage(from, getString(proto.message)).then(function(res) {
|
||||
return textsecure.protobuf.DeviceControl.decode(res[0]);
|
||||
});
|
||||
default:
|
||||
return new Promise(function(resolve, reject) { reject(new Error("Unknown message type")); });
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
};
|
||||
|
||||
var pushMessages = loadProtoBufs('IncomingPushMessageSignal.proto');
|
||||
var protocolMessages = loadProtoBufs('WhisperTextProtocol.proto');
|
||||
var subProtocolMessages = loadProtoBufs('SubProtocol.proto');
|
||||
var deviceMessages = loadProtoBufs('DeviceMessages.proto');
|
||||
|
||||
|
@ -13,8 +12,6 @@
|
|||
window.textsecure.protobuf = {
|
||||
IncomingPushMessageSignal : pushMessages.IncomingPushMessageSignal,
|
||||
PushMessageContent : pushMessages.PushMessageContent,
|
||||
WhisperMessage : protocolMessages.WhisperMessage,
|
||||
PreKeyWhisperMessage : protocolMessages.PreKeyWhisperMessage,
|
||||
ProvisioningUuid : deviceMessages.ProvisioningUuid,
|
||||
ProvisionEnvelope : deviceMessages.ProvisionEnvelope,
|
||||
ProvisionMessage : deviceMessages.ProvisionMessage,
|
||||
|
|
|
@ -31,7 +31,7 @@ describe('Protocol', function() {
|
|||
message: text_message.encode()
|
||||
};
|
||||
|
||||
return textsecure.protocol.handleIncomingPushMessageProto(server_message).
|
||||
return textsecure.protocol_wrapper.handleIncomingPushMessageProto(server_message).
|
||||
then(function(message) {
|
||||
assert.equal(message.body, text_message.body);
|
||||
assert.equal(message.attachments.length, text_message.attachments.length);
|
||||
|
@ -134,7 +134,7 @@ describe('Protocol', function() {
|
|||
message.sourceDevice = 1;
|
||||
try {
|
||||
var proto = textsecure.protobuf.IncomingPushMessageSignal.decode(message.encode());
|
||||
return textsecure.protocol.handleIncomingPushMessageProto(proto).then(function(res) {
|
||||
return textsecure.protocol_wrapper.handleIncomingPushMessageProto(proto).then(function(res) {
|
||||
if (data.expectTerminateSession)
|
||||
return res.flags == textsecure.protobuf.PushMessageContent.Flags.END_SESSION;
|
||||
return res.body == data.expectedSmsText;
|
||||
|
@ -182,11 +182,11 @@ describe('Protocol', function() {
|
|||
//XXX: This should be all we do: isEqual(data.expectedCiphertext, msg.body, false);
|
||||
if (msg.type == 1) {
|
||||
var expected = getString(data.expectedCiphertext);
|
||||
var decoded = textsecure.protobuf.WhisperMessage.decode(expected.substring(1, expected.length - 8), 'binary');
|
||||
var decoded = axolotl.protobuf.WhisperMessage.decode(expected.substring(1, expected.length - 8), 'binary');
|
||||
var result = getString(msg.body);
|
||||
return getString(decoded.encode()) == result.substring(1, result.length - 8);
|
||||
} else {
|
||||
var decoded = textsecure.protobuf.PreKeyWhisperMessage.decode(getString(data.expectedCiphertext).substr(1), 'binary');
|
||||
var decoded = axolotl.protobuf.PreKeyWhisperMessage.decode(getString(data.expectedCiphertext).substr(1), 'binary');
|
||||
var result = getString(msg.body).substring(1);
|
||||
return getString(decoded.encode()) == result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue