From 37c496f4f0f51d527461700b503d70873e4fee17 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 4 May 2015 22:26:32 -0700 Subject: [PATCH] Close the provisioning socket --- js/libtextsecure.js | 5 ++++- libtextsecure/account_manager.js | 4 +++- libtextsecure/websocket.js | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index d4866ef2..565c8130 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38356,6 +38356,7 @@ TextSecureWebSocket = function (url) { function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); + if (calledClose) { return; } keepAliveTimer = setTimeout(function() { if (socket.readyState === WebSocket.OPEN) { socket.send( @@ -39298,7 +39299,8 @@ TextSecureServer = function () { registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) { return new Promise(function(resolve) { - new WebSocketResource(TextSecureServer.getTempWebsocket(), function(request) { + var socket = TextSecureServer.getTempWebsocket(); + new WebSocketResource(socket, function(request) { if (request.path == "/v1/address" && request.verb == "PUT") { var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body); setProvisioningUrl([ @@ -39309,6 +39311,7 @@ TextSecureServer = function () { } else if (request.path == "/v1/message" && request.verb == "PUT") { var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary'); request.respond(200, 'OK'); + socket.close(); resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) { return confirmNumber(provisionMessage.number).then(function() { return createAccount( diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 1ab06ad9..4a1f0b5c 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -41,7 +41,8 @@ registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) { return new Promise(function(resolve) { - new WebSocketResource(TextSecureServer.getTempWebsocket(), function(request) { + var socket = TextSecureServer.getTempWebsocket(); + new WebSocketResource(socket, function(request) { if (request.path == "/v1/address" && request.verb == "PUT") { var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body); setProvisioningUrl([ @@ -52,6 +53,7 @@ } else if (request.path == "/v1/message" && request.verb == "PUT") { var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary'); request.respond(200, 'OK'); + socket.close(); resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) { return confirmNumber(provisionMessage.number).then(function() { return createAccount( diff --git a/libtextsecure/websocket.js b/libtextsecure/websocket.js index 1366283c..5d818686 100644 --- a/libtextsecure/websocket.js +++ b/libtextsecure/websocket.js @@ -40,6 +40,7 @@ TextSecureWebSocket = function (url) { function resetKeepAliveTimer() { clearTimeout(keepAliveTimer); + if (calledClose) { return; } keepAliveTimer = setTimeout(function() { if (socket.readyState === WebSocket.OPEN) { socket.send(