From 29b2ffc769f2cb9f40c5b70747a0c98fa3607da9 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 19 Jan 2015 10:23:25 -1000 Subject: [PATCH] Update to real server provisioning API --- js/libtextsecure.js | 11 +++-------- js/options.js | 18 ++++++++---------- libtextsecure/api.js | 10 ++-------- libtextsecure/protobufs.js | 1 + protos/DeviceMessages.proto | 4 ++++ 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 45d5528dd..14b3e4edd 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -5674,6 +5674,7 @@ CryptoJS.lib.Cipher || (function (undefined) { PushMessageContent : pushMessages.PushMessageContent, WhisperMessage : protocolMessages.WhisperMessage, PreKeyWhisperMessage : protocolMessages.PreKeyWhisperMessage, + ProvisioningUuid : deviceMessages.ProvisioningUuid, DeviceInit : deviceMessages.DeviceInit, IdentityKey : deviceMessages.IdentityKey, DeviceControl : deviceMessages.DeviceControl, @@ -6739,7 +6740,7 @@ window.textsecure.api = function () { URL_CALLS.devices = "/v1/devices"; URL_CALLS.keys = "/v2/keys"; URL_CALLS.push = "/v1/websocket"; - URL_CALLS.temp_push = "/v1/temp_websocket"; + URL_CALLS.temp_push = "/v1/provisioning"; URL_CALLS.messages = "/v1/messages"; URL_CALLS.attachment = "/v1/attachments"; @@ -7023,13 +7024,7 @@ window.textsecure.api = function () { } self.getTempWebsocket = function() { - //XXX - var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} }; - setTimeout(function() { - socketWrapper.onmessage({uuid: "404-42-magic"}); - }, 1000); - return socketWrapper; - //return getWebsocket(URL_CALLS['temp_push'], false, 5000); + return getWebsocket(URL_CALLS['temp_push'], false, 1000); } return self; diff --git a/js/options.js b/js/options.js index 75d1149a3..8c22ce603 100644 --- a/js/options.js +++ b/js/options.js @@ -137,16 +137,18 @@ $('#setup-qr').html(''); textsecure.protocol.prepareTempWebsocket().then(function(cryptoInfo) { var qrCode = new QRCode(document.getElementById('setup-qr')); - var socket = textsecure.api.getTempWebsocket(); - socket.onmessage = function(message) { - if (message.uuid) { + var socket = textsecure.api.getTempWebsocket(); + new WebSocketResource(socket, function(request) { + if (request.path == "/v1/address" && request.verb == "PUT") { + var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body); qrCode.makeCode('textsecure-device-init:/' + - '?channel_uuid=' + message.uuid + + '?channel_uuid=' + proto.uuid + '&channel_server=' + textsecure.api.relay + '&publicKey=' + btoa(getString(cryptoInfo.publicKey))); $('img').removeAttr('style'); $('#multi-device .status').text("Use your phone to scan the QR code.") + request.respond(200, 'OK'); } else { $('#init-setup').hide(); $('#verify1done').text(''); @@ -157,7 +159,7 @@ $('#verify').show().addClass('in'); - textsecure.registerSecondDevice(cryptoInfo, message.message, function(step) { + textsecure.registerSecondDevice(message.body, cryptoInfo, function(step) { switch(step) { case 1: $('#verify1done').text('done'); @@ -179,11 +181,7 @@ } }); } - }; - - socket.ondisconnect = function() { - $('#multi-device .status').text("The push server disconnected, please wait while we reconnect..."); - }; + }); }); }); } diff --git a/libtextsecure/api.js b/libtextsecure/api.js index d3096d840..e2b47d444 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -37,7 +37,7 @@ window.textsecure.api = function () { URL_CALLS.devices = "/v1/devices"; URL_CALLS.keys = "/v2/keys"; URL_CALLS.push = "/v1/websocket"; - URL_CALLS.temp_push = "/v1/temp_websocket"; + URL_CALLS.temp_push = "/v1/provisioning"; URL_CALLS.messages = "/v1/messages"; URL_CALLS.attachment = "/v1/attachments"; @@ -321,13 +321,7 @@ window.textsecure.api = function () { } self.getTempWebsocket = function() { - //XXX - var socketWrapper = { onmessage: function() {}, ondisconnect: function() {}, onconnect: function() {} }; - setTimeout(function() { - socketWrapper.onmessage({uuid: "404-42-magic"}); - }, 1000); - return socketWrapper; - //return getWebsocket(URL_CALLS['temp_push'], false, 5000); + return getWebsocket(URL_CALLS['temp_push'], false, 1000); } return self; diff --git a/libtextsecure/protobufs.js b/libtextsecure/protobufs.js index ec620b976..30869a524 100644 --- a/libtextsecure/protobufs.js +++ b/libtextsecure/protobufs.js @@ -15,6 +15,7 @@ PushMessageContent : pushMessages.PushMessageContent, WhisperMessage : protocolMessages.WhisperMessage, PreKeyWhisperMessage : protocolMessages.PreKeyWhisperMessage, + ProvisioningUuid : deviceMessages.ProvisioningUuid, DeviceInit : deviceMessages.DeviceInit, IdentityKey : deviceMessages.IdentityKey, DeviceControl : deviceMessages.DeviceControl, diff --git a/protos/DeviceMessages.proto b/protos/DeviceMessages.proto index c23bb2f68..355e7f910 100644 --- a/protos/DeviceMessages.proto +++ b/protos/DeviceMessages.proto @@ -1,5 +1,9 @@ package textsecure; +message ProvisioningUuid { + optional string uuid = 1; +} + message DeviceInit { required bytes masterEphemeralPubKey = 1; required bytes identityKeyMessage = 2; // contains an IdentityKey