2014-05-14 18:58:12 +00:00
|
|
|
/* vim: ts=4:sw=4
|
|
|
|
*
|
2014-05-04 06:34:13 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2014-01-12 07:32:13 +00:00
|
|
|
function b64ToUint6 (nChr) {
|
|
|
|
|
|
|
|
return nChr > 64 && nChr < 91 ?
|
|
|
|
nChr - 65
|
|
|
|
: nChr > 96 && nChr < 123 ?
|
|
|
|
nChr - 71
|
|
|
|
: nChr > 47 && nChr < 58 ?
|
|
|
|
nChr + 4
|
|
|
|
: nChr === 43 ?
|
|
|
|
62
|
|
|
|
: nChr === 47 ?
|
|
|
|
63
|
|
|
|
:
|
|
|
|
0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function base64DecToArr (sBase64, nBlocksSize) {
|
|
|
|
var
|
|
|
|
sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length,
|
2014-01-22 06:23:41 +00:00
|
|
|
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2;
|
|
|
|
var aBBytes = new ArrayBuffer(nOutLen);
|
|
|
|
var taBytes = new Uint8Array(aBBytes);
|
2014-01-12 07:32:13 +00:00
|
|
|
|
|
|
|
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
|
|
|
nMod4 = nInIdx & 3;
|
|
|
|
nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
|
|
|
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
|
|
|
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
|
|
|
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
|
|
|
}
|
|
|
|
nUint24 = 0;
|
|
|
|
}
|
|
|
|
}
|
2014-01-22 06:23:41 +00:00
|
|
|
return aBBytes;
|
2014-01-12 07:32:13 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 01:31:15 +00:00
|
|
|
/* Base64 string to array encoding */
|
|
|
|
|
|
|
|
function uint6ToB64 (nUint6) {
|
|
|
|
|
|
|
|
return nUint6 < 26 ?
|
|
|
|
nUint6 + 65
|
|
|
|
: nUint6 < 52 ?
|
|
|
|
nUint6 + 71
|
|
|
|
: nUint6 < 62 ?
|
|
|
|
nUint6 - 4
|
|
|
|
: nUint6 === 62 ?
|
|
|
|
43
|
|
|
|
: nUint6 === 63 ?
|
|
|
|
47
|
|
|
|
:
|
|
|
|
65;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function base64EncArr (aBytes) {
|
|
|
|
|
|
|
|
var nMod3, sB64Enc = "";
|
|
|
|
|
|
|
|
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
|
|
|
|
nMod3 = nIdx % 3;
|
|
|
|
//if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += "\r\n"; }
|
|
|
|
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
|
|
|
|
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
|
|
|
|
sB64Enc += String.fromCharCode(uint6ToB64(nUint24 >>> 18 & 63), uint6ToB64(nUint24 >>> 12 & 63), uint6ToB64(nUint24 >>> 6 & 63), uint6ToB64(nUint24 & 63));
|
|
|
|
nUint24 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sB64Enc.replace(/A(?=A$|$)/g, "=");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-04 06:33:02 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
|
2014-01-12 07:32:13 +00:00
|
|
|
/*********************************
|
|
|
|
*** Type conversion utilities ***
|
|
|
|
*********************************/
|
2014-01-15 07:46:05 +00:00
|
|
|
// Strings/arrays
|
2014-03-06 21:44:59 +00:00
|
|
|
//TODO: Throw all this shit in favor of consistent types
|
2014-07-21 02:06:04 +00:00
|
|
|
//TODO: Namespace
|
2014-01-12 14:07:13 +00:00
|
|
|
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
|
2014-01-22 06:23:41 +00:00
|
|
|
var StaticArrayBufferProto = new ArrayBuffer().__proto__;
|
2014-03-06 18:18:11 +00:00
|
|
|
var StaticUint8ArrayProto = new Uint8Array().__proto__;
|
|
|
|
var StaticWordArrayProto = CryptoJS.lib.WordArray.create('').__proto__;
|
2014-01-12 07:32:13 +00:00
|
|
|
function getString(thing) {
|
2014-03-06 18:18:11 +00:00
|
|
|
if (thing === Object(thing)) {
|
|
|
|
if (thing.__proto__ == StaticUint8ArrayProto)
|
|
|
|
return String.fromCharCode.apply(null, thing);
|
|
|
|
if (thing.__proto__ == StaticArrayBufferProto)
|
|
|
|
return getString(new Uint8Array(thing));
|
|
|
|
if (thing.__proto__ == StaticByteBufferProto)
|
|
|
|
return thing.toString("binary");
|
|
|
|
if (thing.__proto__ == StaticWordArrayProto)
|
|
|
|
return thing.toString(CryptoJS.enc.Latin1);
|
|
|
|
}
|
2014-01-12 07:32:13 +00:00
|
|
|
return thing;
|
|
|
|
}
|
|
|
|
|
2014-03-05 01:31:15 +00:00
|
|
|
function getStringable(thing) {
|
2014-03-10 22:47:37 +00:00
|
|
|
return (typeof thing == "string" || typeof thing == "number" || typeof thing == "boolean" ||
|
2014-03-06 18:18:11 +00:00
|
|
|
(thing === Object(thing) &&
|
|
|
|
(thing.__proto__ == StaticArrayBufferProto ||
|
|
|
|
thing.__proto__ == StaticUint8ArrayProto ||
|
|
|
|
thing.__proto__ == StaticByteBufferProto ||
|
|
|
|
thing.__proto__ == StaticWordArrayProto)));
|
2014-03-05 01:31:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-23 05:49:13 +00:00
|
|
|
function isEqual(a, b, mayBeShort) {
|
2014-07-21 02:06:04 +00:00
|
|
|
// TODO: Special-case arraybuffers, etc
|
2014-07-23 07:36:11 +00:00
|
|
|
if (a === undefined || b === undefined)
|
|
|
|
return false;
|
2014-07-21 02:06:04 +00:00
|
|
|
a = getString(a);
|
|
|
|
b = getString(b);
|
2014-07-23 05:49:13 +00:00
|
|
|
var maxLength = mayBeShort ? Math.min(a.length, b.length) : Math.max(a.length, b.length);
|
2014-07-21 02:55:07 +00:00
|
|
|
if (maxLength < 5)
|
|
|
|
throw new Error("a/b compare too short");
|
2014-07-21 02:06:04 +00:00
|
|
|
return a.substring(0, Math.min(maxLength, a.length)) == b.substring(0, Math.min(maxLength, b.length));
|
|
|
|
}
|
|
|
|
|
2014-03-05 01:31:15 +00:00
|
|
|
function toArrayBuffer(thing) {
|
2014-03-06 18:18:11 +00:00
|
|
|
//TODO: Optimize this for specific cases
|
2014-03-05 01:31:15 +00:00
|
|
|
if (thing === undefined)
|
|
|
|
return undefined;
|
2014-03-06 21:44:59 +00:00
|
|
|
if (thing === Object(thing) && thing.__proto__ == StaticArrayBufferProto)
|
|
|
|
return thing;
|
2014-03-10 00:32:00 +00:00
|
|
|
|
|
|
|
if (thing instanceof Array) {
|
|
|
|
// Assuming Uint16Array from curve25519
|
|
|
|
var res = new ArrayBuffer(thing.length * 2);
|
|
|
|
var uint = new Uint16Array(res);
|
|
|
|
for (var i = 0; i < thing.length; i++)
|
|
|
|
uint[i] = thing[i];
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-03-05 01:31:15 +00:00
|
|
|
if (!getStringable(thing))
|
2014-05-03 03:16:36 +00:00
|
|
|
throw new Error("Tried to convert a non-stringable thing of type " + typeof thing + " to an array buffer");
|
2014-03-05 01:31:15 +00:00
|
|
|
var str = getString(thing);
|
|
|
|
var res = new ArrayBuffer(str.length);
|
|
|
|
var uint = new Uint8Array(res);
|
|
|
|
for (var i = 0; i < str.length; i++)
|
|
|
|
uint[i] = str.charCodeAt(i);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-22 06:23:41 +00:00
|
|
|
function base64ToArrayBuffer(string) {
|
2014-01-12 07:32:13 +00:00
|
|
|
return base64DecToArr(string);
|
|
|
|
}
|
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
// Protobuf decoding
|
2014-01-15 07:46:05 +00:00
|
|
|
//TODO: throw on missing fields everywhere
|
2014-05-21 19:04:05 +00:00
|
|
|
window.textsecure.protos = function() {
|
|
|
|
var self = {};
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-21 19:04:05 +00:00
|
|
|
self.IncomingPushMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.IncomingPushMessageSignal");
|
|
|
|
self.decodeIncomingPushMessageProtobuf = function(string) {
|
2014-05-25 23:48:41 +00:00
|
|
|
return self.IncomingPushMessageProtobuf.decode(btoa(string));
|
2014-05-21 19:04:05 +00:00
|
|
|
}
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-21 19:04:05 +00:00
|
|
|
self.PushMessageContentProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.PushMessageContent");
|
|
|
|
self.decodePushMessageContentProtobuf = function(string) {
|
2014-05-25 23:48:41 +00:00
|
|
|
return self.PushMessageContentProtobuf.decode(btoa(string));
|
2014-05-21 19:04:05 +00:00
|
|
|
}
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-21 19:04:05 +00:00
|
|
|
self.WhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.WhisperMessage");
|
|
|
|
self.decodeWhisperMessageProtobuf = function(string) {
|
2014-05-25 23:48:41 +00:00
|
|
|
return self.WhisperMessageProtobuf.decode(btoa(string));
|
2014-05-21 19:04:05 +00:00
|
|
|
}
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-21 19:04:05 +00:00
|
|
|
self.PreKeyWhisperMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.PreKeyWhisperMessage");
|
|
|
|
self.decodePreKeyWhisperMessageProtobuf = function(string) {
|
2014-05-25 23:48:41 +00:00
|
|
|
return self.PreKeyWhisperMessageProtobuf.decode(btoa(string));
|
2014-05-21 19:04:05 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 05:31:41 +00:00
|
|
|
self.DeviceInitProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/DeviceMessages.proto").build("textsecure.DeviceInit");
|
|
|
|
self.decodeDeviceInitProtobuf = function(string) {
|
|
|
|
return self.DeviceInitProtobuf.decode(btoa(string));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.IdentityKeyProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/DeviceMessages.proto").build("textsecure.IdentityKey");
|
|
|
|
self.decodeIdentityKeyProtobuf = function(string) {
|
|
|
|
return self.IdentityKeyProtobuf.decode(btoa(string));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.DeviceControlProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/DeviceMessages.proto").build("textsecure.DeviceControl");
|
|
|
|
self.decodeDeviceControlProtobuf = function(string) {
|
|
|
|
return self.DeviceControlProtobuf.decode(btoa(string));
|
2014-05-21 19:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}();
|
2014-01-12 07:32:13 +00:00
|
|
|
|
2014-05-25 22:09:07 +00:00
|
|
|
// Number formatting utils
|
|
|
|
window.textsecure.utils = function() {
|
|
|
|
var self = {};
|
2014-05-25 22:45:22 +00:00
|
|
|
self.unencodeNumber = function(number) {
|
2014-05-31 17:28:46 +00:00
|
|
|
return number.split(".");
|
2014-06-29 22:15:27 +00:00
|
|
|
};
|
2014-05-25 22:09:07 +00:00
|
|
|
|
2014-05-25 22:45:22 +00:00
|
|
|
/**************************
|
|
|
|
*** JSON'ing Utilities ***
|
|
|
|
**************************/
|
2014-05-21 19:04:05 +00:00
|
|
|
function ensureStringed(thing) {
|
|
|
|
if (getStringable(thing))
|
|
|
|
return getString(thing);
|
|
|
|
else if (thing instanceof Array) {
|
|
|
|
var res = [];
|
|
|
|
for (var i = 0; i < thing.length; i++)
|
|
|
|
res[i] = ensureStringed(thing[i]);
|
|
|
|
return res;
|
|
|
|
} else if (thing === Object(thing)) {
|
|
|
|
var res = {};
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var key in thing)
|
2014-05-21 19:04:05 +00:00
|
|
|
res[key] = ensureStringed(thing[key]);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
throw new Error("unsure of how to jsonify object of type " + typeof thing);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-25 22:45:22 +00:00
|
|
|
self.jsonThing = function(thing) {
|
2014-05-21 19:04:05 +00:00
|
|
|
return JSON.stringify(ensureStringed(thing));
|
|
|
|
}
|
|
|
|
|
2014-05-25 22:45:22 +00:00
|
|
|
return self;
|
|
|
|
}();
|
|
|
|
|
2014-05-27 19:29:44 +00:00
|
|
|
window.textsecure.throwHumanError = function(error, type, humanError) {
|
|
|
|
var e = new Error(error);
|
|
|
|
if (type !== undefined)
|
|
|
|
e.name = type;
|
|
|
|
e.humanError = humanError;
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2014-05-25 22:45:22 +00:00
|
|
|
/************************************************
|
|
|
|
*** Utilities to store data in local storage ***
|
|
|
|
************************************************/
|
|
|
|
window.textsecure.storage = function() {
|
|
|
|
var self = {};
|
|
|
|
|
2014-05-17 04:54:12 +00:00
|
|
|
/*****************************
|
|
|
|
*** Base Storage Routines ***
|
|
|
|
*****************************/
|
2014-05-17 05:53:58 +00:00
|
|
|
self.putEncrypted = function(key, value) {
|
2014-05-17 04:54:12 +00:00
|
|
|
//TODO
|
|
|
|
if (value === undefined)
|
|
|
|
throw new Error("Tried to store undefined");
|
2014-05-25 22:45:22 +00:00
|
|
|
localStorage.setItem("e" + key, textsecure.utils.jsonThing(value));
|
2014-05-17 04:54:12 +00:00
|
|
|
}
|
2014-01-17 06:08:33 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.getEncrypted = function(key, defaultValue) {
|
2014-01-10 07:48:05 +00:00
|
|
|
//TODO
|
2014-05-17 04:54:12 +00:00
|
|
|
var value = localStorage.getItem("e" + key);
|
|
|
|
if (value === null)
|
|
|
|
return defaultValue;
|
|
|
|
return JSON.parse(value);
|
|
|
|
}
|
2014-01-10 07:48:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.removeEncrypted = function(key) {
|
2014-05-17 04:54:12 +00:00
|
|
|
localStorage.removeItem("e" + key);
|
|
|
|
}
|
2014-01-10 07:48:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.putUnencrypted = function(key, value) {
|
2014-05-17 04:54:12 +00:00
|
|
|
if (value === undefined)
|
|
|
|
throw new Error("Tried to store undefined");
|
2014-05-25 22:45:22 +00:00
|
|
|
localStorage.setItem("u" + key, textsecure.utils.jsonThing(value));
|
2014-05-17 04:54:12 +00:00
|
|
|
}
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.getUnencrypted = function(key, defaultValue) {
|
2014-05-17 04:54:12 +00:00
|
|
|
var value = localStorage.getItem("u" + key);
|
|
|
|
if (value === null)
|
|
|
|
return defaultValue;
|
|
|
|
return JSON.parse(value);
|
|
|
|
}
|
2014-01-10 07:48:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.removeUnencrypted = function(key) {
|
2014-05-17 04:54:12 +00:00
|
|
|
localStorage.removeItem("u" + key);
|
|
|
|
}
|
2014-01-10 07:48:05 +00:00
|
|
|
|
2014-05-17 04:54:12 +00:00
|
|
|
/**********************
|
|
|
|
*** Device Storage ***
|
|
|
|
**********************/
|
2014-05-17 05:53:58 +00:00
|
|
|
self.devices = function() {
|
|
|
|
var self = {};
|
|
|
|
|
2014-07-25 00:15:27 +00:00
|
|
|
var internalSaveDeviceObject = function(deviceObject, onlyKeys) {
|
|
|
|
if (deviceObject.identityKey === undefined || deviceObject.encodedNumber === undefined)
|
2014-05-31 17:28:46 +00:00
|
|
|
throw new Error("Tried to store invalid deviceObject");
|
|
|
|
|
|
|
|
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
|
2014-05-27 23:14:16 +00:00
|
|
|
var map = textsecure.storage.getEncrypted("devices" + number);
|
2014-05-17 04:54:12 +00:00
|
|
|
|
2014-05-27 23:14:16 +00:00
|
|
|
if (map === undefined)
|
|
|
|
map = { devices: [deviceObject], identityKey: deviceObject.identityKey };
|
|
|
|
else if (map.identityKey != getString(deviceObject.identityKey))
|
|
|
|
throw new Error("Identity key changed");
|
2014-05-31 17:28:46 +00:00
|
|
|
else {
|
|
|
|
var updated = false;
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var i in map.devices) {
|
2014-05-31 17:28:46 +00:00
|
|
|
if (map.devices[i].encodedNumber == deviceObject.encodedNumber) {
|
2014-07-25 00:15:27 +00:00
|
|
|
if (!onlyKeys)
|
|
|
|
map.devices[i] = deviceObject;
|
|
|
|
else {
|
|
|
|
map.devices[i].preKey = deviceObject.preKey;
|
|
|
|
map.devices[i].preKeyId = deviceObject.preKeyId;
|
|
|
|
map.devices[i].signedKey = deviceObject.signedKey;
|
|
|
|
map.devices[i].signedKeyId = deviceObject.signedKeyId;
|
|
|
|
map.devices[i].registrationId = deviceObject.registrationId;
|
|
|
|
}
|
2014-05-31 17:28:46 +00:00
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!updated)
|
|
|
|
map.devices.push(deviceObject);
|
|
|
|
}
|
2014-05-17 04:54:12 +00:00
|
|
|
|
2014-05-27 23:14:16 +00:00
|
|
|
textsecure.storage.putEncrypted("devices" + number, map);
|
2014-05-17 04:54:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 00:15:27 +00:00
|
|
|
self.saveDeviceObject = function(deviceObject) {
|
|
|
|
return internalSaveDeviceObject(deviceObject, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.saveKeysToDeviceObject = function(deviceObject) {
|
|
|
|
return internalSaveDeviceObject(deviceObject, true);
|
|
|
|
}
|
|
|
|
|
2014-05-27 23:14:16 +00:00
|
|
|
self.getDeviceObjectsForNumber = function(number) {
|
|
|
|
var map = textsecure.storage.getEncrypted("devices" + number);
|
|
|
|
return map === undefined ? [] : map.devices;
|
2014-05-17 05:53:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 17:28:46 +00:00
|
|
|
self.getDeviceObject = function(encodedNumber) {
|
|
|
|
var number = textsecure.utils.unencodeNumber(encodedNumber);
|
|
|
|
var devices = self.getDeviceObjectsForNumber(number[0]);
|
|
|
|
if (devices === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var i in devices)
|
2014-05-31 17:28:46 +00:00
|
|
|
if (devices[i].encodedNumber == encodedNumber)
|
|
|
|
return devices[i];
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2014-05-27 23:14:16 +00:00
|
|
|
self.removeDeviceIdsForNumber = function(number, deviceIdsToRemove) {
|
|
|
|
var map = textsecure.storage.getEncrypted("devices" + number);
|
|
|
|
if (map === undefined)
|
|
|
|
throw new Error("Tried to remove device for unknown number");
|
|
|
|
|
|
|
|
var newDevices = [];
|
|
|
|
var devicesRemoved = 0;
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var i in map.devices) {
|
2014-05-27 23:14:16 +00:00
|
|
|
var keep = true;
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var j in deviceIdsToRemove)
|
2014-06-01 17:39:35 +00:00
|
|
|
if (map.devices[i].encodedNumber == number + "." + deviceIdsToRemove[j])
|
2014-05-27 23:14:16 +00:00
|
|
|
keep = false;
|
|
|
|
|
|
|
|
if (keep)
|
2014-05-28 02:16:45 +00:00
|
|
|
newDevices.push(map.devices[i]);
|
2014-05-27 23:14:16 +00:00
|
|
|
else
|
|
|
|
devicesRemoved++;
|
2014-05-17 04:54:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 23:14:16 +00:00
|
|
|
if (devicesRemoved != deviceIdsToRemove.length)
|
|
|
|
throw new Error("Tried to remove unknown device");
|
2014-05-17 04:54:12 +00:00
|
|
|
}
|
2014-05-17 05:53:58 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}();
|
|
|
|
|
2014-06-03 16:39:29 +00:00
|
|
|
/*********************
|
|
|
|
*** Group Storage ***
|
|
|
|
*********************/
|
|
|
|
self.groups = function() {
|
|
|
|
var self = {};
|
|
|
|
|
2014-06-06 01:05:42 +00:00
|
|
|
var addGroupToNumber = function(groupId, number) {
|
|
|
|
var membership = textsecure.storage.getEncrypted("groupMembership" + number, [groupId]);
|
|
|
|
if (membership.indexOf(groupId) < 0)
|
|
|
|
membership.push(groupId);
|
|
|
|
textsecure.storage.putEncrypted("groupMembership" + number, membership);
|
|
|
|
}
|
|
|
|
|
|
|
|
var removeGroupFromNumber = function(groupId, number) {
|
|
|
|
var membership = textsecure.storage.getEncrypted("groupMembership" + number, [groupId]);
|
|
|
|
membership = membership.filter(function(group) { return group != groupId; });
|
|
|
|
if (membership.length == 0)
|
|
|
|
textsecure.storage.removeEncrypted("groupMembership" + number);
|
|
|
|
else
|
|
|
|
textsecure.storage.putEncrypted("groupMembership" + number, membership);
|
|
|
|
}
|
|
|
|
|
2014-06-06 02:26:01 +00:00
|
|
|
self.getGroupListForNumber = function(number) {
|
|
|
|
return textsecure.storage.getEncrypted("groupMembership" + number, []);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:09:04 +00:00
|
|
|
self.createNewGroup = function(numbers, groupId) {
|
2014-10-14 22:27:47 +00:00
|
|
|
if (groupId !== undefined && textsecure.storage.getEncrypted("group" + groupId) !== undefined) {
|
2014-06-06 01:05:42 +00:00
|
|
|
throw new Error("Tried to recreate group");
|
2014-10-14 22:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (groupId === undefined || textsecure.storage.getEncrypted("group" + groupId) !== undefined) {
|
2014-10-16 20:38:33 +00:00
|
|
|
groupId = getString(textsecure.crypto.getRandomBytes(16));
|
2014-10-14 22:27:47 +00:00
|
|
|
}
|
2014-06-04 01:09:04 +00:00
|
|
|
|
2014-06-05 23:20:09 +00:00
|
|
|
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
|
|
|
var haveMe = false;
|
|
|
|
var finalNumbers = [];
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var i in numbers) {
|
2014-10-12 00:19:16 +00:00
|
|
|
var number = libphonenumber.util.verifyNumber(numbers[i]);
|
2014-06-05 23:20:09 +00:00
|
|
|
if (number == me)
|
|
|
|
haveMe = true;
|
2014-06-06 01:05:42 +00:00
|
|
|
if (finalNumbers.indexOf(number) < 0) {
|
2014-06-05 23:20:09 +00:00
|
|
|
finalNumbers.push(number);
|
2014-06-06 01:05:42 +00:00
|
|
|
addGroupToNumber(groupId, number);
|
|
|
|
}
|
2014-06-05 23:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!haveMe)
|
|
|
|
finalNumbers.push(me);
|
|
|
|
|
|
|
|
textsecure.storage.putEncrypted("group" + groupId, {numbers: finalNumbers});
|
2014-06-04 01:09:04 +00:00
|
|
|
|
2014-06-05 23:20:09 +00:00
|
|
|
return {id: groupId, numbers: finalNumbers};
|
2014-06-04 01:09:04 +00:00
|
|
|
}
|
2014-06-03 16:39:29 +00:00
|
|
|
|
|
|
|
self.getNumbers = function(groupId) {
|
2014-06-04 01:09:04 +00:00
|
|
|
var group = textsecure.storage.getEncrypted("group" + groupId);
|
|
|
|
if (group === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return group.numbers;
|
|
|
|
}
|
|
|
|
|
2014-06-04 02:18:14 +00:00
|
|
|
self.removeNumber = function(groupId, number) {
|
|
|
|
var group = textsecure.storage.getEncrypted("group" + groupId);
|
|
|
|
if (group === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
2014-06-05 23:20:09 +00:00
|
|
|
try {
|
2014-10-12 00:19:16 +00:00
|
|
|
number = libphonenumber.util.verifyNumber(number);
|
2014-06-05 23:20:09 +00:00
|
|
|
} 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");
|
|
|
|
|
|
|
|
var i = group.numbers.indexOf(number);
|
|
|
|
if (i > -1) {
|
|
|
|
group.numbers.slice(i, 1);
|
|
|
|
textsecure.storage.putEncrypted("group" + groupId, group);
|
2014-06-06 01:05:42 +00:00
|
|
|
removeGroupFromNumber(groupId, number);
|
2014-06-05 23:20:09 +00:00
|
|
|
}
|
2014-06-04 02:18:14 +00:00
|
|
|
|
|
|
|
return group.numbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.addNumbers = function(groupId, numbers) {
|
|
|
|
var group = textsecure.storage.getEncrypted("group" + groupId);
|
|
|
|
if (group === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
2014-07-23 01:33:35 +00:00
|
|
|
for (var i in numbers) {
|
2014-10-12 00:19:16 +00:00
|
|
|
var number = libphonenumber.util.verifyNumber(numbers[i]);
|
2014-06-06 02:26:01 +00:00
|
|
|
if (group.numbers.indexOf(number) < 0) {
|
2014-06-05 23:20:09 +00:00
|
|
|
group.numbers.push(number);
|
2014-06-06 02:26:01 +00:00
|
|
|
addGroupToNumber(groupId, number);
|
|
|
|
}
|
2014-06-05 23:20:09 +00:00
|
|
|
}
|
2014-06-04 02:18:14 +00:00
|
|
|
|
|
|
|
textsecure.storage.putEncrypted("group" + groupId, group);
|
|
|
|
return group.numbers;
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:09:04 +00:00
|
|
|
self.deleteGroup = function(groupId) {
|
|
|
|
textsecure.storage.removeEncrypted("group" + groupId);
|
2014-06-03 16:39:29 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 02:26:01 +00:00
|
|
|
self.getGroup = function(groupId) {
|
|
|
|
var group = textsecure.storage.getEncrypted("group" + groupId);
|
|
|
|
if (group === undefined)
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
return { id: groupId, numbers: group.numbers }; //TODO: avatar/name tracking
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:39:29 +00:00
|
|
|
return self;
|
|
|
|
}();
|
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
return self;
|
|
|
|
}();
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-01-22 06:23:41 +00:00
|
|
|
/**********************
|
|
|
|
*** NaCL Interface ***
|
|
|
|
**********************/
|
2014-05-17 05:53:58 +00:00
|
|
|
window.textsecure.nacl = function() {
|
|
|
|
var self = {};
|
|
|
|
|
2014-07-20 20:31:56 +00:00
|
|
|
self.USE_NACL = true;
|
2014-05-17 05:53:58 +00:00
|
|
|
|
|
|
|
var onLoadCallbacks = [];
|
|
|
|
var naclLoaded = 0;
|
|
|
|
self.registerOnLoadFunction = function(func) {
|
2014-07-27 06:05:25 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
if (naclLoaded || !self.USE_NACL)
|
|
|
|
return resolve(func());
|
|
|
|
onLoadCallbacks[onLoadCallbacks.length] = [ func, resolve, reject ];
|
|
|
|
});
|
2014-03-10 00:32:00 +00:00
|
|
|
}
|
2014-01-22 06:23:41 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
var naclMessageNextId = 0;
|
|
|
|
var naclMessageIdCallbackMap = {};
|
|
|
|
window.moduleDidLoad = function() {
|
|
|
|
common.hideModule();
|
|
|
|
naclLoaded = 1;
|
2014-07-27 06:05:25 +00:00
|
|
|
for (var i = 0; i < onLoadCallbacks.length; i++) {
|
|
|
|
try {
|
|
|
|
onLoadCallbacks[i][1](onLoadCallbacks[i][0]());
|
|
|
|
} catch (e) {
|
|
|
|
onLoadCallbacks[i][2](e);
|
|
|
|
}
|
|
|
|
}
|
2014-05-17 05:53:58 +00:00
|
|
|
onLoadCallbacks = [];
|
|
|
|
}
|
2014-01-22 06:23:41 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
window.handleMessage = function(message) {
|
|
|
|
naclMessageIdCallbackMap[message.data.call_id](message.data);
|
|
|
|
}
|
2014-01-22 06:23:41 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
self.postNaclMessage = function(message) {
|
|
|
|
if (!self.USE_NACL)
|
|
|
|
throw new Error("Attempted to make NaCL call with !USE_NACL?");
|
2014-03-10 00:32:00 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
return new Promise(function(resolve) {
|
|
|
|
naclMessageIdCallbackMap[naclMessageNextId] = resolve;
|
|
|
|
message.call_id = naclMessageNextId++;
|
2014-01-15 07:46:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
common.naclModule.postMessage(message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}();
|
2014-01-10 07:48:05 +00:00
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
//TODO: Some kind of textsecure.init(use_nacl)
|
|
|
|
window.textsecure.registerOnLoadFunction = window.textsecure.nacl.registerOnLoadFunction;
|
|
|
|
|
2014-06-01 17:39:35 +00:00
|
|
|
window.textsecure.replay = function() {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.REPLAY_FUNCS = {
|
|
|
|
SEND_MESSAGE: 1,
|
|
|
|
INIT_SESSION: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
var functions = {};
|
|
|
|
|
|
|
|
self.registerReplayFunction = function(func, functionCode) {
|
|
|
|
functions[functionCode] = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.replayError = function(replayData) {
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
args.shift();
|
|
|
|
args = replayData.args.concat(args);
|
|
|
|
functions[replayData.replayFunction].apply(window, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.createReplayableError = function(shortMsg, longMsg, replayFunction, args) {
|
|
|
|
var e = new Error(shortMsg);
|
|
|
|
e.name = "ReplayableError";
|
|
|
|
e.humanError = e.longMessage = longMsg;
|
|
|
|
e.replayData = { replayFunction: replayFunction, args: args };
|
|
|
|
e.replay = function() {
|
|
|
|
self.replayError(e.replayData);
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}();
|
|
|
|
|
2014-05-17 05:53:58 +00:00
|
|
|
// message_callback({message: decryptedMessage, pushMessage: server-providedPushMessage})
|
2014-07-26 05:31:41 +00:00
|
|
|
window.textsecure.subscribeToPush = function(message_callback) {
|
|
|
|
var socket = textsecure.api.getMessageWebsocket();
|
|
|
|
|
|
|
|
socket.onmessage = function(message) {
|
|
|
|
textsecure.crypto.decryptWebsocketMessage(message.message).then(function(plaintext) {
|
|
|
|
var proto = textsecure.protos.decodeIncomingPushMessageProtobuf(getString(plaintext));
|
|
|
|
// After this point, a) decoding errors are not the server's fault, and
|
|
|
|
// b) we should handle them gracefully and tell the user they received an invalid message
|
|
|
|
console.log("Successfully decoded message with id: " + message.id);
|
|
|
|
socket.send(JSON.stringify({type: 1, id: message.id}));
|
|
|
|
return textsecure.crypto.handleIncomingPushMessageProto(proto).then(function(decrypted) {
|
2014-07-26 05:53:24 +00:00
|
|
|
// Delivery receipt
|
|
|
|
if (decrypted === null)
|
|
|
|
//TODO: Pass to UI
|
|
|
|
return;
|
|
|
|
|
2014-07-26 05:31:41 +00:00
|
|
|
// Now that its decrypted, validate the message and clean it up for consumer processing
|
|
|
|
// Note that messages may (generally) only perform one action and we ignore remaining fields
|
|
|
|
// after the first action.
|
|
|
|
|
|
|
|
if (decrypted.flags == null)
|
|
|
|
decrypted.flags = 0;
|
|
|
|
|
|
|
|
if ((decrypted.flags & textsecure.protos.PushMessageContentProtobuf.Flags.END_SESSION)
|
|
|
|
== textsecure.protos.PushMessageContentProtobuf.Flags.END_SESSION)
|
|
|
|
return;
|
|
|
|
if (decrypted.flags != 0)
|
|
|
|
throw new Error("Unknown flags in message");
|
|
|
|
|
|
|
|
var handleAttachment = function(attachment) {
|
|
|
|
return textsecure.api.getAttachment(attachment.id).then(function(encryptedBin) {
|
|
|
|
return textsecure.crypto.decryptAttachment(encryptedBin, toArrayBuffer(attachment.key)).then(function(decryptedBin) {
|
|
|
|
attachment.decrypted = decryptedBin;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var promises = [];
|
|
|
|
|
|
|
|
if (decrypted.group !== null) {
|
2014-10-17 00:39:44 +00:00
|
|
|
decrypted.group.id = getString(decrypted.group.id);
|
2014-07-26 05:31:41 +00:00
|
|
|
var existingGroup = textsecure.storage.groups.getNumbers(decrypted.group.id);
|
|
|
|
if (existingGroup === undefined) {
|
2014-10-15 01:25:15 +00:00
|
|
|
if (decrypted.group.type != textsecure.protos.PushMessageContentProtobuf.GroupContext.Type.UPDATE)
|
2014-07-26 05:31:41 +00:00
|
|
|
throw new Error("Got message for unknown group");
|
|
|
|
textsecure.storage.groups.createNewGroup(decrypted.group.members, decrypted.group.id);
|
|
|
|
} else {
|
|
|
|
var fromIndex = existingGroup.indexOf(proto.source);
|
|
|
|
|
|
|
|
if (fromIndex < 0) //TODO: This could be indication of a race...
|
|
|
|
throw new Error("Sender was not a member of the group they were sending from");
|
|
|
|
|
|
|
|
switch(decrypted.group.type) {
|
2014-10-15 01:25:15 +00:00
|
|
|
case textsecure.protos.PushMessageContentProtobuf.GroupContext.Type.UPDATE:
|
2014-07-26 05:31:41 +00:00
|
|
|
if (decrypted.group.avatar !== null)
|
|
|
|
promises.push(handleAttachment(decrypted.group.avatar));
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (newGroup.length != decrypted.group.members.length ||
|
|
|
|
newGroup.filter(function(number) { return decrypted.group.members.indexOf(number) < 0; }).length != 0)
|
|
|
|
throw new Error("Error calculating group member difference");
|
|
|
|
|
|
|
|
//TODO: Also follow this path if avatar + name haven't changed (ie we should start storing those)
|
|
|
|
if (decrypted.group.avatar === null && decrypted.group.added.length == 0 && decrypted.group.name === null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//TODO: Strictly verify all numbers (ie dont let verifyNumber do any user-magic tweaking)
|
|
|
|
|
|
|
|
decrypted.body = null;
|
|
|
|
decrypted.attachments = [];
|
|
|
|
|
|
|
|
break;
|
2014-10-15 01:25:15 +00:00
|
|
|
case textsecure.protos.PushMessageContentProtobuf.GroupContext.Type.QUIT:
|
2014-07-26 05:31:41 +00:00
|
|
|
textsecure.storage.groups.removeNumber(decrypted.group.id, proto.source);
|
|
|
|
|
|
|
|
decrypted.body = null;
|
|
|
|
decrypted.attachments = [];
|
2014-10-15 01:25:15 +00:00
|
|
|
case textsecure.protos.PushMessageContentProtobuf.GroupContext.Type.DELIVER:
|
2014-07-26 05:31:41 +00:00
|
|
|
decrypted.group.name = null;
|
|
|
|
decrypted.group.members = [];
|
|
|
|
decrypted.group.avatar = null;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("Unknown group message type");
|
2014-06-04 02:18:14 +00:00
|
|
|
}
|
2014-07-26 05:31:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 02:18:14 +00:00
|
|
|
|
2014-07-26 05:31:41 +00:00
|
|
|
for (var i in decrypted.attachments)
|
|
|
|
promises.push(handleAttachment(decrypted.attachments[i]));
|
|
|
|
return Promise.all(promises).then(function() {
|
|
|
|
message_callback({pushMessage: proto, message: decrypted});
|
2014-05-17 05:53:58 +00:00
|
|
|
});
|
2014-07-26 05:31:41 +00:00
|
|
|
})
|
|
|
|
}).catch(function(e) {
|
|
|
|
// TODO: Show "Invalid message" messages?
|
|
|
|
console.log("Error handling incoming message: ");
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2014-05-17 05:53:58 +00:00
|
|
|
|
2014-10-10 01:54:23 +00:00
|
|
|
window.textsecure.registerSingleDevice = function(number, verificationCode, stepDone) {
|
|
|
|
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
|
|
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
|
|
|
|
|
|
|
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
|
|
|
|
password = password.substring(0, password.length - 2);
|
|
|
|
textsecure.storage.putEncrypted("password", password);
|
|
|
|
|
|
|
|
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
|
|
|
|
registrationId = registrationId & 0x3fff;
|
|
|
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
|
|
|
|
|
|
|
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
|
|
|
var numberId = number + ".1";
|
|
|
|
textsecure.storage.putUnencrypted("number_id", numberId);
|
2014-10-12 00:19:16 +00:00
|
|
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
|
2014-10-10 01:54:23 +00:00
|
|
|
stepDone(1);
|
|
|
|
|
|
|
|
return textsecure.crypto.generateKeys().then(function(keys) {
|
|
|
|
stepDone(2);
|
|
|
|
return textsecure.api.registerKeys(keys).then(function() {
|
|
|
|
stepDone(3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-07-26 05:31:41 +00:00
|
|
|
|
|
|
|
window.textsecure.registerSecondDevice = function(encodedDeviceInit, cryptoInfo, stepDone) {
|
|
|
|
var deviceInit = textsecure.protos.decodeDeviceInit(encodedDeviceInit);
|
|
|
|
return cryptoInfo.decryptAndHandleDeviceInit(deviceInit).then(function(identityKey) {
|
|
|
|
if (identityKey.server != textsecure.api.relay)
|
|
|
|
throw new Error("Unknown relay used by master");
|
|
|
|
var number = identityKey.phoneNumber;
|
|
|
|
|
|
|
|
stepDone(1);
|
|
|
|
|
|
|
|
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
|
|
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
|
|
|
|
|
|
|
var password = btoa(getString(textsecure.crypto.getRandomBytes(16)));
|
|
|
|
password = password.substring(0, password.length - 2);
|
|
|
|
textsecure.storage.putEncrypted("password", password);
|
|
|
|
|
|
|
|
var registrationId = new Uint16Array(textsecure.crypto.getRandomBytes(2))[0];
|
|
|
|
registrationId = registrationId & 0x3fff;
|
|
|
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
|
|
|
|
|
|
|
return textsecure.api.confirmCode(number, identityKey.provisioningCode, password, signalingKey, registrationId, false).then(function(result) {
|
|
|
|
var numberId = number + "." + result;
|
|
|
|
textsecure.storage.putUnencrypted("number_id", numberId);
|
2014-10-12 00:19:16 +00:00
|
|
|
textsecure.storage.putUnencrypted("regionCode", libphonenumber.util.getRegion(number));
|
2014-07-26 05:31:41 +00:00
|
|
|
stepDone(2);
|
2014-05-27 18:40:39 +00:00
|
|
|
|
|
|
|
return textsecure.crypto.generateKeys().then(function(keys) {
|
|
|
|
stepDone(3);
|
|
|
|
return textsecure.api.registerKeys(keys).then(function() {
|
|
|
|
stepDone(4);
|
2014-07-26 05:31:41 +00:00
|
|
|
//TODO: Send DeviceControl.NEW_DEVICE_REGISTERED to all other devices
|
2014-05-27 18:40:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-07-26 05:31:41 +00:00
|
|
|
});
|
|
|
|
};
|