Fix decoding/protos/tests
This commit is contained in:
parent
6a00e8e348
commit
2d12a33ead
3 changed files with 22 additions and 21 deletions
|
@ -603,14 +603,15 @@ window.textsecure.crypto = new function() {
|
||||||
case 0: //TYPE_MESSAGE_PLAINTEXT
|
case 0: //TYPE_MESSAGE_PLAINTEXT
|
||||||
return Promise.resolve(textsecure.protos.decodePushMessageContentProtobuf(getString(proto.message)));
|
return Promise.resolve(textsecure.protos.decodePushMessageContentProtobuf(getString(proto.message)));
|
||||||
case 1: //TYPE_MESSAGE_CIPHERTEXT
|
case 1: //TYPE_MESSAGE_CIPHERTEXT
|
||||||
return decryptWhisperMessage(proto.source + "." + proto.sourceDevice, getString(proto.message));
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
|
return decryptWhisperMessage(from, getString(proto.message));
|
||||||
case 3: //TYPE_MESSAGE_PREKEY_BUNDLE
|
case 3: //TYPE_MESSAGE_PREKEY_BUNDLE
|
||||||
if (proto.message.readUint8() != (2 << 4 | 2))
|
if (proto.message.readUint8() != (2 << 4 | 2))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
var preKeyProto = textsecure.protos.decodePreKeyWhisperMessageProtobuf(getString(proto.message));
|
var preKeyProto = textsecure.protos.decodePreKeyWhisperMessageProtobuf(getString(proto.message));
|
||||||
//XXX: proto.sourceDevice == jsNumber??? (and above)
|
return initSessionFromPreKeyWhisperMessage(from, preKeyProto).then(function(sessions) {
|
||||||
return initSessionFromPreKeyWhisperMessage(proto.source + "." + proto.sourceDevice, preKeyProto).then(function(sessions) {
|
return decryptWhisperMessage(from, getString(preKeyProto.message), sessions[0]).then(function(result) {
|
||||||
return decryptWhisperMessage(proto.source, getString(preKeyProto.message), sessions[0]).then(function(result) {
|
|
||||||
if (sessions[1] !== undefined)
|
if (sessions[1] !== undefined)
|
||||||
crypto_storage.saveSession(proto.source, sessions[1]);
|
crypto_storage.saveSession(proto.source, sessions[1]);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -164,27 +164,27 @@ window.textsecure.protos = function() {
|
||||||
|
|
||||||
self.IncomingPushMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.IncomingPushMessageSignal");
|
self.IncomingPushMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.IncomingPushMessageSignal");
|
||||||
self.decodeIncomingPushMessageProtobuf = function(string) {
|
self.decodeIncomingPushMessageProtobuf = function(string) {
|
||||||
return IncomingPushMessageProtobuf.decode(btoa(string));
|
return self.IncomingPushMessageProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.PushMessageContentProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.PushMessageContent");
|
self.PushMessageContentProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.PushMessageContent");
|
||||||
self.decodePushMessageContentProtobuf = function(string) {
|
self.decodePushMessageContentProtobuf = function(string) {
|
||||||
return PushMessageContentProtobuf.decode(btoa(string));
|
return self.PushMessageContentProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.WhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.WhisperMessage");
|
self.WhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.WhisperMessage");
|
||||||
self.decodeWhisperMessageProtobuf = function(string) {
|
self.decodeWhisperMessageProtobuf = function(string) {
|
||||||
return WhisperMessageProtobuf.decode(btoa(string));
|
return self.WhisperMessageProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.PreKeyWhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.PreKeyWhisperMessage");
|
self.PreKeyWhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.PreKeyWhisperMessage");
|
||||||
self.decodePreKeyWhisperMessageProtobuf = function(string) {
|
self.decodePreKeyWhisperMessageProtobuf = function(string) {
|
||||||
return PreKeyWhisperMessageProtobuf.decode(btoa(string));
|
return self.PreKeyWhisperMessageProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.KeyExchangeMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.KeyExchangeMessage");
|
self.KeyExchangeMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.KeyExchangeMessage");
|
||||||
self.decodeKeyExchangeMessageProtobuf = function(string) {
|
self.decodeKeyExchangeMessageProtobuf = function(string) {
|
||||||
return KeyExchangeMessageProtobuf.decode(btoa(string));
|
return self.KeyExchangeMessageProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
24
js/test.js
24
js/test.js
|
@ -118,8 +118,8 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
source: "+19999999999", timestamp: 42, message: text_message.encode() };
|
source: "+19999999999", timestamp: 42, message: text_message.encode() };
|
||||||
|
|
||||||
return textsecure.crypto.handleIncomingPushMessageProto(server_message).then(function(message) {
|
return textsecure.crypto.handleIncomingPushMessageProto(server_message).then(function(message) {
|
||||||
return (message.message.body == text_message.body &&
|
return (message.body == text_message.body &&
|
||||||
message.message.attachments.length == text_message.attachments.length &&
|
message.attachments.length == text_message.attachments.length &&
|
||||||
text_message.attachments.length == 0);
|
text_message.attachments.length == 0);
|
||||||
});
|
});
|
||||||
}, 'Unencrypted PushMessageProto "decrypt"', true);
|
}, 'Unencrypted PushMessageProto "decrypt"', true);
|
||||||
|
@ -338,10 +338,10 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
|
|
||||||
var message = new textsecure.protos.IncomingPushMessageProtobuf();
|
var message = new textsecure.protos.IncomingPushMessageProtobuf();
|
||||||
message.type = data.type;
|
message.type = data.type;
|
||||||
message.source = remoteDevice.encodedNumber;
|
message.source = textsecure.utils.unencodeNumber(remoteDevice.encodedNumber);
|
||||||
message.message = data.message;
|
message.message = data.message;
|
||||||
return textsecure.crypto.handleIncomingPushMessageProto(textsecure.protos.decodeIncomingPushMessageProtobuf(getString(message.encode()))).then(function(res) {
|
return textsecure.crypto.handleIncomingPushMessageProto(textsecure.protos.decodeIncomingPushMessageProtobuf(getString(message.encode()))).then(function(res) {
|
||||||
return res.message.body == data.expectedSmsText;
|
return res.body == data.expectedSmsText;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
textsecure.storage.putUnencrypted("registrationId", data.registrationId);
|
textsecure.storage.putUnencrypted("registrationId", data.registrationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = new PushMessageContentProtobuf();
|
var message = new textsecure.protos.PushMessageContentProtobuf();
|
||||||
message.body = data.smsText;
|
message.body = data.smsText;
|
||||||
|
|
||||||
return textsecure.crypto.encryptMessageFor(remoteDevice, message).then(function(res) {
|
return textsecure.crypto.encryptMessageFor(remoteDevice, message).then(function(res) {
|
||||||
|
@ -405,7 +405,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, { encodedNumber: "BOB" });
|
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, { encodedNumber: "BOB.0" });
|
||||||
}, "Standard Axolotl Test Vectors as Alice", true);
|
}, "Standard Axolotl Test Vectors as Alice", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
@ -414,11 +414,11 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
axolotlTwoPartyTestVectorsAlice[2][1].newEphemeralKey = t.newEphemeralKey;
|
axolotlTwoPartyTestVectorsAlice[2][1].newEphemeralKey = t.newEphemeralKey;
|
||||||
axolotlTwoPartyTestVectorsAlice[3][1] = t;
|
axolotlTwoPartyTestVectorsAlice[3][1] = t;
|
||||||
delete axolotlTwoPartyTestVectorsAlice[3][1]['newEphemeralKey'];
|
delete axolotlTwoPartyTestVectorsAlice[3][1]['newEphemeralKey'];
|
||||||
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, { encodedNumber: "BOB" });
|
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, { encodedNumber: "BOB.0" });
|
||||||
}, "Shuffled Axolotl Test Vectors as Alice", true);
|
}, "Shuffled Axolotl Test Vectors as Alice", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
return axolotlTestVectors(axolotlTwoPartyTestVectorsBob, { encodedNumber: "ALICE" });
|
return axolotlTestVectors(axolotlTwoPartyTestVectorsBob, { encodedNumber: "ALICE.0" });
|
||||||
}, "Standard Axolotl Test Vectors as Bob", true);
|
}, "Standard Axolotl Test Vectors as Bob", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
@ -440,7 +440,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
v[0][1].newEphemeralKey = orig[0][1].newEphemeralKey;
|
v[0][1].newEphemeralKey = orig[0][1].newEphemeralKey;
|
||||||
|
|
||||||
v[1][1] = { message: orig[0][1].message, type: orig[0][1].type, expectedSmsText: orig[0][1].expectedSmsText };
|
v[1][1] = { message: orig[0][1].message, type: orig[0][1].type, expectedSmsText: orig[0][1].expectedSmsText };
|
||||||
return axolotlTestVectors(v, { encodedNumber: "ALICE" });
|
return axolotlTestVectors(v, { encodedNumber: "ALICE.0" });
|
||||||
}, "Shuffled Axolotl Test Vectors as Bob I", true);
|
}, "Shuffled Axolotl Test Vectors as Bob I", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
@ -457,7 +457,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
v[1] = orig[2];
|
v[1] = orig[2];
|
||||||
v[2] = orig[1];
|
v[2] = orig[1];
|
||||||
|
|
||||||
return axolotlTestVectors(v, { encodedNumber: "ALICE" });
|
return axolotlTestVectors(v, { encodedNumber: "ALICE.0" });
|
||||||
}, "Shuffled Axolotl Test Vectors as Bob II", true);
|
}, "Shuffled Axolotl Test Vectors as Bob II", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
@ -476,7 +476,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
v[2] = orig[3];
|
v[2] = orig[3];
|
||||||
v[3] = orig[4];
|
v[3] = orig[4];
|
||||||
|
|
||||||
return axolotlTestVectors(v, { encodedNumber: "ALICE" });
|
return axolotlTestVectors(v, { encodedNumber: "ALICE.0" });
|
||||||
}, "Shuffled Axolotl Test Vectors as Bob III", true);
|
}, "Shuffled Axolotl Test Vectors as Bob III", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
@ -506,7 +506,7 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
v[2] = orig[3];
|
v[2] = orig[3];
|
||||||
v[3] = orig[4];
|
v[3] = orig[4];
|
||||||
|
|
||||||
return axolotlTestVectors(v, { encodedNumber: "ALICE" });
|
return axolotlTestVectors(v, { encodedNumber: "ALICE.0" });
|
||||||
}, "Shuffled Axolotl Test Vectors as Bob IV", true);
|
}, "Shuffled Axolotl Test Vectors as Bob IV", true);
|
||||||
|
|
||||||
TEST(function() {
|
TEST(function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue