Move test shuffling to js/testvectors.js
This commit is contained in:
parent
0088721343
commit
85f33345ab
2 changed files with 203 additions and 193 deletions
123
js/test.js
123
js/test.js
|
@ -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];
|
||||
return runAxolotlTest(axolotlTestVectors[i].vectors);
|
||||
}, axolotlTestVectors[i].name, true);
|
||||
}(index);
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
|
||||
// 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,7 +5,11 @@ 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 = [];
|
||||
|
||||
// The common-case ALICE test vectors themselves...
|
||||
var axolotlTwoPartyTestVectorsAlice = [
|
||||
["sendMessage",
|
||||
{
|
||||
|
@ -48,7 +52,27 @@ 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};
|
||||
|
||||
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",
|
||||
{
|
||||
|
@ -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…
Add table
Reference in a new issue