[Pkg-privacy-commits] [xul-ext-monkeysphere] 176/296: scoping nearly all variables in monkeysphere.js (except for those which get bound to events)
Ximin Luo
infinity0 at moszumanska.debian.org
Mon Aug 24 07:39:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository xul-ext-monkeysphere.
commit 1f96408b34cba81e52933a289ffcf5f79c1ec8f5
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Wed Mar 10 23:23:21 2010 -0500
scoping nearly all variables in monkeysphere.js (except for those which get bound to events)
---
chrome/content/monkeysphere.js | 547 +++++++++++++++++++++--------------------
1 file changed, 277 insertions(+), 270 deletions(-)
diff --git a/chrome/content/monkeysphere.js b/chrome/content/monkeysphere.js
index 4846975..0c12b1e 100644
--- a/chrome/content/monkeysphere.js
+++ b/chrome/content/monkeysphere.js
@@ -32,7 +32,7 @@ var monkeysphere = (function() {
var agent_socket = function() {
var envvar = "MONKEYSPHERE_VALIDATION_AGENT_SOCKET";;
try {
- envvar = monkeysphere.prefs.getCharPref("validation_agent_socket_environment_variable");
+ envvar = prefs.getCharPref("validation_agent_socket_environment_variable");
} catch (e) {
log("falling back to built-in environment variable: " + envvar);
}
@@ -44,7 +44,7 @@ var monkeysphere = (function() {
if(!ret) {
ret = "http://localhost:8901";;
try {
- ret = monkeysphere.prefs.getCharPref("default_socket");
+ ret = prefs.getCharPref("default_socket");
} catch (e) {
log("falling back to built-in default socket location: " + ret);
}
@@ -96,67 +96,90 @@ var monkeysphere = (function() {
log("dump: " + key + " = " + obj[key]);
}
};
-
- return {
-
+
////////////////////////////////////////////////////////////
-// INITIALIZATION
+// OVERRIDE CACHE OBJECT
////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
- // initialization function
- init: function() {
- log("---- begin initialization ----");
+ // object to store and retrieve data about monkeysphere status for sites
+ // uses string of apd as key, and agent response as data
+ var overrides = (function() {
- // get localization messages
- monkeysphere.messages = document.getElementById("message_strings");
+ // response cache object
+ var responses = {};
- // create event listeners
- log("creating listeners...");
- gBrowser.addProgressListener(monkeysphere.progressListener);
- gBrowser.addTabsProgressListener(monkeysphere.tabProgressListener);
+ return {
- log("---- initialization complete ----");
- },
+ // set override
+ set: function(apd, agentResponse) {
+ log("**** SET OVERRIDE ****");
-////////////////////////////////////////////////////////////
-// LISTENERS
-////////////////////////////////////////////////////////////
+ var uri = apd.uri;
+ var cert = apd.cert;
- // https://developer.mozilla.org/en/nsIWebProgressListener
- progressListener: {
- onLocationChange: function(aWebProgress, aRequest, aLocation) {
- log("++++ PL location change: " + aLocation.prePath);
- monkeysphere.updateDisplay();
- },
+ var SSLStatus = getInvalidCertSSLStatus(uri);
+ var overrideBits = 0;
- onProgressChange: function() {},
- onSecurityChange: function() {},
- onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {},
- onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {}
- },
+ // set override bits
+ // FIXME: should this just be for all flags by default?
+ if(SSLStatus.isUntrusted) {
+ log("flag: ERROR_UNTRUSTED");
+ overrideBits |= certOverrideService.ERROR_UNTRUSTED;
+ }
+ if(SSLStatus.isDomainMismatch) {
+ log("flag: ERROR_MISMATCH");
+ overrideBits |= certOverrideService.ERROR_MISMATCH;
+ }
+ if(SSLStatus.isNotValidAtThisTime) {
+ log("flag: ERROR_TIME");
+ overrideBits |= certOverrideService.ERROR_TIME;
+ }
- // https://developer.mozilla.org/en/Listening_to_events_on_all_tabs
- tabProgressListener: {
- onSecurityChange: function(aBrowser, aWebProgress, aRequest, aState) {
- log("++++ tabPL security change: ");
- monkeysphere.checkSite(aBrowser, aState);
- },
+ log("overrideBits: " + overrideBits);
- onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocation) {
- //log("++++ tabPL location change: " + aLocation.prePath);
- },
- onProgressChange: function(aBrowser, awebProgress, aRequest, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
- //log("++++ tabPL progress change: " + curSelfProgress);
- },
- onStateChange: function(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
- log("++++ tabPL state change: " + aRequest);
- monkeysphere.updateDisplay();
- },
- onStatusChange: function(aBrowser, aWebProgress, aRequest, aStatus, aMessage) {
- //log("++++ tabPL status change: " + aRequest);
- }
- },
+ log("set cert override: " + uri.asciiHost + ":" + uri.port);
+ certOverrideService.rememberValidityOverride(uri.asciiHost, uri.port,
+ cert,
+ overrideBits,
+ true);
+
+ log("setting cache");
+ apd.log();
+ responses[apd.toOverrideLabel()] = agentResponse;
+ },
+
+ // return response object
+ response: function(apd) {
+ return responses[apd.toOverrideLabel()];
+ },
+
+ // return override status as bool, true for override set
+ certStatus: function(apd) {
+ var uri = apd.uri;
+ var aHashAlg = {};
+ var aFingerprint = {};
+ var aOverrideBits = {};
+ var aIsTemporary = {};
+ return certOverrideService.getValidityOverride(uri.asciiHost, uri.port,
+ aHashAlg,
+ aFingerprint,
+ aOverrideBits,
+ aIsTemporary);
+ },
+
+ // clear override
+ clear: function(apd) {
+ log("**** CLEAR OVERRIDE ****");
+ var uri = apd.uri;
+ log("clearing cert override");
+ certOverrideService.clearValidityOverride(uri.asciiHost, uri.port);
+ log("clearing cache");
+ apd.log();
+ delete responses[apd.toOverrideLabel()];
+ }
+ };
+ })();
////////////////////////////////////////////////////////////
// SITE URI CHECK FUNCTION
@@ -164,7 +187,7 @@ var monkeysphere = (function() {
//////////////////////////////////////////////////////////
// check uri is relevant to monkeysphere
- isRelevantURI: function(uri) {
+ isRelevantURI = function(uri) {
////////////////////////////////////////
// check host
try {
@@ -194,7 +217,7 @@ var monkeysphere = (function() {
// if uri is relevant for monkeysphere return true
return true;
- },
+ };
////////////////////////////////////////////////////////////
// MAIN SITE CHECK FUNCTION
@@ -202,14 +225,14 @@ var monkeysphere = (function() {
//////////////////////////////////////////////////////////
// check site monkeysphere status
- checkSite: function(browser, state) {
+ checkSite = function(browser, state) {
log("check site:");
var uri = browser.currentURI;
// if uri not relevant, return
- if(!monkeysphere.isRelevantURI(uri)) {
- monkeysphere.setStatus(browser, 'NEUTRAL');
+ if(!isRelevantURI(uri)) {
+ setStatus(browser, 'NEUTRAL');
return;
}
@@ -222,12 +245,12 @@ var monkeysphere = (function() {
// if a monkeysphere-generated cert override is being used by this connection, then we should be setting the status from the override
var cert = browser.securityUI.SSLStatus.serverCert;
- var apd = monkeysphere.createAgentPostData(uri, cert);
- var response = monkeysphere.overrides.response(apd);
+ var apd = createAgentPostData(uri, cert);
+ var response = overrides.response(apd);
if ( typeof response === 'undefined' ) {
- monkeysphere.setStatus(browser, 'NEUTRAL');
+ setStatus(browser, 'NEUTRAL');
} else {
- monkeysphere.setStatus(browser, 'VALID', response.message);
+ setStatus(browser, 'VALID', response.message);
}
return;
@@ -243,95 +266,38 @@ var monkeysphere = (function() {
////////////////////////////////////////
// get site certificate
log("retrieving site certificate:");
- var cert = monkeysphere.getInvalidCert(uri);
+ var cert = getInvalidCert(uri);
////////////////////////////////////////
// finally go ahead and query the agent
log("querying agent...");
- monkeysphere.queryAgent(browser, cert);
- },
+ queryAgent(browser, cert);
+ };
//////////////////////////////////////////////////////////
// set site monkeysphere status
- setStatus: function(browser, state, message) {
+ setStatus = function(browser, state, message) {
if ( typeof message === 'undefined' ) {
var key = "status" + state;
message = monkeysphere.messages.getString(key);
}
log("set browser status: " + state + ', ' + message);
browser.monkeysphere = { state: state, message: message };
- },
+ };
//////////////////////////////////////////////////////////
// clear site monkeysphere status for browser
- clearStatus: function(browser) {
+ clearStatus = function(browser) {
log("clear browser status");
delete browser.monkeysphere;
- },
-
-////////////////////////////////////////////////////////////
-// UPDATE DISPLAY
-////////////////////////////////////////////////////////////
-
- //////////////////////////////////////////////////////////
- // update the display for the currently visible browser
- updateDisplay: function() {
- log("update display:");
-
- var browser = gBrowser.selectedBrowser;
- var panel = document.getElementById("monkeysphere-status");
- var icon = document.getElementById("monkeysphere-status-image");
-
- // the following happens when called from a dialog
- if(!panel || !icon) {
- log(" panel/icon not available; falling back to window.opener");
- panel = window.opener.document.getElementById("monkeysphere-status");
- icon = window.opener.document.getElementById("monkeysphere-status-image");
- }
-
- // set state neutral by default
- var state = 'NEUTRAL';
- var message = "";
-
- // set from the browser monkeysphere state object if available
- if( typeof browser.monkeysphere !== "undefined" ) {
- state = browser.monkeysphere.state;
- message = browser.monkeysphere.message;
- }
-
- log(" state: " + state);
- switch(state){
- case 'INPROGRESS':
- icon.setAttribute("src", "chrome://monkeysphere/content/progress.gif");
- panel.hidden = false;
- break;
- case 'VALID':
- icon.setAttribute("src", "chrome://monkeysphere/content/good.png");
- panel.hidden = false;
- break;
- case 'NOTVALID':
- icon.setAttribute("src", "chrome://monkeysphere/content/bad.png");
- panel.hidden = false;
- break;
- case 'NEUTRAL':
- icon.setAttribute("src", "");
- panel.hidden = true;
- break;
- case 'ERROR':
- icon.setAttribute("src", "chrome://monkeysphere/content/error.png");
- panel.hidden = false;
- break;
- }
-
- log(" message: " + message);
- panel.setAttribute("tooltiptext", message);
- },
+ };
+
////////////////////////////////////////////////////////////
// AGENT QUERY FUNCTIONS
////////////////////////////////////////////////////////////
- createAgentPostData: function(uri, cert) {
+ createAgentPostData = function(uri, cert) {
// get certificate info
var cert_length = {};
var dummy = {};
@@ -366,11 +332,11 @@ var monkeysphere = (function() {
};
return apd;
- },
+ };
//////////////////////////////////////////////////////////
// query the validation agent
- queryAgent: function(browser, cert) {
+ queryAgent = function(browser, cert) {
log("#### querying validation agent ####");
var socket = agent_socket();
@@ -380,7 +346,7 @@ var monkeysphere = (function() {
var client = new XMLHttpRequest();
// make JSON query string
- client.apd = monkeysphere.createAgentPostData(uri, cert);
+ client.apd = createAgentPostData(uri, cert);
client.apd.log();
var query = client.apd.toJSON();
@@ -402,134 +368,8 @@ var monkeysphere = (function() {
log("sending query...");
client.send(query);
log("query sent");
- monkeysphere.setStatus(browser, 'INPROGRESS');
- },
-
- //////////////////////////////////////////////////////////
- // when the XMLHttpRequest to the agent state changes
- onAgentStateChange: function(client, browser, cert) {
- log("agent query state change: " + client.readyState);
- log(" status: " + client.status);
- log(" response: " + client.responseText);
-
- if (client.readyState == 4) {
- if (client.status == 200) {
-
- var response = JSON.parse(client.responseText);
-
- if (response.valid) {
-
- // VALID!
- log("SITE VERIFIED!");
- monkeysphere.overrides.set(client.apd, response);
- monkeysphere.setStatus(browser, 'VALID', response.message);
-
- // reload page
- log("reloading browser...");
- browser.webNavigation.reload(nsIWebNavigation.LOAD_FLAGS_NONE);
-
- } else {
-
- // NOT VALID
- log("site not verified.");
- monkeysphere.setStatus(browser, 'NOTVALID', response.message);
-
- }
- } else {
- log("validation agent did not respond.");
- //alert(monkeysphere.messages.getString("agentError"));
- monkeysphere.setStatus(browser, 'ERROR', monkeysphere.messages.getString('noResponseFromAgent'));
- }
-
- // update the current display, so that if we're looking at the
- // browser being processed, the result will be immediately displayed
- monkeysphere.updateDisplay();
- }
- },
-
-////////////////////////////////////////////////////////////
-// OVERRIDE CACHE OBJECT
-////////////////////////////////////////////////////////////
-
- //////////////////////////////////////////////////////////
- // object to store and retrieve data about monkeysphere status for sites
- // uses string of apd as key, and agent response as data
- overrides: (function() {
-
- // response cache object
- var responses = {};
-
- return {
-
- // set override
- set: function(apd, agentResponse) {
- log("**** SET OVERRIDE ****");
-
- var uri = apd.uri;
- var cert = apd.cert;
-
- var SSLStatus = monkeysphere.getInvalidCertSSLStatus(uri);
- var overrideBits = 0;
-
- // set override bits
- // FIXME: should this just be for all flags by default?
- if(SSLStatus.isUntrusted) {
- log("flag: ERROR_UNTRUSTED");
- overrideBits |= certOverrideService.ERROR_UNTRUSTED;
- }
- if(SSLStatus.isDomainMismatch) {
- log("flag: ERROR_MISMATCH");
- overrideBits |= certOverrideService.ERROR_MISMATCH;
- }
- if(SSLStatus.isNotValidAtThisTime) {
- log("flag: ERROR_TIME");
- overrideBits |= certOverrideService.ERROR_TIME;
- }
-
- log("overrideBits: " + overrideBits);
-
- log("set cert override: " + uri.asciiHost + ":" + uri.port);
- certOverrideService.rememberValidityOverride(uri.asciiHost, uri.port,
- cert,
- overrideBits,
- true);
-
- log("setting cache");
- apd.log();
- responses[apd.toOverrideLabel()] = agentResponse;
- },
-
- // return response object
- response: function(apd) {
- return responses[apd.toOverrideLabel()];
- },
-
- // return override status as bool, true for override set
- certStatus: function(apd) {
- var uri = apd.uri;
- var aHashAlg = {};
- var aFingerprint = {};
- var aOverrideBits = {};
- var aIsTemporary = {};
- return certOverrideService.getValidityOverride(uri.asciiHost, uri.port,
- aHashAlg,
- aFingerprint,
- aOverrideBits,
- aIsTemporary);
- },
-
- // clear override
- clear: function(apd) {
- log("**** CLEAR OVERRIDE ****");
- var uri = apd.uri;
- log("clearing cert override");
- certOverrideService.clearValidityOverride(uri.asciiHost, uri.port);
- log("clearing cache");
- apd.log();
- delete responses[apd.toOverrideLabel()];
- }
- };
- })(),
+ setStatus(browser, 'INPROGRESS');
+ };
////////////////////////////////////////////////////////////
// CERT FUNCTIONS
@@ -540,20 +380,20 @@ var monkeysphere = (function() {
// securityUI = [xpconnect wrapped (nsISupports, nsISecureBrowserUI, nsISSLStatusProvider)]
// but i don't think it can be used because it doesn't hold invalid cert info
// FIXME: is there a better way to get the cert for the actual current connection?
- getInvalidCert: function(uri) {
+ getInvalidCert = function(uri) {
try {
- var cert = monkeysphere.getInvalidCertSSLStatus(uri).QueryInterface(Components.interfaces.nsISSLStatus).serverCert;
- monkeysphere.printCertInfo(cert);
+ var cert = getInvalidCertSSLStatus(uri).QueryInterface(Components.interfaces.nsISSLStatus).serverCert;
+ printCertInfo(cert);
return cert;
} catch(e) {
return null;
}
- },
+ };
//////////////////////////////////////////////////////////
// gets current ssl status info
// http://www.oxymoronical.com/experiments/apidocs/interface/nsIRecentBadCertsService
- getInvalidCertSSLStatus: function(uri) {
+ getInvalidCertSSLStatus = function(uri) {
var recentCertsService =
Components.classes["@mozilla.org/security/recentbadcerts;1"].getService(Components.interfaces.nsIRecentBadCertsService);
if (!recentCertsService)
@@ -569,12 +409,12 @@ var monkeysphere = (function() {
return null;
return SSLStatus;
- },
+ };
//////////////////////////////////////////////////////////
// Print SSL certificate details
// https://developer.mozilla.org/En/How_to_check_the_security_state_of_an_XMLHTTPRequest_over_SSL
- printCertInfo: function(cert) {
+ printCertInfo = function(cert) {
const Ci = Components.interfaces;
log("certificate:");
@@ -615,6 +455,173 @@ var monkeysphere = (function() {
var validity = cert.validity.QueryInterface(Ci.nsIX509CertValidity);
log("\tValid from: " + validity.notBeforeGMT);
log("\tValid until: " + validity.notAfterGMT);
+ };
+
+
+////////////////////////////////////////////////////////////
+// UPDATE DISPLAY
+////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////
+ // update the display for the currently visible browser
+ updateDisplay = function() {
+ log("update display:");
+
+ var browser = gBrowser.selectedBrowser;
+ var panel = document.getElementById("monkeysphere-status");
+ var icon = document.getElementById("monkeysphere-status-image");
+
+ // the following happens when called from a dialog
+ if(!panel || !icon) {
+ log(" panel/icon not available; falling back to window.opener");
+ panel = window.opener.document.getElementById("monkeysphere-status");
+ icon = window.opener.document.getElementById("monkeysphere-status-image");
+ }
+
+ // set state neutral by default
+ var state = 'NEUTRAL';
+ var message = "";
+
+ // set from the browser monkeysphere state object if available
+ if( typeof browser.monkeysphere !== "undefined" ) {
+ state = browser.monkeysphere.state;
+ message = browser.monkeysphere.message;
+ }
+
+ log(" state: " + state);
+ switch(state){
+ case 'INPROGRESS':
+ icon.setAttribute("src", "chrome://monkeysphere/content/progress.gif");
+ panel.hidden = false;
+ break;
+ case 'VALID':
+ icon.setAttribute("src", "chrome://monkeysphere/content/good.png");
+ panel.hidden = false;
+ break;
+ case 'NOTVALID':
+ icon.setAttribute("src", "chrome://monkeysphere/content/bad.png");
+ panel.hidden = false;
+ break;
+ case 'NEUTRAL':
+ icon.setAttribute("src", "");
+ panel.hidden = true;
+ break;
+ case 'ERROR':
+ icon.setAttribute("src", "chrome://monkeysphere/content/error.png");
+ panel.hidden = false;
+ break;
+ }
+
+ log(" message: " + message);
+ panel.setAttribute("tooltiptext", message);
+ };
+
+
+////////////////////////////////////////////////////////////
+// EXTERNAL INTERFACE
+////////////////////////////////////////////////////////////
+
+ return {
+
+////////////////////////////////////////////////////////////
+// INITIALIZATION
+////////////////////////////////////////////////////////////
+
+ //////////////////////////////////////////////////////////
+ // initialization function
+ init: function() {
+ log("---- begin initialization ----");
+
+ // get localization messages
+ monkeysphere.messages = document.getElementById("message_strings");
+
+ // create event listeners
+ log("creating listeners...");
+ gBrowser.addProgressListener(monkeysphere.progressListener);
+ gBrowser.addTabsProgressListener(monkeysphere.tabProgressListener);
+
+ log("---- initialization complete ----");
+ },
+
+////////////////////////////////////////////////////////////
+// LISTENERS
+////////////////////////////////////////////////////////////
+
+ // https://developer.mozilla.org/en/nsIWebProgressListener
+ progressListener: {
+ onLocationChange: function(aWebProgress, aRequest, aLocation) {
+ log("++++ PL location change: " + aLocation.prePath);
+ updateDisplay();
+ },
+
+ onProgressChange: function() {},
+ onSecurityChange: function() {},
+ onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {},
+ onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {}
+ },
+
+ // https://developer.mozilla.org/en/Listening_to_events_on_all_tabs
+ tabProgressListener: {
+ onSecurityChange: function(aBrowser, aWebProgress, aRequest, aState) {
+ log("++++ tabPL security change: ");
+ checkSite(aBrowser, aState);
+ },
+
+ onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocation) {
+ //log("++++ tabPL location change: " + aLocation.prePath);
+ },
+ onProgressChange: function(aBrowser, awebProgress, aRequest, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
+ //log("++++ tabPL progress change: " + curSelfProgress);
+ },
+ onStateChange: function(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
+ log("++++ tabPL state change: " + aRequest);
+ updateDisplay();
+ },
+ onStatusChange: function(aBrowser, aWebProgress, aRequest, aStatus, aMessage) {
+ //log("++++ tabPL status change: " + aRequest);
+ }
+ },
+
+ //////////////////////////////////////////////////////////
+ // when the XMLHttpRequest to the agent state changes
+ onAgentStateChange: function(client, browser, cert) {
+ log("agent query state change: " + client.readyState);
+ log(" status: " + client.status);
+ log(" response: " + client.responseText);
+
+ if (client.readyState == 4) {
+ if (client.status == 200) {
+
+ var response = JSON.parse(client.responseText);
+
+ if (response.valid) {
+
+ // VALID!
+ log("SITE VERIFIED!");
+ overrides.set(client.apd, response);
+ setStatus(browser, 'VALID', response.message);
+
+ // reload page
+ log("reloading browser...");
+ browser.webNavigation.reload(nsIWebNavigation.LOAD_FLAGS_NONE);
+
+ } else {
+
+ // NOT VALID
+ log("site not verified.");
+ setStatus(browser, 'NOTVALID', response.message);
+
+ }
+ } else {
+ log("validation agent did not respond.");
+ //alert(monkeysphere.messages.getString("agentError"));
+ setStatus(browser, 'ERROR', monkeysphere.messages.getString('noResponseFromAgent'));
+ }
+
+ // update the current display, so that if we're looking at the
+ // browser being processed, the result will be immediately displayed
+ updateDisplay();
+ }
},
////////////////////////////////////////////////////////////
@@ -632,16 +639,16 @@ var monkeysphere = (function() {
log("no valid cert found?");
return;
}
- var apd = monkeysphere.createAgentPostData(uri, cert);
- monkeysphere.overrides.clear(apd);
+ var apd = createAgentPostData(uri, cert);
+ overrides.clear(apd);
// FIXME: why does the override seem to persist after a clear?
- if(!monkeysphere.overrides.certStatus(apd)) {
+ if(!overrides.certStatus(apd)) {
alert('Monkeysphere: site clear error. Is override cert cleared?');
}
var newstate = browser.monkeysphere.state;
var newmessage = browser.monkeysphere.message + ' [NO LONGER CACHED]';
- monkeysphere.setStatus(browser, newstate, newmessage);
- monkeysphere.updateDisplay();
+ setStatus(browser, newstate, newmessage);
+ updateDisplay();
},
certs: function() {
@@ -654,4 +661,4 @@ var monkeysphere = (function() {
}
}
};
- })();
+})();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/xul-ext-monkeysphere.git
More information about the Pkg-privacy-commits
mailing list