Merge pull request #123 from WhisperSystems/libts

libtextsecure split
This commit is contained in:
Matt Corallo 2015-01-14 10:33:21 -10:00
commit 2eac191a6a
40 changed files with 40291 additions and 121 deletions

View file

@ -10,6 +10,11 @@ module.exports = function(grunt) {
components.push('components/' + bower.concat.app[i] + '/**/*.js');
}
var libcomponents = [];
for (i in bower.concat.lib) {
libcomponents.push('components/' + bower.concat.lib[i] + '/**/*.js');
}
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
@ -17,12 +22,16 @@ module.exports = function(grunt) {
src: components,
dest: 'js/components.js',
},
libcomponents: {
src: libcomponents,
dest: 'libtextsecure/components.js',
},
curve25519: {
src: [
'build/curve25519_compiled.js',
'build/curve25519.js',
],
dest: 'js/curve25519_compiled.js',
dest: 'libtextsecure/curve25519_concat.js',
options: {
banner: ';(function(){\n',
footer: '\n})();'
@ -40,7 +49,7 @@ module.exports = function(grunt) {
'components/cryptojs/src/aes.js',
'build/webcrypto.js'
],
dest: 'js/webcrypto.js',
dest: 'libtextsecure/webcrypto_concat.js',
options: {
banner: ';(function(){\n',
footer: '\n})();'
@ -53,6 +62,36 @@ module.exports = function(grunt) {
'test/_test.js'
],
dest: 'test/test.js',
},
libtextsecure: {
src: [
'libtextsecure/curve25519_concat.js',
'libtextsecure/nativeclient.js',
'libtextsecure/webcrypto_concat.js',
'libtextsecure/protobufs.js',
'libtextsecure/websocket.js',
'libtextsecure/websocket-resources.js',
'libtextsecure/helpers.js',
'libtextsecure/errors.js',
'libtextsecure/stringview.js',
'libtextsecure/storage.js',
'libtextsecure/storage/devices.js',
'libtextsecure/storage/groups.js',
'libtextsecure/api.js',
'libtextsecure/crypto.js',
'libtextsecure/protocol.js',
'libtextsecure/sendmessage.js',
],
dest: 'js/libtextsecure.js',
},
libtextsecuretest: {
src: [
'components/mocha/mocha.js',
'components/chai/chai.js',
'libtextsecure/test/_test.js'
],
dest: 'libtextsecure/test/test.js',
}
},
sass: {
@ -104,9 +143,9 @@ module.exports = function(grunt) {
'saucelabs-mocha': {
all: {
options: {
urls: ['http://127.0.0.1:9999/test/index.html'],
urls: ['http://127.0.0.1:9999/test/index.html', 'http://127.0.0.1:9999/libtextsecure/test/index.html'],
build: process.env.TRAVIS_JOB_ID,
browsers: [{ browserName: 'chrome', version: '38' }],
browsers: [{ browserName: 'chrome', version: '38' }, { browserName: 'firefox', version: '34' }],
testname: 'TextSecure-Browser Tests'
}
}

View file

@ -16,27 +16,12 @@
<html>
<head>
<script type="text/javascript" src="js/components.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="js/libtextsecure.js"></script>
<script type="text/javascript" src="js/protobufs.js"></script>
<script type="text/javascript" src="js/curve25519_compiled.js"></script>
<script type="text/javascript" src="js/nativeclient.js"></script>
<script type="text/javascript" src="js/websocket.js"></script>
<script type="text/javascript" src="js/websocket-resources.js"></script>
<script type="text/javascript" src="js/helpers.js"></script>
<script type="text/javascript" src="js/errors.js"></script>
<script type="text/javascript" src="js/stringview.js"></script>
<script type="text/javascript" src="js/storage.js"></script>
<script type="text/javascript" src="js/storage/devices.js"></script>
<script type="text/javascript" src="js/storage/groups.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="js/libphonenumber-util.js"></script>
<script type="text/javascript" src="js/webcrypto.js"></script>
<script type="text/javascript" src="js/crypto.js"></script>
<script type="text/javascript" src="js/protocol.js"></script>
<script type="text/javascript" src="js/models/messages.js"></script>
<script type="text/javascript" src="js/models/conversations.js"></script>
<script type="text/javascript" src="js/api.js"></script>
<script type="text/javascript" src="js/sendmessage.js"></script>
<script type="text/javascript" src="js/chromium.js"></script>
<script type="text/javascript" src="js/background.js"></script>

View file

@ -99,6 +99,13 @@
"libphonenumber-api",
"momentjs",
"native-client"
],
"lib": [
"jquery",
"long",
"bytebuffer",
"protobuf",
"native-client"
]
}
}

View file

@ -130,31 +130,16 @@
</form>
</script>
<script type="text/javascript" src="js/components.js"></script>
<script type="text/javascript" src="js/libtextsecure.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="components/bootstrap-tagsinput/dist/bootstrap-tagsinput.js"></script>
<script type="text/javascript" src="js/protobufs.js"></script>
<script type="text/javascript" src="js/curve25519_compiled.js"></script>
<script type="text/javascript" src="js/nativeclient.js"></script>
<script type="text/javascript" src="js/websocket.js"></script>
<script type="text/javascript" src="js/websocket-resources.js"></script>
<script type="text/javascript" src="js/helpers.js"></script>
<script type="text/javascript" src="js/errors.js"></script>
<script type="text/javascript" src="js/stringview.js"></script>
<script type="text/javascript" src="js/storage.js"></script>
<script type="text/javascript" src="js/storage/devices.js"></script>
<script type="text/javascript" src="js/storage/groups.js"></script>
<script type="text/javascript" src="js/libphonenumber-util.js"></script>
<script type="text/javascript" src="js/webcrypto.js"></script>
<script type="text/javascript" src="js/crypto.js"></script>
<script type="text/javascript" src="js/protocol.js"></script>
<script type="text/javascript" src="js/models/messages.js"></script>
<script type="text/javascript" src="js/models/conversations.js"></script>
<script type="text/javascript" src="js/api.js"></script>
<script type="text/javascript" src="js/sendmessage.js"></script>
<script type="text/javascript" src="js/chromium.js"></script>
<script type="text/javascript" src="js/views/notifications.js"></script>

5610
js/libtextsecure.js Normal file

File diff suppressed because one or more lines are too long

18210
libtextsecure/components.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -90,6 +90,11 @@ window.textsecure.utils = function() {
return number.split(".");
};
self.isNumberSane = function(number) {
return number[0] == "+" &&
/^[0-9]+$/.test(number.substring(1));
}
/**************************
*** JSON'ing Utilities ***
**************************/
@ -189,9 +194,11 @@ textsecure.processDecrypted = function(decrypted, source) {
if (decrypted.group.avatar !== null)
promises.push(handleAttachment(decrypted.group.avatar));
if (existingGroup.filter(function(number) { decrypted.group.members.indexOf(number) < 0 }).length != 0) {
if (decrypted.group.members.filter(function(number) { return !textsecure.utils.isNumberSane(number); }).length != 0)
throw new Error("Invalid number in new group members");
if (existingGroup.filter(function(number) { decrypted.group.members.indexOf(number) < 0 }).length != 0)
throw new Error("Attempted to remove numbers from group with an UPDATE");
}
decrypted.group.added = decrypted.group.members.filter(function(number) { return existingGroup.indexOf(number) < 0; });
var newGroup = textsecure.storage.groups.addNumbers(decrypted.group.id, decrypted.group.added);
@ -205,8 +212,6 @@ textsecure.processDecrypted = function(decrypted, source) {
return;
}
//TODO: Strictly verify all numbers (ie dont let verifyNumber do any user-magic tweaking)
decrypted.body = null;
decrypted.attachments = [];

View file

@ -17,8 +17,9 @@
'use strict';
window.textsecure = window.textsecure || {};
if (navigator.mimeTypes['application/x-nacl'] === undefined &&
navigator.mimeTypes['application/x-pnacl'] === undefined) {
if ((navigator.mimeTypes['application/x-nacl'] === undefined &&
navigator.mimeTypes['application/x-pnacl'] === undefined) ||
window.location.protocol != "chrome-extension:") {
// browser does not support native client.
return;
}

View file

@ -203,7 +203,8 @@ window.textsecure.messaging = function() {
});
}
_.each(numbers, function(number) {
for (var i in numbers) {
var number = numbers[i];
var devicesForNumber = textsecure.storage.devices.getDeviceObjectsForNumber(number);
var promises = [];
@ -223,7 +224,7 @@ window.textsecure.messaging = function() {
} else
doSendMessage(number, devicesForNumber, true);
});
});
}
}
makeAttachmentPointer = function(attachment) {

View file

@ -35,7 +35,9 @@
var haveMe = false;
var finalNumbers = [];
for (var i in numbers) {
var number = libphonenumber.util.verifyNumber(numbers[i]);
var number = numbers[i];
if (!textsecure.utils.isNumberSane(number))
throw new Error("Invalid number in group");
if (number == me)
haveMe = true;
if (finalNumbers.indexOf(number) < 0)
@ -67,12 +69,6 @@
if (group === undefined)
return undefined;
try {
number = libphonenumber.util.verifyNumber(number);
} catch (e) {
return group.numbers;
}
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
if (number == me)
throw new Error("Cannot remove ourselves from a group, leave the group instead");
@ -93,7 +89,9 @@
return undefined;
for (var i in numbers) {
var number = libphonenumber.util.verifyNumber(numbers[i]);
var number = numbers[i];
if (!textsecure.utils.isNumberSane(number))
throw new Error("Invalid number in set to add to group");
if (group.numbers.indexOf(number) < 0) {
group.numbers.push(number);
group.numberRegistrationIds[number] = {};

View file

@ -0,0 +1,69 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
mocha.setup("bdd");
window.assert = chai.assert;
(function() {
var OriginalReporter = mocha._reporter;
var SauceReporter = function(runner) {
var failedTests = [];
runner.on('end', function() {
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
runner.on('fail', function(test, err) {
var flattenTitles = function(test) {
var titles = [];
while (test.parent.title) {
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
failedTests.push({
name: test.title,
result: false,
message: err.message,
stack: err.stack,
titles: flattenTitles(test)
});
});
new OriginalReporter(runner);
};
SauceReporter.prototype = OriginalReporter.prototype;
mocha.reporter(SauceReporter);
}());
/*
* global helpers for tests
*/
function assertEqualArrayBuffers(ab1, ab2) {
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
};
function hexToArrayBuffer(str) {
var ret = new ArrayBuffer(str.length / 2);
var array = new Uint8Array(ret);
for (var i = 0; i < str.length/2; i++)
array[i] = parseInt(str.substr(i*2, 2), 16);
return ret;
};

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,65 @@
<!--This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<html>
<head>
<title>libTextSecure test runner</title>
<link rel="stylesheet" href="../../components/mocha/mocha.css" />
</head>
<body data-name="curve25519" data-tools="pnacl" data-configs="Debug Release" data-path="../../nacl/pnacl/{config}">
<h2>Run this out of the chrome-plugin:// namespace (and expect plugin state to be cleared/corrupted), not file://</h2>
<div id="listener"></div>
<div id="log"></div>
<div id="mocha">
</div>
<div id="tests">
</div>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="blanket_mocha.js"></script>
<script type="text/javascript" src="../components.js"></script>
<script type="text/javascript" src="../curve25519_concat.js"></script>
<script type="text/javascript" src="../nativeclient.js"></script>
<script type="text/javascript" src="../webcrypto_concat.js"></script>
<script type="text/javascript" src="../protobufs.js" data-cover></script>
<script type="text/javascript" src="../websocket.js" data-cover></script>
<script type="text/javascript" src="../websocket-resources.js" data-cover></script>
<script type="text/javascript" src="../helpers.js" data-cover></script>
<script type="text/javascript" src="../errors.js" data-cover></script>
<script type="text/javascript" src="../stringview.js" data-cover></script>
<script type="text/javascript" src="../storage.js" data-cover></script>
<script type="text/javascript" src="../storage/devices.js" data-cover></script>
<script type="text/javascript" src="../storage/groups.js" data-cover></script>
<script type="text/javascript" src="../api.js"></script>
<script type="text/javascript" src="../crypto.js" data-cover></script>
<script type="text/javascript" src="../protocol.js" data-cover></script>
<script type="text/javascript" src="../sendmessage.js" data-cover></script>
<script type="text/javascript" src="fake_api.js"></script>
<script type="text/javascript" src="testvectors.js"></script>
<script type="text/javascript" src="curve25519_test.js"></script>
<script type="text/javascript" src="crypto_test.js"></script>
<script type="text/javascript" src="nativeclient_test.js"></script>
<script type="text/javascript" src="curve25519_compiled_test.js"></script>
<script type="text/javascript" src="helpers_test.js"></script>
<script type="text/javascript" src="websocket-resources_test.js"></script>
<script type="text/javascript" src="protocol_test.js"></script>
</body>
</html>

View file

@ -219,14 +219,14 @@ describe('Protocol', function() {
};
describe("test vectors", function() {
_.each(axolotlTestVectors, function(t, i) {
it(t.name, function(done) {
for (var i in axolotlTestVectors) {
it(axolotlTestVectors[i].name, function(done) {
localStorage.clear();
return runAxolotlTest(t.vectors).then(function(res) {
return runAxolotlTest(axolotlTestVectors[i].vectors).then(function(res) {
assert(res);
}).then(done).catch(done);
});
});
}
});
});
});

1
libtextsecure/test/protos Symbolic link
View file

@ -0,0 +1 @@
../../protos/

10943
libtextsecure/test/test.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -95,27 +95,13 @@
</div>
</div>
<script type="text/javascript" src="js/components.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="js/protobufs.js"></script>
<script type="text/javascript" src="js/curve25519_compiled.js"></script>
<script type="text/javascript" src="js/nativeclient.js"></script>
<script type="text/javascript" src="js/websocket.js"></script>
<script type="text/javascript" src="js/websocket-resources.js"></script>
<script type="text/javascript" src="js/helpers.js"></script>
<script type="text/javascript" src="js/errors.js"></script>
<script type="text/javascript" src="js/stringview.js"></script>
<script type="text/javascript" src="js/storage.js"></script>
<script type="text/javascript" src="js/storage/devices.js"></script>
<script type="text/javascript" src="js/storage/groups.js"></script>
<script type="text/javascript" src="js/libtextsecure.js"></script>
<script type="text/javascript" src="js/database.js"></script>
<script type="text/javascript" src="js/libphonenumber-util.js"></script>
<script type="text/javascript" src="js/webcrypto.js"></script>
<script type="text/javascript" src="js/crypto.js"></script>
<script type="text/javascript" src="js/protocol.js"></script>
<script type="text/javascript" src="js/models/messages.js"></script>
<script type="text/javascript" src="js/models/conversations.js"></script>
<script type="text/javascript" src="js/api.js"></script>
<script type="text/javascript" src="js/sendmessage.js"></script>
<script type="text/javascript" src="js/chromium.js"></script>
<script type="text/javascript" src="js/options.js"></script>

View file

@ -65,17 +65,6 @@ function assertEqualArrayBuffers(ab1, ab2) {
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
};
function arrayBufferToHex(buffer) {
var array = new Uint8Array(buffer);
var s = '';
for (var i in array) {
var h = array[i].toString(16);
if (h.length < 2) { s += '0'; }
s += h;
}
return s;
};
function hexToArrayBuffer(str) {
var ret = new ArrayBuffer(str.length / 2);
var array = new Uint8Array(ret);

View file

@ -125,27 +125,14 @@
<script type="text/javascript" src="../js/components.js"></script>
<script type="text/javascript" src="../js/protobufs.js" data-cover></script>
<script type="text/javascript" src="../js/websocket.js"></script>
<script type="text/javascript" src="../js/websocket-resources.js"></script>
<script type="text/javascript" src="../js/helpers.js" data-cover></script>
<script type="text/javascript" src="../js/errors.js"></script>
<script type="text/javascript" src="../js/stringview.js" data-cover></script>
<script type="text/javascript" src="../js/storage.js"></script>
<script type="text/javascript" src="../js/storage/devices.js"></script>
<script type="text/javascript" src="../js/storage/groups.js"></script>
<script type="text/javascript" src="../js/libtextsecure.js"></script>
<script type="text/javascript" src="../js/libphonenumber-util.js"></script>
<script type="text/javascript" src="../js/webcrypto.js"></script>
<script type="text/javascript" src="../js/crypto.js"></script>
<script type="text/javascript" src="../js/protocol.js" data-cover></script>
<script type="text/javascript" src="../js/database.js"></script>
<script type="text/javascript" src="../js/models/messages.js" data-cover></script>
<script type="text/javascript" src="../js/models/conversations.js" data-cover></script>
<script type="text/javascript" src="../js/api.js"></script>
<script type="text/javascript" src="../js/sendmessage.js" data-cover></script>
<script type="text/javascript" src="../js/chromium.js"></script>
<script type="text/javascript" src="../js/curve25519_compiled.js"></script>
<script type="text/javascript" src="../js/views/notifications.js"></script>
<script type="text/javascript" src="../js/views/list_view.js" data-cover></script>
@ -159,20 +146,11 @@
<script type="text/javascript" src="../js/views/new_conversation_view.js" data-cover></script>
<script type="text/javascript" src="../js/views/new_group_view.js" data-cover></script>
<script type="text/javascript" src="fake_api.js"></script>
<script type="text/javascript" src="testvectors.js"></script>
<script type="text/javascript" src="curve25519_test.js"></script>
<script type="text/javascript" src="crypto_test.js"></script>
<script type="text/javascript" src="nativeclient_test.js"></script>
<script type="text/javascript" src="curve25519_compiled_test.js"></script>
<script type="text/javascript" src="helpers_test.js"></script>
<script type="text/javascript" src="views/group_update_view_test.js"></script>
<script type="text/javascript" src="views/message_view_test.js"></script>
<script type="text/javascript" src="views/list_view_test.js"></script>
<script type="text/javascript" src="views/message_list_view_test.js"></script>
<script type="text/javascript" src="models/conversations_test.js"></script>
<script type="text/javascript" src="models/messages_test.js"></script>
<script type="text/javascript" src="websocket-resources_test.js"></script>
<script type="text/javascript" src="protocol_test.js"></script>
</body>
</html>

View file

@ -10939,17 +10939,6 @@ function assertEqualArrayBuffers(ab1, ab2) {
assert.deepEqual(new Uint8Array(ab1), new Uint8Array(ab2));
};
function arrayBufferToHex(buffer) {
var array = new Uint8Array(buffer);
var s = '';
for (var i in array) {
var h = array[i].toString(16);
if (h.length < 2) { s += '0'; }
s += h;
}
return s;
};
function hexToArrayBuffer(str) {
var ret = new ArrayBuffer(str.length / 2);
var array = new Uint8Array(ret);