Add entirely untested secondary device init
This commit is contained in:
parent
379115d902
commit
a6b0d1f84b
9 changed files with 425 additions and 198 deletions
|
@ -18,7 +18,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
margin: 12px 0 0 100px; }
|
margin: 12px 100px 0 100px; }
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 30pt;
|
font-size: 30pt;
|
||||||
|
@ -30,6 +30,16 @@ h2 {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
font-weight: normal; }
|
font-weight: normal; }
|
||||||
|
|
||||||
|
.left-column {
|
||||||
|
float: left;
|
||||||
|
width: 45%;
|
||||||
|
text-align: center; }
|
||||||
|
|
||||||
|
.right-column {
|
||||||
|
float: right;
|
||||||
|
width: 50%;
|
||||||
|
text-align: center; }
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none; }
|
display: none; }
|
||||||
|
|
||||||
|
@ -37,9 +47,6 @@ h2 {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
height: 50px; }
|
height: 50px; }
|
||||||
|
|
||||||
#init-go-single-client {
|
|
||||||
display:block; }
|
|
||||||
|
|
||||||
#phonenumberspan {
|
#phonenumberspan {
|
||||||
display: block;
|
display: block;
|
||||||
margin: .5em auto 1em auto; }
|
margin: .5em auto 1em auto; }
|
||||||
|
|
2
js-deps/qrcode.min.js
vendored
2
js-deps/qrcode.min.js
vendored
File diff suppressed because one or more lines are too long
86
js/api.js
86
js/api.js
|
@ -26,6 +26,7 @@ window.textsecure.api = function() {
|
||||||
************************************************/
|
************************************************/
|
||||||
// Staging server
|
// Staging server
|
||||||
var URL_BASE = "https://textsecure-service-ca.whispersystems.org:4433";
|
var URL_BASE = "https://textsecure-service-ca.whispersystems.org:4433";
|
||||||
|
self.relay = "textsecure-service-staging.whispersystems.org";
|
||||||
|
|
||||||
// This is the real server
|
// This is the real server
|
||||||
//var URL_BASE = "https://textsecure-service.whispersystems.org";
|
//var URL_BASE = "https://textsecure-service.whispersystems.org";
|
||||||
|
@ -35,6 +36,7 @@ window.textsecure.api = function() {
|
||||||
URL_CALLS['devices'] = "/v1/devices";
|
URL_CALLS['devices'] = "/v1/devices";
|
||||||
URL_CALLS['keys'] = "/v2/keys";
|
URL_CALLS['keys'] = "/v2/keys";
|
||||||
URL_CALLS['push'] = "/v1/websocket";
|
URL_CALLS['push'] = "/v1/websocket";
|
||||||
|
URL_CALLS['temp_push'] = "/v1/temp_websocket";
|
||||||
URL_CALLS['messages'] = "/v1/messages";
|
URL_CALLS['messages'] = "/v1/messages";
|
||||||
URL_CALLS['attachment'] = "/v1/attachments";
|
URL_CALLS['attachment'] = "/v1/attachments";
|
||||||
|
|
||||||
|
@ -279,15 +281,93 @@ window.textsecure.api = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.getWebsocket = function() {
|
var getWebsocket = function(url, auth, reconnectTimeout) {
|
||||||
|
var URL = URL_BASE.replace(/^http/g, 'ws') + url + '/?';
|
||||||
|
if (auth) {
|
||||||
var user = textsecure.storage.getUnencrypted("number_id");
|
var user = textsecure.storage.getUnencrypted("number_id");
|
||||||
var password = textsecure.storage.getEncrypted("password");
|
var password = textsecure.storage.getEncrypted("password");
|
||||||
var URL = URL_BASE.replace(/^http/g, 'ws') + URL_CALLS['push'] + '/?';
|
|
||||||
var params = $.param({
|
var params = $.param({
|
||||||
login: '+' + getString(user).substring(1),
|
login: '+' + getString(user).substring(1),
|
||||||
password: getString(password)
|
password: getString(password)
|
||||||
});
|
});
|
||||||
return new WebSocket(URL+params);
|
} else
|
||||||
|
var params = $.param({});
|
||||||
|
|
||||||
|
var reconnectSemaphore = 0;
|
||||||
|
var pingInterval;
|
||||||
|
|
||||||
|
var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} };
|
||||||
|
|
||||||
|
var connect = function() {
|
||||||
|
reconnectSemaphore++;
|
||||||
|
if (reconnectSemaphore <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var socket = new WebSocket(URL+params);
|
||||||
|
|
||||||
|
socket.onerror = function(socketEvent) {
|
||||||
|
console.log('Server is down :(');
|
||||||
|
clearInterval(pingInterval);
|
||||||
|
reconnectSemaphore--;
|
||||||
|
setTimeout(function() { connect(); }, reconnectTimeout);
|
||||||
|
socketWrapper.ondisconnect();
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.onclose = function(socketEvent) {
|
||||||
|
console.log('Server closed :(');
|
||||||
|
clearInterval(pingInterval);
|
||||||
|
reconnectSemaphore--;
|
||||||
|
setTimeout(function() { connect(); }, reconnectTimeout);
|
||||||
|
socketWrapper.ondisconnect();
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.onopen = function(socketEvent) {
|
||||||
|
console.log('Connected to server!');
|
||||||
|
pingInterval = setInterval(function() {
|
||||||
|
console.log("Sending server ping message.");
|
||||||
|
if (socket.readyState == socket.CLOSED || socket.readyState == socket.CLOSING) {
|
||||||
|
socket.close();
|
||||||
|
socket.onclose();
|
||||||
|
} else
|
||||||
|
socket.send(JSON.stringify({type: 2}));
|
||||||
|
}, reconnectTimeout / 2);
|
||||||
|
socketWrapper.onconnect();
|
||||||
|
};
|
||||||
|
|
||||||
|
//TODO: wrap onmessage so that we reconnect on missing pong
|
||||||
|
socket.onmessage = function(response) {
|
||||||
|
try {
|
||||||
|
var message = JSON.parse(response.data);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Error parsing server JSON message: ' + response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type == 3)
|
||||||
|
console.log("Got pong message");
|
||||||
|
else if ((message.type === undefined && message.id !== undefined) || message.type === 4)
|
||||||
|
socketWrapper.onmessage(message);
|
||||||
|
else
|
||||||
|
console.log("Got invalid message from server: " + message);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
connect();
|
||||||
|
|
||||||
|
return socketWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.getMessageWebsocket = function() {
|
||||||
|
return getWebsocket(URL_CALLS['push'], true, 60000);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.getTempWebsocket = function() {
|
||||||
|
//XXX
|
||||||
|
var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} };
|
||||||
|
setTimeout(function() {
|
||||||
|
socketWrapper.onmessage({type: 4, message: "404-42-magic"});
|
||||||
|
}, 1000);
|
||||||
|
return socketWrapper;
|
||||||
|
//return getWebsocket(URL_CALLS['temp_push'], false, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
51
js/crypto.js
51
js/crypto.js
|
@ -110,9 +110,13 @@ window.textsecure.crypto = function() {
|
||||||
***************************/
|
***************************/
|
||||||
var crypto_storage = {};
|
var crypto_storage = {};
|
||||||
|
|
||||||
|
crypto_storage.putKeyPair = function(keyName, keyPair) {
|
||||||
|
textsecure.storage.putEncrypted("25519Key" + keyName, keyPair);
|
||||||
|
}
|
||||||
|
|
||||||
crypto_storage.getNewStoredKeyPair = function(keyName, isIdentity) {
|
crypto_storage.getNewStoredKeyPair = function(keyName, isIdentity) {
|
||||||
return createNewKeyPair(isIdentity).then(function(keyPair) {
|
return createNewKeyPair(isIdentity).then(function(keyPair) {
|
||||||
textsecure.storage.putEncrypted("25519Key" + keyName, keyPair);
|
crypto_storage.putKeyPair(keyName, keyPair);
|
||||||
return keyPair;
|
return keyPair;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -736,10 +740,10 @@ window.textsecure.crypto = function() {
|
||||||
|
|
||||||
var iv = decodedMessage.slice(1, 1 + 16);
|
var iv = decodedMessage.slice(1, 1 + 16);
|
||||||
var ciphertext = decodedMessage.slice(1 + 16, decodedMessage.byteLength - 10);
|
var ciphertext = decodedMessage.slice(1 + 16, decodedMessage.byteLength - 10);
|
||||||
var ivAndCiphertext = decodedMessage.slice(1, decodedMessage.byteLength - 10);
|
var ivAndCiphertext = decodedMessage.slice(0, decodedMessage.byteLength - 10);
|
||||||
var mac = decodedMessage.slice(decodedMessage.byteLength - 10, decodedMessage.byteLength);
|
var mac = decodedMessage.slice(decodedMessage.byteLength - 10, decodedMessage.byteLength);
|
||||||
|
|
||||||
return verifyMACWithVersionByte(ivAndCiphertext, mac_key, mac).then(function() {
|
return verifyMAC(ivAndCiphertext, mac_key, mac).then(function() {
|
||||||
return window.crypto.subtle.decrypt({name: "AES-CBC", iv: iv}, aes_key, ciphertext);
|
return window.crypto.subtle.decrypt({name: "AES-CBC", iv: iv}, aes_key, ciphertext);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -935,6 +939,47 @@ window.textsecure.crypto = function() {
|
||||||
|
|
||||||
self.Ed25519Verify = Ed25519Verify;
|
self.Ed25519Verify = Ed25519Verify;
|
||||||
|
|
||||||
|
self.prepareTempWebsocket = function() {
|
||||||
|
var socketInfo = {};
|
||||||
|
var keyPair;
|
||||||
|
|
||||||
|
socketInfo.decryptAndHandleDeviceInit = function(deviceInit) {
|
||||||
|
var masterEphemeral = toArrayBuffer(deviceInit.masterEphemeralPubKey);
|
||||||
|
var message = toArrayBuffer(deviceInit.identityKeyMessage);
|
||||||
|
|
||||||
|
return ECDHE(masterEphemeral, keyPair.privKey).then(function(ecRes) {
|
||||||
|
return HKDF(ecRes, masterEphemeral, "WhisperDeviceInit").then(function(keys) {
|
||||||
|
if (new Uint8Array(message)[0] != (3 << 4) | 3)
|
||||||
|
throw new Error("Bad version number on IdentityKeyMessage");
|
||||||
|
|
||||||
|
var iv = message.slice(1, 16 + 1);
|
||||||
|
var mac = message.slice(message.length - 32, message.length);
|
||||||
|
var ivAndCiphertext = message.slice(0, message.length - 32);
|
||||||
|
var ciphertext = message.slice(16 + 1, message.length - 32);
|
||||||
|
|
||||||
|
return verifyMAC(ivAndCiphertext, ecRes[1], mac).then(function() {
|
||||||
|
window.crypto.subtle.decrypt({name: "AES-CBC", iv: iv}, ecRes[0], ciphertext).then(function(plaintext) {
|
||||||
|
var identityKeyMsg = textsecure.protos.decodeIdentityKeyProtobuf(getString(plaintext));
|
||||||
|
|
||||||
|
privToPub(toArrayBuffer(identityKeyMsg.identityKey)).then(function(identityKeyPair) {
|
||||||
|
crypto_storage.putKeyPair("identityKey", identityKeyPair);
|
||||||
|
identityKeyMsg.identityKey = null;
|
||||||
|
|
||||||
|
return identityKeyMsg;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return createNewKeyPair(false).then(function(newKeyPair) {
|
||||||
|
keyPair = newKeyPair;
|
||||||
|
socketInfo.pubKey = keyPair.pubKey;
|
||||||
|
return socketInfo;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
self.testing_only = testing_only;
|
self.testing_only = testing_only;
|
||||||
return self;
|
return self;
|
||||||
}();
|
}();
|
||||||
|
|
125
js/helpers.js
125
js/helpers.js
|
@ -195,9 +195,19 @@ window.textsecure.protos = function() {
|
||||||
return self.PreKeyWhisperMessageProtobuf.decode(btoa(string));
|
return self.PreKeyWhisperMessageProtobuf.decode(btoa(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.KeyExchangeMessageProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/WhisperTextProtocol.proto").build("textsecure.KeyExchangeMessage");
|
self.DeviceInitProtobuf = dcodeIO.ProtoBuf.loadProtoFile("protos/DeviceMessages.proto").build("textsecure.DeviceInit");
|
||||||
self.decodeKeyExchangeMessageProtobuf = function(string) {
|
self.decodeDeviceInitProtobuf = function(string) {
|
||||||
return self.KeyExchangeMessageProtobuf.decode(btoa(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));
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -635,53 +645,10 @@ window.textsecure.replay = function() {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
// message_callback({message: decryptedMessage, pushMessage: server-providedPushMessage})
|
// message_callback({message: decryptedMessage, pushMessage: server-providedPushMessage})
|
||||||
window.textsecure.subscribeToPush = function() {
|
window.textsecure.subscribeToPush = function(message_callback) {
|
||||||
var subscribeToPushMessageSemaphore = 0;
|
var socket = textsecure.api.getMessageWebsocket();
|
||||||
return function(message_callback) {
|
|
||||||
subscribeToPushMessageSemaphore++;
|
|
||||||
if (subscribeToPushMessageSemaphore <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var socket = textsecure.api.getWebsocket();
|
socket.onmessage = function(message) {
|
||||||
|
|
||||||
var pingInterval;
|
|
||||||
|
|
||||||
//TODO: GUI
|
|
||||||
socket.onerror = function(socketEvent) {
|
|
||||||
console.log('Server is down :(');
|
|
||||||
clearInterval(pingInterval);
|
|
||||||
subscribeToPushMessageSemaphore--;
|
|
||||||
setTimeout(function() { textsecure.subscribeToPush(message_callback); }, 60000);
|
|
||||||
};
|
|
||||||
socket.onclose = function(socketEvent) {
|
|
||||||
console.log('Server closed :(');
|
|
||||||
clearInterval(pingInterval);
|
|
||||||
subscribeToPushMessageSemaphore--;
|
|
||||||
setTimeout(function() { textsecure.subscribeToPush(message_callback); }, 60000);
|
|
||||||
};
|
|
||||||
socket.onopen = function(socketEvent) {
|
|
||||||
console.log('Connected to server!');
|
|
||||||
pingInterval = setInterval(function() {
|
|
||||||
console.log("Sending server ping message.");
|
|
||||||
if (socket.readyState == socket.CLOSED || socket.readyState == socket.CLOSING) {
|
|
||||||
socket.close();
|
|
||||||
socket.onclose();
|
|
||||||
} else
|
|
||||||
socket.send(JSON.stringify({type: 2}));
|
|
||||||
}, 30000);
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onmessage = function(response) {
|
|
||||||
try {
|
|
||||||
var message = JSON.parse(response.data);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error parsing server JSON message: ' + response.responseBody.split("|")[1]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.type == 3) {
|
|
||||||
console.log("Got pong message");
|
|
||||||
} else if (message.type === undefined && message.id !== undefined) {
|
|
||||||
textsecure.crypto.decryptWebsocketMessage(message.message).then(function(plaintext) {
|
textsecure.crypto.decryptWebsocketMessage(message.message).then(function(plaintext) {
|
||||||
var proto = textsecure.protos.decodeIncomingPushMessageProtobuf(getString(plaintext));
|
var proto = textsecure.protos.decodeIncomingPushMessageProtobuf(getString(plaintext));
|
||||||
// After this point, a) decoding errors are not the server's fault, and
|
// After this point, a) decoding errors are not the server's fault, and
|
||||||
|
@ -776,13 +743,11 @@ window.textsecure.subscribeToPush = function() {
|
||||||
console.log("Error handling incoming message: ");
|
console.log("Error handling incoming message: ");
|
||||||
console.log(e);
|
console.log(e);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
}();
|
|
||||||
|
|
||||||
window.textsecure.register = function() {
|
window.textsecure.registerSingleDevice = function() {
|
||||||
return function(number, verificationCode, singleDevice, stepDone) {
|
return function(number, verificationCode, stepDone) {
|
||||||
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
|
||||||
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
textsecure.storage.putEncrypted('signaling_key', signalingKey);
|
||||||
|
|
||||||
|
@ -794,25 +759,55 @@ window.textsecure.register = function() {
|
||||||
registrationId = registrationId & 0x3fff;
|
registrationId = registrationId & 0x3fff;
|
||||||
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
textsecure.storage.putUnencrypted("registrationId", registrationId);
|
||||||
|
|
||||||
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, singleDevice).then(function(response) {
|
return textsecure.api.confirmCode(number, verificationCode, password, signalingKey, registrationId, true).then(function() {
|
||||||
if (singleDevice)
|
var numberId = number + ".1";
|
||||||
response = 1;
|
|
||||||
var numberId = number + "." + response;
|
|
||||||
textsecure.storage.putUnencrypted("number_id", numberId);
|
textsecure.storage.putUnencrypted("number_id", numberId);
|
||||||
textsecure.storage.putUnencrypted("regionCode", textsecure.utils.getRegionCodeForNumber(number));
|
textsecure.storage.putUnencrypted("regionCode", textsecure.utils.getRegionCodeForNumber(number));
|
||||||
stepDone(1);
|
stepDone(1);
|
||||||
|
|
||||||
if (!singleDevice) {
|
|
||||||
//TODO: Do things???
|
|
||||||
stepDone(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return textsecure.crypto.generateKeys().then(function(keys) {
|
return textsecure.crypto.generateKeys().then(function(keys) {
|
||||||
stepDone(3);
|
stepDone(2);
|
||||||
return textsecure.api.registerKeys(keys).then(function() {
|
return textsecure.api.registerKeys(keys).then(function() {
|
||||||
stepDone(4);
|
stepDone(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
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);
|
||||||
|
textsecure.storage.putUnencrypted("regionCode", textsecure.utils.getRegionCodeForNumber(number));
|
||||||
|
stepDone(2);
|
||||||
|
|
||||||
|
return textsecure.crypto.generateKeys().then(function(keys) {
|
||||||
|
stepDone(3);
|
||||||
|
return textsecure.api.registerKeys(keys).then(function() {
|
||||||
|
stepDone(4);
|
||||||
|
//TODO: Send DeviceControl.NEW_DEVICE_REGISTERED to all other devices
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -73,26 +73,23 @@ $('#init-go').click(function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$('#init-setup').hide();
|
$('#init-setup').hide();
|
||||||
$('#verify1done').text('');
|
$('#verify1').hide();
|
||||||
$('#verify2').hide();
|
$('#verify2done').text('');
|
||||||
$('#verify3done').text('');
|
$('#verify3done').text('');
|
||||||
$('#verify4done').text('');
|
$('#verify4done').text('');
|
||||||
|
$('#verify5').hide();
|
||||||
$('#verify').show();
|
$('#verify').show();
|
||||||
|
|
||||||
textsecure.register(parsedNumber, $('#code').val(), single_device, function(step) {
|
textsecure.registerSingleDevice(parsedNumber, $('#code').val(), function(step) {
|
||||||
switch(step) {
|
switch(step) {
|
||||||
case 1:
|
case 1:
|
||||||
$('#verify1done').text('done');
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$('#verify2done').text('done');
|
$('#verify2done').text('done');
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 2:
|
||||||
$('#verify3done').text('done');
|
$('#verify3done').text('done');
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 3:
|
||||||
$('#complete-number').text(parsedNumber);
|
$('#complete-number').text(parsedNumber);
|
||||||
$('#verify').hide();
|
$('#verify').hide();
|
||||||
$('#setup-complete').show();
|
$('#setup-complete').show();
|
||||||
|
@ -136,6 +133,61 @@ textsecure.registerOnLoadFunction(function() {
|
||||||
$('#regionCode').val(textsecure.utils.getRegionCodeForCountryCode($('#countrycode').val()));
|
$('#regionCode').val(textsecure.utils.getRegionCodeForCountryCode($('#countrycode').val()));
|
||||||
updateNumberColors();
|
updateNumberColors();
|
||||||
|
|
||||||
|
textsecure.crypto.prepareTempWebsocket().then(function(cryptoInfo) {
|
||||||
|
var qrCode = new QRCode(document.getElementById('setup-qr'));
|
||||||
|
var socket = textsecure.api.getTempWebsocket();
|
||||||
|
|
||||||
|
socket.onmessage = function(message) {
|
||||||
|
//TODO: Get a server format for this
|
||||||
|
if (message.type === 4) {
|
||||||
|
qrCode.makeCode('textsecure-device-init:/' +
|
||||||
|
'?channel_uuid=' + message.message +
|
||||||
|
'&channel_server=' + textsecure.api.relay +
|
||||||
|
'&publicKey=' + btoa(getString(cryptoInfo.publicKey)));
|
||||||
|
$('img').removeAttr('style');
|
||||||
|
$('#left-connecting').hide();
|
||||||
|
$('#left-setup').show();
|
||||||
|
$('#left-reconnecting').hide();
|
||||||
|
} else {
|
||||||
|
$('#init-setup').hide();
|
||||||
|
$('#verify1done').text('');
|
||||||
|
$('#verify2done').text('');
|
||||||
|
$('#verify3done').text('');
|
||||||
|
$('#verify4done').text('');
|
||||||
|
$('#verify5done').text('');
|
||||||
|
$('#verify').show();
|
||||||
|
|
||||||
|
|
||||||
|
textsecure.registerSecondDevice(cryptoInfo, message.message, function(step) {
|
||||||
|
switch(step) {
|
||||||
|
case 1:
|
||||||
|
$('#verify1done').text('done');
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$('#verify2done').text('done');
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$('#verify3done').text('done');
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
//TODO: User needs to verify number before we continue
|
||||||
|
$('#complete-number').text(parsedNumber);
|
||||||
|
$('#verify4done').text('done');
|
||||||
|
case 5:
|
||||||
|
$('#verify').hide();
|
||||||
|
$('#setup-complete').show();
|
||||||
|
registrationDone();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.ondisconnect = function() {
|
||||||
|
$('#left-connecting').hide();
|
||||||
|
$('#left-setup').hide();
|
||||||
|
$('#left-reconnecting').show();
|
||||||
|
};
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
$('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no
|
$('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no
|
||||||
$('#setup-complete').show();
|
$('#setup-complete').show();
|
||||||
|
|
26
options.html
26
options.html
|
@ -27,23 +27,38 @@
|
||||||
|
|
||||||
<h1><img id="textsecure-icon" src='icon.png'/> TextSecure</h1>
|
<h1><img id="textsecure-icon" src='icon.png'/> TextSecure</h1>
|
||||||
<div id="init-setup" class="hidden">
|
<div id="init-setup" class="hidden">
|
||||||
<h2>Welcome to TextSecure. To get started please get a 6-digit setup code from your phone and enter it below.</h2>
|
<h2>Welcome to TextSecure. If you want to register as a secondary device, follow the instructions on the left, if you want to register as the only device, follow the instructions on the right</h2>
|
||||||
<span>Please select your country:</span>
|
|
||||||
|
<div id="left-connecting" class="left-column">
|
||||||
|
Please wait while we connect to the push server...
|
||||||
|
</div>
|
||||||
|
<div id="left-setup" class="left-column hidden">
|
||||||
|
Please scan the QR code below on the master device: <br>
|
||||||
|
<div id="setup-qr"></div>
|
||||||
|
</div>
|
||||||
|
<div id="left-reconnecting" class="left-column hidden">
|
||||||
|
The push server disconnected, please wait while we reconnect...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="right-column">
|
||||||
|
<span>Please select your country or enter your country code below:</span>
|
||||||
<select id="regionCode">
|
<select id="regionCode">
|
||||||
<option value="ZZ" selected>Please choose your country.</option>
|
<option value="ZZ" selected>Please choose your country.</option>
|
||||||
</select>
|
</select>
|
||||||
<span id="phonenumberspan">Enter your phone number (including country code): + <input type="text" size="3" id="countrycode"> <input type="text" size="14" id="number"></span>
|
<span id="phonenumberspan">+ <input type="text" size="3" id="countrycode"> <input type="text" size="14" id="number"></span>
|
||||||
<button id="init-go-single-client" class="btn">Send single-client code</button>
|
<button id="init-go-single-client" class="btn">Send single-client code</button>
|
||||||
<div id="init-setup-verification" class="hidden">
|
<div id="init-setup-verification" class="hidden">
|
||||||
<p>Code: <input type="text" pattern="[0-9]{3}-?[0-9]{3}" title="Enter the 6-didgit verificaion code displayed on your phone." size="8" id="code" /></p>
|
<p>Code: <input type="text" pattern="[0-9]{3}-?[0-9]{3}" title="Enter the 6-didgit verificaion code displayed on your phone." size="8" id="code" /></p>
|
||||||
<button id="init-go" class="btn">Sync</button>
|
<button id="init-go" class="btn">Sync</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div id="verify" class="hidden">
|
<div id="verify" class="hidden">
|
||||||
<div id="verify1">Verifying number and setup code...<span id="verify1done"></span></div>
|
<div id="verify1">Receiving identity key...<span id="verify1done"></span></div>
|
||||||
<div id="verify2">Syncing with existing devices...<span id="verify2done"></span></div>
|
<div id="verify2">Verifying number and setup code...<span id="verify2done"></span></div>
|
||||||
<div id="verify3">Generating keys...<span id="verify3done"></span></div>
|
<div id="verify3">Generating keys...<span id="verify3done"></span></div>
|
||||||
<div id="verify4">Registering...<span id="verify4done"></span></div>
|
<div id="verify4">Registering...<span id="verify4done"></span></div>
|
||||||
|
<div id="verify5">Syncing with existing devices...<span id="verify5done"></span></div>
|
||||||
</div>
|
</div>
|
||||||
<div id="setup-complete" class="hidden">
|
<div id="setup-complete" class="hidden">
|
||||||
<h2>You are now registered on TextSecure with number <span id="complete-number"></span></h2>
|
<h2>You are now registered on TextSecure with number <span id="complete-number"></span></h2>
|
||||||
|
@ -59,6 +74,7 @@
|
||||||
<script type="text/javascript" src="js-deps/backbone.js"></script>
|
<script type="text/javascript" src="js-deps/backbone.js"></script>
|
||||||
<script type="text/javascript" src="js-deps/backbone.localStorage.js"></script>
|
<script type="text/javascript" src="js-deps/backbone.localStorage.js"></script>
|
||||||
<script type="text/javascript" src="js-deps/libphonenumber_api-compiled.js"></script>
|
<script type="text/javascript" src="js-deps/libphonenumber_api-compiled.js"></script>
|
||||||
|
<script type="text/javascript" src="js-deps/qrcode.min.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/helpers.js"></script>
|
<script type="text/javascript" src="js/helpers.js"></script>
|
||||||
<script type="text/javascript" src="js/webcrypto.js"></script>
|
<script type="text/javascript" src="js/webcrypto.js"></script>
|
||||||
|
|
30
protos/DeviceMessages.proto
Normal file
30
protos/DeviceMessages.proto
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package textsecure;
|
||||||
|
|
||||||
|
message DeviceInit {
|
||||||
|
required bytes masterEphemeralPubKey = 1;
|
||||||
|
required bytes identityKeyMessage = 2; // contains an IdentityKey
|
||||||
|
}
|
||||||
|
|
||||||
|
message IdentityKey {
|
||||||
|
required bytes identityKey = 1;
|
||||||
|
required string phoneNumber = 2;
|
||||||
|
required string server = 3;
|
||||||
|
required bool masterSupportsSms = 4;
|
||||||
|
required uint32 provisioningCode = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeviceControl {
|
||||||
|
enum Type {
|
||||||
|
UNKNOWN = 0;
|
||||||
|
NEW_DEVICE_REGISTERED = 1; // Requries only newDeviceId
|
||||||
|
SENT_MESSAGE = 2; // Requires only message
|
||||||
|
}
|
||||||
|
message MessageSent {
|
||||||
|
required string otherNumber = 1; // The destination account (ie phone #), not device
|
||||||
|
required uint64 timestamp = 2;
|
||||||
|
required bytes message = 3; // PushMessageContent
|
||||||
|
}
|
||||||
|
required Type type = 1;
|
||||||
|
optional uint32 newDeviceId = 2;
|
||||||
|
optional MessageSent message = 3;
|
||||||
|
}
|
|
@ -48,13 +48,15 @@
|
||||||
<script type="text/javascript" src="js-deps/backbone.localStorage.js"></script>
|
<script type="text/javascript" src="js-deps/backbone.localStorage.js"></script>
|
||||||
<script type="text/javascript" src="js-deps/libphonenumber_api-compiled.js"></script>
|
<script type="text/javascript" src="js-deps/libphonenumber_api-compiled.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/helpers.js"></script>
|
<script type="text/javascript" src="js-deps/blanket.min.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="js/helpers.js" data-cover></script>
|
||||||
<script type="text/javascript" src="js/webcrypto.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/crypto.js" data-cover></script>
|
||||||
<script type="text/javascript" src="js/models/messages.js"></script>
|
<script type="text/javascript" src="js/models/messages.js"></script>
|
||||||
<script type="text/javascript" src="js/models/threads.js"></script>
|
<script type="text/javascript" src="js/models/threads.js"></script>
|
||||||
<script type="text/javascript" src="js/api.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/sendmessage.js" data-cover></script>
|
||||||
|
|
||||||
<script type="text/javascript" src="js/chromium.js"></script>
|
<script type="text/javascript" src="js/chromium.js"></script>
|
||||||
<script type="text/javascript" src="js/fake_api.js"></script>
|
<script type="text/javascript" src="js/fake_api.js"></script>
|
||||||
|
|
Loading…
Reference in a new issue