From 3c1e0ad2ecd0b981d11f6e15bfd84b4c69b589db Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Jan 2015 12:47:13 -0600 Subject: [PATCH] Bug 1103120 - Part 11: Client: Pass auth settings from advertisement. r=past --- browser/devtools/webide/modules/runtimes.js | 5 +- toolkit/devtools/client/connection-manager.js | 63 +++++++++++++++++-- toolkit/devtools/client/dbg-client.jsm | 11 +++- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/browser/devtools/webide/modules/runtimes.js b/browser/devtools/webide/modules/runtimes.js index 90c22b41a17..4222127a1d9 100644 --- a/browser/devtools/webide/modules/runtimes.js +++ b/browser/devtools/webide/modules/runtimes.js @@ -447,9 +447,8 @@ WiFiRuntime.prototype = { if (!service) { return promise.reject(new Error("Can't find device: " + this.name)); } - connection.host = service.host; - connection.port = service.port; - connection.encryption = service.encryption; + connection.advertisement = service; + // TODO: Customize client authentication UX connection.connect(); return promise.resolve(); }, diff --git a/toolkit/devtools/client/connection-manager.js b/toolkit/devtools/client/connection-manager.js index ad4ed6eb3bd..2593b8490df 100644 --- a/toolkit/devtools/client/connection-manager.js +++ b/toolkit/devtools/client/connection-manager.js @@ -53,6 +53,11 @@ DevToolsUtils.defineLazyModuleGetter(this, "Task", * . store Reference to a local data store (see below) * . keepConnecting Should the connection keep trying to connect? * . encryption Should the connection be encrypted? + * . authentication What authentication scheme should be used? + * . authenticator The |Authenticator| instance used. Overriding + * properties of this instance may be useful to + * customize authentication UX for a specific use case. + * . advertisement The server's advertisement if found by discovery * . status Connection status: * Connection.Status.CONNECTED * Connection.Status.DISCONNECTED @@ -179,9 +184,60 @@ Connection.prototype = { this.emit(Connection.Events.PORT_CHANGED); }, + get authentication() { + return this._authentication; + }, + + set authentication(value) { + this._authentication = value; + // Create an |Authenticator| of this type + if (!value) { + this.authenticator = null; + return; + } + let AuthenticatorType = DebuggerClient.Authenticators.get(value); + this.authenticator = new AuthenticatorType.Client(); + }, + + get advertisement() { + return this._advertisement; + }, + + set advertisement(advertisement) { + // The full advertisement may contain more info than just the standard keys + // below, so keep a copy for use during connection later. + this._advertisement = advertisement; + if (advertisement) { + ["host", "port", "encryption", "authentication"].forEach(key => { + this[key] = advertisement[key]; + }); + } + }, + + /** + * Settings to be passed to |socketConnect| at connection time. + */ + get socketSettings() { + let settings = {}; + if (this.advertisement) { + // Use the advertisement as starting point if it exists, as it may contain + // extra data, like the server's cert. + Object.assign(settings, this.advertisement); + } + Object.assign(settings, { + host: this.host, + port: this.port, + encryption: this.encryption, + authenticator: this.authenticator + }); + return settings; + }, + resetOptions() { this.keepConnecting = false; this.encryption = false; + this.authentication = null; + this.advertisement = null; }, disconnect: function(force) { @@ -238,11 +294,8 @@ Connection.prototype = { if (!this.host) { return DebuggerServer.connectPipe(); } - let transport = yield DebuggerClient.socketConnect({ - host: this.host, - port: this.port, - encryption: this.encryption - }); + let settings = this.socketSettings; + let transport = yield DebuggerClient.socketConnect(settings); return transport; }), diff --git a/toolkit/devtools/client/dbg-client.jsm b/toolkit/devtools/client/dbg-client.jsm index 92d1afc4176..e22e73ee8ac 100644 --- a/toolkit/devtools/client/dbg-client.jsm +++ b/toolkit/devtools/client/dbg-client.jsm @@ -83,6 +83,9 @@ DevToolsUtils.defineLazyGetter(this, "DebuggerSocket", () => { let { DebuggerSocket } = devtools.require("devtools/toolkit/security/socket"); return DebuggerSocket; }); +DevToolsUtils.defineLazyGetter(this, "Authentication", () => { + return devtools.require("devtools/toolkit/security/auth"); +}); /** * TODO: Get rid of this API in favor of EventTarget (bug 1042642) @@ -372,11 +375,17 @@ DebuggerClient.Argument.prototype.getArgument = function (aParams) { return aParams[this.position]; }; -// Expose this to save callers the trouble of importing DebuggerSocket +// Expose these to save callers the trouble of importing DebuggerSocket DebuggerClient.socketConnect = function(options) { // Defined here instead of just copying the function to allow lazy-load return DebuggerSocket.connect(options); }; +DevToolsUtils.defineLazyGetter(DebuggerClient, "Authenticators", () => { + return Authentication.Authenticators; +}); +DevToolsUtils.defineLazyGetter(DebuggerClient, "AuthenticationResult", () => { + return Authentication.AuthenticationResult; +}); DebuggerClient.prototype = { /**