Move test shuffling to js/testvectors.js

pull/749/head
Matt Corallo 11 years ago
parent 0088721343
commit 85f33345ab

@ -263,7 +263,7 @@ textsecure.registerOnLoadFunction(function() {
});
}, "HMAC RFC5869 Test vectors");
var axolotlTestVectors = function(v, remoteNumber) {
var runAxolotlTest = function(v) {
var origCreateNewKeyPair = textsecure.crypto.testing_only.createNewKeyPair;
var doStep;
var stepDone;
@ -307,7 +307,7 @@ textsecure.registerOnLoadFunction(function() {
var message = new textsecure.protos.IncomingPushMessageProtobuf();
message.type = data.type;
message.source = remoteNumber;
message.source = "SNOWDEN";
message.message = data.message;
message.sourceDevice = 1;
return textsecure.crypto.handleIncomingPushMessageProto(textsecure.protos.decodeIncomingPushMessageProtobuf(getString(message.encode()))).then(function(res) {
@ -335,11 +335,11 @@ textsecure.registerOnLoadFunction(function() {
textsecure.storage.putUnencrypted("registrationId", data.registrationId);
if (data.getKeys !== undefined)
getKeysForNumberMap[remoteNumber] = data.getKeys;
getKeysForNumberMap["SNOWDEN"] = data.getKeys;
return textsecure.messaging.sendMessageToNumber(remoteNumber, data.smsText, []).then(function() {
var msg = messagesSentMap[remoteNumber + "." + 1];
delete messagesSentMap[remoteNumber + "." + 1];
return textsecure.messaging.sendMessageToNumber("SNOWDEN", data.smsText, []).then(function() {
var msg = messagesSentMap["SNOWDEN.1"];
delete messagesSentMap["SNOWDEN.1"];
//XXX: This should be all we do: isEqual(data.expectedCiphertext, msg.body, false);
if (msg.type == 1) {
var expected = getString(data.expectedCiphertext);
@ -374,115 +374,14 @@ textsecure.registerOnLoadFunction(function() {
return doStep().then(stepDone);
}
for (index in axolotlTestVectors) {
var _ = function(i) {
TEST(function() {
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, "BOB");
}, "Standard Axolotl Test Vectors as Alice", true);
TEST(function() {
var t = axolotlTwoPartyTestVectorsAlice[2][1];
axolotlTwoPartyTestVectorsAlice[2][1] = axolotlTwoPartyTestVectorsAlice[3][1];
axolotlTwoPartyTestVectorsAlice[2][1].newEphemeralKey = t.newEphemeralKey;
axolotlTwoPartyTestVectorsAlice[3][1] = t;
delete axolotlTwoPartyTestVectorsAlice[3][1]['newEphemeralKey'];
return axolotlTestVectors(axolotlTwoPartyTestVectorsAlice, "BOB");
}, "Shuffled Axolotl Test Vectors as Alice", true);
TEST(function() {
return axolotlTestVectors(axolotlTwoPartyTestVectorsBob, "ALICE");
}, "Standard Axolotl Test Vectors as Bob", true);
TEST(function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var orig = axolotlTwoPartyTestVectorsBob;
var v = [];
for (var i = 0; i < axolotlTwoPartyTestVectorsBob.length; i++) {
v[i] = [];
v[i][0] = orig[i][0];
v[i][1] = orig[i][1];
}
// Swap first and second received prekey messages
v[0][1] = { message: orig[1][1].message, type: orig[1][1].type, expectedSmsText: orig[1][1].expectedSmsText };
v[0][1].ourPreKey = orig[0][1].ourPreKey;
v[0][1].preKeyId = orig[0][1].preKeyId;
v[0][1].ourSignedPreKey = orig[0][1].ourSignedPreKey;
v[0][1].signedPreKeyId = orig[0][1].signedPreKeyId;
v[0][1].registrationId = orig[0][1].registrationId;
v[0][1].ourIdentityKey = orig[0][1].ourIdentityKey;
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 };
return axolotlTestVectors(v, "ALICE");
}, "Shuffled Axolotl Test Vectors as Bob I", true);
TEST(function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var orig = axolotlTwoPartyTestVectorsBob;
var v = [];
for (var i = 0; i < axolotlTwoPartyTestVectorsBob.length; i++) {
v[i] = [];
v[i][0] = orig[i][0];
v[i][1] = orig[i][1];
return runAxolotlTest(axolotlTestVectors[i].vectors);
}, axolotlTestVectors[i].name, true);
}(index);
}
// Swap second received prekey msg with the first send
v[1] = orig[2];
v[2] = orig[1];
return axolotlTestVectors(v, "ALICE");
}, "Shuffled Axolotl Test Vectors as Bob II", true);
TEST(function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var orig = axolotlTwoPartyTestVectorsBob;
var v = [];
for (var i = 0; i < axolotlTwoPartyTestVectorsBob.length; i++) {
v[i] = [];
v[i][0] = orig[i][0];
v[i][1] = orig[i][1];
}
// Move second received prekey msg to the end (incl after the first received message in the second chain)
v[4] = orig[1];
v[1] = orig[2];
v[2] = orig[3];
v[3] = orig[4];
return axolotlTestVectors(v, "ALICE");
}, "Shuffled Axolotl Test Vectors as Bob III", true);
TEST(function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var orig = axolotlTwoPartyTestVectorsBob;
var v = [];
for (var i = 0; i < axolotlTwoPartyTestVectorsBob.length; i++) {
v[i] = [];
v[i][0] = orig[i][0];
v[i][1] = orig[i][1];
}
// Move first received prekey msg to the end (incl after the first received message in the second chain)
// ... by first swapping first and second received prekey msg
v[0][1] = { message: orig[1][1].message, type: orig[1][1].type, expectedSmsText: orig[1][1].expectedSmsText };
v[0][1].ourPreKey = orig[0][1].ourPreKey;
v[0][1].preKeyId = orig[0][1].preKeyId;
v[0][1].ourSignedPreKey = orig[0][1].ourSignedPreKey;
v[0][1].signedPreKeyId = orig[0][1].signedPreKeyId;
v[0][1].registrationId = orig[0][1].registrationId;
v[0][1].ourIdentityKey = orig[0][1].ourIdentityKey;
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 };
// ... then moving the (now-second) message to the end
v[4] = v[1];
v[1] = orig[2];
v[2] = orig[3];
v[3] = orig[4];
return axolotlTestVectors(v, "ALICE");
}, "Shuffled Axolotl Test Vectors as Bob IV", true);
TEST(function() {
var key = hexToArrayBuffer('6f35628d65813435534b5d67fbdb54cb33403d04e843103e6399f806cb5df95febbdd61236f33245');
var input = hexToArrayBuffer('752cff52e4b90768558e5369e75d97c69643509a5e5904e0a386cbe4d0970ef73f918f675945a9aefe26daea27587e8dc909dd56fd0468805f834039b345f855cfe19c44b55af241fff3ffcd8045cd5c288e6c4e284c3720570b58e4d47b8feeedc52fd1401f698a209fccfa3b4c0d9a797b046a2759f82a54c41ccd7b5f592b');

@ -5,8 +5,12 @@ function hexToArrayBuffer(str) {
array[i] = parseInt(str.substr(i*2, 2), 16);
return ret;
}
axolotlTestVectors = function() {
// We're gonna throw the finalized tests in here:
var tests = [];
var axolotlTwoPartyTestVectorsAlice = [
// The common-case ALICE test vectors themselves...
var axolotlTwoPartyTestVectorsAlice = [
["sendMessage",
{
smsText: "A",
@ -48,8 +52,28 @@ var axolotlTwoPartyTestVectorsAlice = [
expectedCiphertext: hexToArrayBuffer('330a2105f9f6061f063849e5957880e62b7b96526ab4bae4bf4135ebe5a3c231b7a867421000180122a001989aa9d32f1425eebec0695129d1b0952d79a39a107764862afecb02cc56bd699f2f080df5368eee8cf043bda845b92589f61af233d731146420701355b85e4a0aefef6c9b83c91caf79a285c26b021569129d23e8147b09a65d705d9a3c095b9d60ad8fe4b4cb4ea139e894527bdf076d9f096f4776497be427eef3b22fe6ff07c7030e0a3c063c0a84d0aee95063d62355f9cb9b75c4cb5c162fb2af2675847040357010464726'),
}],
];
// Now change the order and make 2 tests out of them:
tests[tests.length] = {name: "Standard Axolotl Test Vectors as Alice", vectors: axolotlTwoPartyTestVectorsAlice};
var axolotlTwoPartyTestVectorsBob = [
tests[tests.length] = function() {
var test = [];
test[0] = axolotlTwoPartyTestVectorsAlice[0];
test[1] = axolotlTwoPartyTestVectorsAlice[1];
test[2] = ["receiveMessage", { message: axolotlTwoPartyTestVectorsAlice[3][1].message,
type: axolotlTwoPartyTestVectorsAlice[3][1].type,
expectedSmsText: axolotlTwoPartyTestVectorsAlice[3][1].expectedSmsText,
newEphemeralKey: axolotlTwoPartyTestVectorsAlice[2][1].newEphemeralKey }] ;
test[3] = ["receiveMessage", { message: axolotlTwoPartyTestVectorsAlice[2][1].message,
type: axolotlTwoPartyTestVectorsAlice[2][1].type,
expectedSmsText: axolotlTwoPartyTestVectorsAlice[2][1].expectedSmsText }];
test[4] = axolotlTwoPartyTestVectorsAlice[4];
return {name: "Shuffled Axolotl Test Vectors as Alice", vectors: test};
}();
// The common-case BOB test vectors themselves...
var axolotlTwoPartyTestVectorsBob = [
["receiveMessage",
{
message: hexToArrayBuffer('3308b8896f1221050b71f7b43cf24b70b80fcd0f3c2724a3efcbd194a7d9b46b04757c73ba4a58181a2105eeef4cd089a1b01cbd27ae8c5c4fc46c949c40db889ac1bd5363c3767167bf5122d301330a2105b19f1f4d00684eaf0271b7645356e3313d3d1a55848ca3858fec00e3c34bf60c1000180022a00154c90de4cd2531713f43aba32ee43d40aea071c9a19bdfa9ca04e66972208b31f2f6a97c73105ae192f8b7990113ef33b1c6e7a8fc7481b0b22b2279995e819a295aa076ae6d9670c96376260663f728ecd24ee71e9a5cced7e79dd01efa30bfd4e087ca3be65af8bdaf28dd097cc042b675cc80e66c9f8e8dfc82542b898fb9725acef0619522056f4bd18f8dfed859b2979d45ea64095bb0dd19ab5ab5f0bf1ecd73a516502f7d28823730dffc623a08aa53b8af6e52a86f'),
@ -87,4 +111,91 @@ var axolotlTwoPartyTestVectorsBob = [
}],
];
// Now change the order and make 5 tests out of them:
tests[tests.length] = {name: "Standard Axolotl Test Vectors as Bob", vectors: axolotlTwoPartyTestVectorsBob};
var axolotlTwoPartyTestVectorsBobCopy = function() {
var orig = axolotlTwoPartyTestVectorsBob;
var v = [];
for (var i = 0; i < axolotlTwoPartyTestVectorsBob.length; i++) {
v[i] = [];
v[i][0] = orig[i][0];
v[i][1] = orig[i][1];
}
return v;
}
tests[tests.length] = function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var v = axolotlTwoPartyTestVectorsBobCopy();
var orig = axolotlTwoPartyTestVectorsBob;
// Swap first and second received prekey messages
v[0][1] = { message: orig[1][1].message, type: orig[1][1].type, expectedSmsText: orig[1][1].expectedSmsText };
v[0][1].ourPreKey = orig[0][1].ourPreKey;
v[0][1].preKeyId = orig[0][1].preKeyId;
v[0][1].ourSignedPreKey = orig[0][1].ourSignedPreKey;
v[0][1].signedPreKeyId = orig[0][1].signedPreKeyId;
v[0][1].registrationId = orig[0][1].registrationId;
v[0][1].ourIdentityKey = orig[0][1].ourIdentityKey;
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 };
return {name: "Shuffled Axolotl Test Vectors as Bob I", vectors: v};
}();
tests[tests.length] = function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var v = axolotlTwoPartyTestVectorsBobCopy();
var orig = axolotlTwoPartyTestVectorsBob;
// Swap second received prekey msg with the first send
v[1] = orig[2];
v[2] = orig[1];
return {name: "Shuffled Axolotl Test Vectors as Bob II", vectors: v};
}();
tests[tests.length] = function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var v = axolotlTwoPartyTestVectorsBobCopy();
var orig = axolotlTwoPartyTestVectorsBob;
// Move second received prekey msg to the end (incl after the first received message in the second chain)
v[4] = orig[1];
v[1] = orig[2];
v[2] = orig[3];
v[3] = orig[4];
return {name: "Shuffled Axolotl Test Vectors as Bob III", vectors: v};
}();
tests[tests.length] = function() {
// Copy axolotlTwoPartyTestVectorsBob into v
var v = axolotlTwoPartyTestVectorsBobCopy();
var orig = axolotlTwoPartyTestVectorsBob;
// Move first received prekey msg to the end (incl after the first received message in the second chain)
// ... by first swapping first and second received prekey msg
v[0][1] = { message: orig[1][1].message, type: orig[1][1].type, expectedSmsText: orig[1][1].expectedSmsText };
v[0][1].ourPreKey = orig[0][1].ourPreKey;
v[0][1].preKeyId = orig[0][1].preKeyId;
v[0][1].ourSignedPreKey = orig[0][1].ourSignedPreKey;
v[0][1].signedPreKeyId = orig[0][1].signedPreKeyId;
v[0][1].registrationId = orig[0][1].registrationId;
v[0][1].ourIdentityKey = orig[0][1].ourIdentityKey;
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 };
// ... then moving the (now-second) message to the end
v[4] = v[1];
v[1] = orig[2];
v[2] = orig[3];
v[3] = orig[4];
return {name: "Shuffled Axolotl Test Vectors as Bob IV", vectors: v};
}();
return tests;
}();

Loading…
Cancel
Save