Bug 1103120 - Part 7: Server: Provide session to default prompt. r=past

This commit is contained in:
J. Ryan Stinnett 2015-01-26 12:47:13 -06:00
Родитель de60148114
Коммит b12406c387
4 изменённых файлов: 131 добавлений и 44 удалений

Просмотреть файл

@ -71,11 +71,26 @@ Prompt.Server.prototype = {
* Determine whether a connection the server should be allowed or not based on
* this authenticator's policies.
*
* @param session object
* In PROMPT mode, the |session| includes:
* {
* client: {
* host,
* port
* },
* server: {
* host,
* port
* }
* }
* @return true if the connection should be permitted, false otherwise
*/
authenticate() {
return !Services.prefs.getBoolPref("devtools.debugger.prompt-connection") ||
this.allowConnection();
authenticate(session) {
if (!Services.prefs.getBoolPref("devtools.debugger.prompt-connection")) {
return true;
}
session.authentication = this.mode;
return this.allowConnection(session);
},
/**
@ -83,22 +98,21 @@ Prompt.Server.prototype = {
* implementation is used unless this is overridden on a particular
* authenticator instance.
*
* In PROMPT mode, the |allowConnection| method is provided:
* {
* authentication: "PROMPT",
* client: {
* host,
* port
* },
* server: {
* host,
* port
* }
* }
*
* It is expected that the implementation of |allowConnection| will show a
* prompt to the user so that they can allow or deny the connection.
*
* @param session object
* In PROMPT mode, the |session| includes:
* {
* client: {
* host,
* port
* },
* server: {
* host,
* port
* }
* }
* @return true if the connection should be permitted, false otherwise
*/
allowConnection: prompt.Server.defaultAllowConnection,
@ -175,10 +189,29 @@ OOBCert.Server.prototype = {
* Determine whether a connection the server should be allowed or not based on
* this authenticator's policies.
*
* @param session object
* In OOB_CERT mode, the |session| includes:
* {
* client: {
* host,
* port,
* cert: {
* sha256
* },
* },
* server: {
* host,
* port,
* cert: {
* sha256
* }
* }
* }
* @return true if the connection should be permitted, false otherwise
*/
authenticate() {
return this.allowConnection();
authenticate(session) {
session.authentication = this.mode;
return this.allowConnection(session);
},
/**
@ -186,28 +219,27 @@ OOBCert.Server.prototype = {
* implementation is used unless this is overridden on a particular
* authenticator instance.
*
* In OOB_CERT mode, the |allowConnection| method is provided:
* {
* authentication: "OOB_CERT",
* client: {
* host,
* port,
* cert: {
* sha256
* },
* },
* server: {
* host,
* port,
* cert: {
* sha256
* }
* }
* }
*
* It is expected that the implementation of |allowConnection| will show a
* prompt to the user so that they can allow or deny the connection.
*
* @param session object
* In OOB_CERT mode, the |session| includes:
* {
* client: {
* host,
* port,
* cert: {
* sha256
* },
* },
* server: {
* host,
* port,
* cert: {
* sha256
* }
* }
* }
* @return true if the connection should be permitted, false otherwise
*/
allowConnection: prompt.Server.defaultAllowConnection,

Просмотреть файл

@ -26,9 +26,19 @@ let Server = exports.Server = {};
*
* @return true if the connection should be permitted, false otherwise
*/
Server.defaultAllowConnection = () => {
Server.defaultAllowConnection = ({ client, server }) => {
let title = bundle.GetStringFromName("remoteIncomingPromptTitle");
let msg = bundle.GetStringFromName("remoteIncomingPromptMessage");
let header = bundle.GetStringFromName("remoteIncomingPromptHeader");
let clientEndpoint = `${client.host}:${client.port}`;
let clientMsg =
bundle.formatStringFromName("remoteIncomingPromptClientEndpoint",
[clientEndpoint], 1);
let serverEndpoint = `${server.host}:${server.port}`;
let serverMsg =
bundle.formatStringFromName("remoteIncomingPromptServerEndpoint",
[serverEndpoint], 1);
let footer = bundle.GetStringFromName("remoteIncomingPromptFooter");
let msg =`${header}\n\n${clientMsg}\n${serverMsg}\n\n${footer}`;
let disableButton = bundle.GetStringFromName("remoteIncomingPromptDisable");
let prompt = Services.prompt;
let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_OK +

Просмотреть файл

@ -345,6 +345,16 @@ SocketListener.prototype = {
DebuggerServer._removeListener(this);
},
get host() {
if (!this._socket) {
return null;
}
if (Services.prefs.getBoolPref("devtools.debugger.force-local")) {
return "127.0.0.1";
}
return "0.0.0.0";
},
/**
* Gets whether this listener uses a port number vs. a path.
*/
@ -395,6 +405,10 @@ function ServerSocketConnection(listener, socketTransport) {
ServerSocketConnection.prototype = {
get authentication() {
return this._listener.authenticator.mode;
},
get host() {
return this._socketTransport.host;
},
@ -407,6 +421,20 @@ ServerSocketConnection.prototype = {
return this.host + ":" + this.port;
},
get client() {
return {
host: this.host,
port: this.port
};
},
get server() {
return {
host: this._listener.host,
port: this._listener.port
};
},
/**
* This is the main authentication workflow. If any pieces reject a promise,
* the connection is denied. If the entire process resolves successfully,
@ -501,10 +529,14 @@ ServerSocketConnection.prototype = {
},
_authenticate() {
if (!this._listener.authenticator.authenticate()) {
return promise.reject(Cr.NS_ERROR_CONNECTION_REFUSED);
let result = this._listener.authenticator.authenticate({
client: this.client,
server: this.server
});
if (result) {
return promise.resolve();
}
return promise.resolve();
return promise.reject(Cr.NS_ERROR_CONNECTION_REFUSED);
},
deny(result) {

Просмотреть файл

@ -14,9 +14,22 @@
# dialog that prompts the user to allow the incoming connection.
remoteIncomingPromptTitle=Incoming Connection
# LOCALIZATION NOTE (remoteIncomingPromptMessage): The message displayed on the
# LOCALIZATION NOTE (remoteIncomingPromptHeader): Header displayed on the
# dialog that prompts the user to allow the incoming connection.
remoteIncomingPromptMessage=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser! Allow connection?
remoteIncomingPromptHeader=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser!
# LOCALIZATION NOTE (remoteIncomingPromptClientEndpoint): Part of the prompt
# dialog for the user to choose whether an incoming connection should be
# allowed.
# %1$S: The host and port of the client such as "127.0.0.1:6000"
remoteIncomingPromptClientEndpoint=Client Endpoint: %1$S
# LOCALIZATION NOTE (remoteIncomingPromptServerEndpoint): Part of the prompt
# dialog for the user to choose whether an incoming connection should be
# allowed.
# %1$S: The host and port of the server such as "127.0.0.1:6000"
remoteIncomingPromptServerEndpoint=Server Endpoint: %1$S
# LOCALIZATION NOTE (remoteIncomingPromptFooter): Footer displayed on the
# dialog that prompts the user to allow the incoming connection.
remoteIncomingPromptFooter=Allow connection?
# LOCALIZATION NOTE (remoteIncomingPromptDisable): The label displayed on the
# third button in the incoming connection dialog that lets the user disable the