[Pkg-mozext-commits] [perspectives-extension] 12/72: Check if signature and timestaps are correct and display in notary results accordingly. Fixes #62. To test this set breakpoint in notaryAjaxCallback() and manually set server_result.is_valid = false

David Prévot taffit at moszumanska.debian.org
Thu Dec 11 02:12:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository perspectives-extension.

commit 64a92234104c01f5c9f18d41dddb116bd81b3e9d
Author: Gerold Meisinger <gerold.meisinger at gmail.com>
Date:   Tue Jun 17 22:32:43 2014 +0100

    Check if signature and timestaps are correct and display in notary results accordingly.
    Fixes #62. To test this set breakpoint in notaryAjaxCallback() and manually set server_result.is_valid = false
    
    changed in generate_svg: removed red from color keys as it's now used for "invalid signature"
    changed in *: some code cleanup and hasOwnProperty checks
---
 plugin/chrome/content/generate_svg.js      | 300 +++++++++++++++--------------
 plugin/chrome/content/notaries.js          | 143 ++++++++------
 plugin/chrome/content/xml_notary_client.js |  39 ++--
 3 files changed, 268 insertions(+), 214 deletions(-)

diff --git a/plugin/chrome/content/generate_svg.js b/plugin/chrome/content/generate_svg.js
index 0b3d837..b340c57 100644
--- a/plugin/chrome/content/generate_svg.js
+++ b/plugin/chrome/content/generate_svg.js
@@ -16,196 +16,212 @@
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-
 var Pers_gen = {
-	colors : [ "blue","purple","yellow","orange","cyan", "red", 
-			"brown" ],
-
-	num_sort_desc: function(a,b) { 
-		return b - a; 
-	}, 
-
- 
-	setup_color_info: function(server_result_list,cutoff,color_info) { 
-		var key_to_ts_list = {}; 
-		for(var i = 0; i < server_result_list.length; i++) { 
-			var results = server_result_list[i]; 
-			for(var j = 0; j < results.obs.length; j++) { 
+	colors : ["blue", "purple", "yellow", "orange", "cyan", "brown"],
+
+	num_sort_desc: function(a, b) {
+		return b - a;
+	},
+
+	setup_color_info: function(server_result_list, cutoff, color_info) {
+		var key_to_ts_list = {};
+		for(var i = 0; i < server_result_list.length; i++) {
+			var results = server_result_list[i];
+			for(var j = 0; j < results.obs.length; j++) {
 				var obs = results.obs[j];
-				if (key_to_ts_list[obs.key] == null)  
-					key_to_ts_list[obs.key] = []; 
-				for(k = 0; k < obs.timestamps.length; k++) { 
-					var ts = obs.timestamps[k].end; 
-					key_to_ts_list[obs.key].push(ts); 
-				} 
+				if (key_to_ts_list[obs.key] == null) {
+					key_to_ts_list[obs.key] = [];
+				}
+				for(var k = 0; k < obs.timestamps.length; k++) {
+					var ts = obs.timestamps[k].end;
+					key_to_ts_list[obs.key].push(ts);
+				}
 			}
 		}
-		var most_recent_list = []; 
-		for(key in key_to_ts_list) { 
-			key_to_ts_list[key].sort(Pers_gen.num_sort_desc);
-			var most_recent_ts = key_to_ts_list[key][0]; 
-			if(most_recent_ts >= cutoff) { 
-				most_recent_list.push({ "key" : key, 
-					"ts" : most_recent_ts });
-			} 
+
+		var most_recent_list = [];
+		for(var key in key_to_ts_list) {
+			if(key_to_ts_list.hasOwnProperty(key)) {
+				key_to_ts_list[key].sort(Pers_gen.num_sort_desc);
+				var most_recent_ts = key_to_ts_list[key][0];
+				if(most_recent_ts >= cutoff) {
+					most_recent_list.push({ "key" : key,
+						"ts" : most_recent_ts });
+				}
+			}
 		}
-		var most_recent_ts = function (a, b) { 
-			return b.ts - a.ts; 
-		}  
+		var most_recent_ts = function(a, b) {
+			return b.ts - a.ts;
+		};
 		most_recent_list.sort(most_recent_ts);
-		Pers_debug.d_print("main","most_recent_list");
-		Pers_debug.d_print("main", most_recent_list);
+		Pers_debug.d_print("main", "most_recent_list");
+		Pers_debug.d_print("main", most_recent_list  );
 		var color_count = 0;
-		for(var i = 0; i < most_recent_list.length && 
-			 i < Pers_gen.colors.length; i++) { 
-			color_count++; 
-			color_info[most_recent_list[i].key] = Pers_gen.colors[i]; 
-		}  	
-		return color_count;    
-	}, 
- 
-
-	get_svg_graph: function(service_id, server_result_list, len_days,cur_secs, 
+		for(var i = 0; i < most_recent_list.length &&
+			 i < Pers_gen.colors.length; i++) {
+			color_count++;
+			color_info[most_recent_list[i].key] = Pers_gen.colors[i];
+		}
+		return color_count;
+	},
+
+	get_svg_graph: function(service_id, server_result_list, len_days, cur_secs,
 							browser_key, max_stale_sec) {
-		var x_offset = 230, y_offset = 40; 
+		var x_offset = 230, y_offset = 40;
 		var width = 700;
-		var y_cord = y_offset; 
-		var pixels_per_day = (width - x_offset - 20) / len_days; 
-		var rec_height = 10; 
-		var grey_used = false; 
+		var y_cord = y_offset;
+		var pixels_per_day = (width - x_offset - 20) / len_days;
+		var rec_height = 10;
+		var grey_used = false;
 		var cutoff = cur_secs - Pers_util.DAY2SEC(len_days);
-		var color_info = {};  
-		var color_count = Pers_gen.setup_color_info(server_result_list, 
-							cutoff,color_info);
-		var height = color_count * 30 + server_result_list.length * 20 
+		var color_info = {};
+		var color_count = Pers_gen.setup_color_info(server_result_list,
+							cutoff, color_info); // sort
+		var height = color_count * 30 + server_result_list.length * 20
 			 	+ y_offset + 60;
-		var stale_cutoff = cur_secs - max_stale_sec; 
+		var stale_cutoff = cur_secs - max_stale_sec;
 
-		color_info[browser_key] = "green"; 	
-		var tmp_x = x_offset + 70;
+		color_info[browser_key] = "green";
 
 		if(Perspectives.strbundle == null) {
 			Perspectives.strbundle = document.getElementById("notary_strings");
 		}
 
-		var res =  '<?xml version="1.0"?>\n' 
+		var res =  '<?xml version="1.0"?>\n'
 					+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
 					+   '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n'
-					+  	'<svg xmlns="http://www.w3.org/2000/svg" version="1.1"' 
+					+  	'<svg xmlns="http://www.w3.org/2000/svg" version="1.1"'
 					+    ' width="' + width + '" height="' + height + '">\n'
-					+    '<rect x="0" y="0" width="' + width + '" ' 
+					+    '<rect x="0" y="0" width="' + width + '" '
 					+ 	'height="' + height + '" fill="white" />'
-					+    '<text x="' + (x_offset + 70)  
+					+    '<text x="' + (x_offset + 70)
 					+	'" y="' +  y_cord + '" font-size="15" >'
 					+	Perspectives.strbundle.getString("LegendKeyHistory")
 					+    '</text>\n'
-					+    '<text x="4" y="' + y_cord 
+					+    '<text x="4" y="' + y_cord
 					+ 	'" font-size="15">'
 					+	Perspectives.strbundle.getString("LegendNotaryAndCurrentKey")
 					+	'</text>\n';
-   
+
 		y_cord += 20;
 		for(var i = 0; i < server_result_list.length; i++) {
 			var most_recent_color = "white"; // none
-			var most_recent_end = 0;  
-			var results = server_result_list[i]; 
+			var most_recent_end = 0;
+			var results = server_result_list[i];
 			var servername = results.server.replace(/^https?\:\/\//, '');
-			y_cord += 20; 
-			res += '<text x="4" y="' + (y_cord + 8) + '" font-size="10">' 
+			y_cord += 20;
+			res += '<text x="4" y="' + (y_cord + 8) + '" font-size="10">'
 				+ servername + '</text>\n';
- 
-			for(var j = 0; j < results.obs.length; j++) { 
-				var obs = results.obs[j];
-				var color = color_info[obs.key]; 
-				if(color == null)
-					color = "grey"; // default color 
 
-				for(k = 0; k < obs.timestamps.length; k++) { 
+			for(var j = 0; j < results.obs.length; j++) {
+				var obs   = results.obs[j];
+				var color = color_info[obs.key];
+				if(results.is_valid != null && !results.is_valid) {
+					color = "red";
+				} else if(color == null) {
+					color = "grey"; // default color
+				}
+
+				for(var k = 0; k < obs.timestamps.length; k++) {
 					var t_start = obs.timestamps[k].start;
-					var t_end = obs.timestamps[k].end;
-					if(t_end < cutoff)
+					var t_end   = obs.timestamps[k].end;
+					if(t_end < cutoff) {
 						continue;
-					if(t_start < cutoff)
-						t_start = cutoff; // draw partial 
-					if(t_end > most_recent_end) { 
-						most_recent_end = t_end;
-						most_recent_color = color; 
-					} 
-					if(color == "grey") 
-						grey_used = true; 
-					var time_since = cur_secs - t_end; 
-					var duration = t_end - t_start; 
-					var x_cord = x_offset + 
-					parseInt(pixels_per_day * Pers_util.SEC2DAY(time_since)); 
-					var span_width = pixels_per_day * 
-						Pers_util.SEC2DAY(duration); 
-					// a timespan with no width is not shown        
-					if(span_width > 0) {          
-						res += '<rect x="' + x_cord 
-							+ '" y="' + y_cord + '"'
-							+  ' width="' + span_width + '"'
+					}
+					if(t_start < cutoff) {
+						t_start = cutoff; // draw partial
+					}
+					if(t_end > most_recent_end) {
+						most_recent_end   = t_end;
+						most_recent_color = color;
+					}
+					if(color === "grey") {
+						grey_used = true;
+					}
+					var time_since = cur_secs - t_end;
+					var duration   = t_end - t_start;
+					var x_cord     = x_offset +
+						parseInt(pixels_per_day * Pers_util.SEC2DAY(time_since), 10);
+					var span_width =
+						parseInt(pixels_per_day * Pers_util.SEC2DAY(duration), 10);
+					// a timespan with no width is not shown
+					if(span_width > 0) {
+						res += '<rect x="' + x_cord
+							+ '" y="'      + y_cord     + '"'
+							+  ' width="'  + span_width + '"'
 							+  ' height="' + rec_height + '"'
-							+  ' fill="' + color + '" rx="1"' 
-							+  ' stroke="black" stroke-width="1px" />\n'; 
+							+  ' fill="'   + color      + '" rx="1"'
+							+  ' stroke="black" stroke-width="1px" />\n';
 					}
 				} // end per-timespan
- 
-			} // end per-key  
+
+				if(results.is_valid != null && !results.is_valid) {
+					res += '<text x="' + x_offset + '" y="' + (y_cord + 8) + '" font-size="10">'
+							+ "Invalid signature" + '</text>\n'; // TODO: localize
+				}
+			} // end per-key
 
 			// if the most recent key is stale and thus
 			// will be ignored by the client, don't show
 			// it as the "current key"
-	    		if(most_recent_end < stale_cutoff) { 
-				most_recent_color = "white"; 
-			} 
+	    	if(most_recent_end < stale_cutoff) {
+				most_recent_color = "white";
+			}
+
+			if(results.is_valid != null && !results.is_valid) {
+				most_recent_color = "red";
+			}
 
-			// print "current key" circle      
-			res += '<rect x="' + (x_offset - 30) + '" y="' + y_cord 
-				+ '" width="10" height="10" fill="' + most_recent_color 
+			// print "current key" circle
+			res += '<rect x="' + (x_offset - 30) + '" y="' + y_cord
+				+ '" width="10" height="10" fill="' + most_recent_color
 				+ '" rx="5" stroke="black" stroke-width="1px" />\n';
-		} // end per-server 
-  	
-		// draw Days axis  
-		for(var i = 0; i < 11; i++) {    
+		} // end per-server
+
+		// draw Days axis
+		for(var i = 0; i < 11; i++) {
 			var days = i * (len_days / 10.0);
 			var x = x_offset + (pixels_per_day * days);
-			var y = y_offset + 30;    
-			if(len_days < 10 && days != 0)  {  
+			var y = y_offset + 30;
+			if(len_days < 10 && days != 0) {
 				// print with decimal point (broken)
-				res += '<text x="' + x + '" y="' + y 
-					+ '" font-size="15">' 
-					+ days + '</text>\n'; 
-          	} else {      
-				res += '<text x="' + x + '" y="' + y 
-					+ '" font-size="15">' 
-					+ days + '</text>\n'; 
-			}    
-			res += '<path d = "M ' + x + ' ' + y +  ' L ' + x 
-				+ ' ' + (y_cord + 20) 
-				+ '" stroke = "grey" stroke-width = "1"/>\n'; 
-		} 
-	
+				res += '<text x="' + x + '" y="' + y
+					+ '" font-size="15">'
+					+ days + '</text>\n';
+          	} else {
+				res += '<text x="' + x + '" y="' + y
+					+ '" font-size="15">'
+					+ days + '</text>\n';
+			}
+			res += '<path d = "M ' + x + ' ' + y +  ' L ' + x
+				+ ' ' + (y_cord + 20)
+				+ '" stroke = "grey" stroke-width = "1"/>\n';
+		}
+
 		// draw legend mapping colors to keys
 		y_cord += 30;
-		if(grey_used) 
-			color_info["all other keys"] = "grey"; 
-		for (key in color_info) {
-			var match_text = "";
-			if (key == browser_key) {
-				match_text = " (" +
-					Perspectives.strbundle.getString("LegendBrowsersKey") + ")";
+		if(grey_used) {
+			color_info["all other keys"] = "grey";
+		}
+		for (var key in color_info) {
+			if(color_info.hasOwnProperty(key)) {
+				var match_text = "";
+				if (key === browser_key) {
+					match_text = " (" +
+						Perspectives.strbundle.getString("LegendBrowsersKey") + ")";
+				}
+				res += '<rect x="' + x_offset + '" y="' + y_cord
+					+ '" width="10" height="10" fill="'
+					+ color_info[key]
+					+ '" rx="0" stroke="black" stroke-width="1px" />\n'
+					+ '<text x="' + (x_offset + 15)
+					+ '" y="' + (y_cord + 9) + '" font-size="13">'
+					+  key + match_text + '</text>\n';
+					y_cord += 20;
 			}
-			res += '<rect x="' + x_offset + '" y="' + y_cord 
-				+ '" width="10" height="10" fill="'
-				+ color_info[key] 
-				+ '" rx="0" stroke="black" stroke-width="1px" />\n'
-				+ '<text x="' + (x_offset + 15) 
-				+ '" y="' + (y_cord + 9) + '" font-size="13">'
-				+  key + match_text + '</text>\n'; 
-				y_cord += 20;
 		}
- 
-		res += '</svg>'; 
-		return res; 
-	} 
-}
+
+		res += '</svg>';
+		return res;
+	}
+};
diff --git a/plugin/chrome/content/notaries.js b/plugin/chrome/content/notaries.js
index e9ca143..e081578 100644
--- a/plugin/chrome/content/notaries.js
+++ b/plugin/chrome/content/notaries.js
@@ -18,7 +18,7 @@
 
 var Perspectives = {
  	MY_ID: "perspectives at cmu.edu",
-	strbundle : null, // this isn't loaded when things are intialized
+	strbundle : null, // this isn't loaded when things are initialized
 
 
 	// IP addresses that can't be queried by notary machines
@@ -108,24 +108,28 @@ var Perspectives = {
 
 	//Sets the tooltip and the text of the favicon popup on https sites
 	setFaviconText: function(str){
-        	var box = document.getElementById("identity-box");
-        	if(box)
-            		box.tooltipText = str;
-        	else { // SeaMonkey
-            		box = document.getElementById("security-button");
-            		if(box)
-               		box.tooltipText = str;
-        	}
+		var box = document.getElementById("identity-box");
+		if(box) {
+			box.tooltipText = str;
+		}
+		else { // SeaMonkey
+			box = document.getElementById("security-button");
+			if(box) {
+				box.tooltipText = str;
+			}
+		}
 	},
 
 	getFaviconText: function(){
-        	var box = document.getElementById("identity-box");
-        	if(box)
-            		return box.tooltipText;
-        	// SeaMonkey
-        	box = document.getElementById("security-button");
-        	if(box)
-            		return box.tooltipText;
+		var box = document.getElementById("identity-box");
+		if(box) {
+				return box.tooltipText;
+		}
+		// SeaMonkey
+		box = document.getElementById("security-button");
+		if(box) {
+				return box.tooltipText;
+		}
 	},
 
 	// cached result data
@@ -163,8 +167,9 @@ var Perspectives = {
 
 			var certDB = Components.classes["@mozilla.org/security/x509certdb;1"]
 				.getService(Components.interfaces.nsIX509CertDB);
-			if (!certDB)
+			if (!certDB) {
 				return null;
+			}
 
 			Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 			recentCertsSvc = certDB.getRecentBadCerts(PrivateBrowsingUtils.isWindowPrivate(window));
@@ -174,15 +179,17 @@ var Perspectives = {
 			return null;
 		}
 
-		if (!recentCertsSvc)
+		if (!recentCertsSvc) {
 			return null;
+		}
 
 		var port = (uri.port == -1) ? 443 : uri.port;
 
 		var hostWithPort = uri.host + ":" + port;
 		var gSSLStatus = recentCertsSvc.getRecentBadCert(hostWithPort);
-		if (!gSSLStatus)
+		if(!gSSLStatus) {
 			return null;
+		}
 		return gSSLStatus;
 	},
 
@@ -200,8 +207,9 @@ var Perspectives = {
 	psv_get_valid_cert: function(ui) {
 		try {
 			ui.QueryInterface(Components.interfaces.nsISSLStatusProvider);
-			if(!ui.SSLStatus)
+			if(!ui.SSLStatus) {
 				return null;
+			}
 			return ui.SSLStatus.serverCert;
 		}
 		catch (e) {
@@ -367,10 +375,28 @@ var Perspectives = {
 							createInstance(Ci.nsIDataSignatureVerifier);
 					var result = verifier.verifyData(bin_result,
 							server_result.signature, notary_server.public_key);
-					if(!result) {
+					if(result) {
+						// TODO: move into a check function
+						// ... and import UnderscoreJS and use functional style programming
+						server_result.is_valid = true;
+						for(var i = 0; i < server_result.obs.length; i++) {
+							var obs = server_result.obs[i];
+							if(server_result.is_valid) {
+								for(var j = 0; j < obs.timestamps.length; j++) {
+									var ts = obs.timestamps[j];
+									if(ts.end < ts.start) {
+										server_result.is_valid = false;
+										break;
+									}
+								}
+							} else {
+								break
+							}
+						}
+					} else {
 						Pers_debug.d_print("error", "Invalid signature from : " +
-							notary_server.host);
-						return;
+													notary_server.host);
+						server_result.is_valid = false;
 					}
 					server_result.server = notary_server.host;
 
@@ -384,16 +410,23 @@ var Perspectives = {
 					}
 				 	var i;
 					for(i = 0; i < result_list.length; i++) {
-						if(result_list[i].server == server_result.server) {
-							Pers_debug.d_print("query",
-							  "Ignoring duplicate reply for '" +
-								ti.service_id + "' from '" +
-								server_result.server + "'");
-							return;
+						if(result_list[i].server === server_result.server) {
+							// also check if previous response was valid
+							if(result_list[i].is_valid === true) {
+								Pers_debug.d_print("query",
+								  	"Ignoring duplicate reply for '" +
+										ti.service_id + "' from '"   +
+										server_result.server + "'");
+								return;
+							} else {
+								result_list.splice(i, 1);
+								break
+							}
 						}
 					}
 					Pers_debug.d_print("query","adding result from: " +
 							notary_server.host);
+
 					result_list.push(server_result);
 
 					var num_replies = ti.partial_query_results.length;
@@ -454,7 +487,6 @@ var Perspectives = {
 					server_result_list, q_required, max_stale_sec,unixtime);
 			var is_cur_consistent = quorum_duration != -1;
 
-
 			var weak_check_time_limit = Perspectives.root_prefs.
 						getIntPref("perspectives.weak_consistency_time_limit");
 			var inconsistent_check_max = Perspectives.root_prefs.
@@ -487,7 +519,7 @@ var Perspectives = {
 					": \n" + obs_text + "\n";
 			//Pers_debug.d_print("main","\n" + str + "\n");
 			var svg = Pers_gen.get_svg_graph(ti.service_id, server_result_list, 30,
-				unixtime,test_key, max_stale_sec);
+				unixtime, test_key, max_stale_sec);
 			ti.query_results = new Perspectives.SslCert(ti.uri.host,
 										ti.uri.port, test_key,
 										str, null,svg, qd_days,
@@ -512,12 +544,15 @@ var Perspectives = {
 			return false;
 		}
 		var flags = 0;
-		if(gSSLStatus.isUntrusted)
+		if(gSSLStatus.isUntrusted) {
 			flags |= Perspectives.overrideService.ERROR_UNTRUSTED;
-		if(gSSLStatus.isDomainMismatch)
+		}
+		if(gSSLStatus.isDomainMismatch) {
 			flags |= Perspectives.overrideService.ERROR_MISMATCH;
-		if(gSSLStatus.isNotValidAtThisTime)
+		}
+		if(gSSLStatus.isNotValidAtThisTime) {
 			flags |= Perspectives.overrideService.ERROR_TIME;
+		}
 
 		Perspectives.overrideService.rememberValidityOverride(
 			uri.asciiHost, uri.port, cert, flags, isTemp);
@@ -557,7 +592,7 @@ var Perspectives = {
 		ti.cert       = Perspectives.getCertificate(ti.browser);
 		if(!ti.cert){
 			var text = Perspectives.strbundle.
-				getFormattedString("noCertError", [ ti.uri.host ])
+				getFormattedString("noCertError", [ti.uri.host]);
 			Pers_statusbar.setStatus(ti.uri, Pers_statusbar.STATE_NEUT, text);
 			ti.reason_str = text;
 			return;
@@ -601,7 +636,7 @@ var Perspectives = {
 			var unreachable = Perspectives.is_nonrouted_ip(ti.uri.host);
 			if(unreachable) {
 				var text = Perspectives.strbundle.
-					getFormattedString("rfc1918Error", [ ti.uri.host ])
+					getFormattedString("rfc1918Error", [ti.uri.host]);
 				Pers_statusbar.setStatus(ti.uri, Pers_statusbar.STATE_NEUT, text);
 				ti.reason_str = text;
 				return;
@@ -706,13 +741,12 @@ var Perspectives = {
 					getBoolPref("perspectives.trust_https_with_weak_consistency");
 			var weak_trust = ti.query_results.inconsistent_results && ti.query_results.weakly_seen;
 
-			debugger
 			if(strong_trust) {
 				// FIXME: need to clear any contrary banners
 				var mixed_security =  ti.state & Perspectives.state.STATE_IS_BROKEN;
 				if(!ti.is_override_cert && (ti.state & Perspectives.state.STATE_IS_INSECURE)){
 					ti.exceptions_enabled = Perspectives.root_prefs.
-						getBoolPref("perspectives.exceptions.enabled")
+						getBoolPref("perspectives.exceptions.enabled");
 					if(ti.exceptions_enabled) {
 						ti.override_used = true;
 						var isTemp = !Perspectives.root_prefs.
@@ -737,7 +771,7 @@ var Perspectives = {
 				if(mixed_security) {
 					// FIXME: need to clear any contrary banners
 					// TODO: once we have separated calculation of results
-					// from applying the resuts and can add better tests for these,
+					// from applying the results and can add better tests for these,
 					// wrap setting the status and the tooltip in their own function
 					// so no steps are forgotten
 					ti.query_results.tooltip = Perspectives.strbundle.getString("trustedButInsecureEmbedded");
@@ -764,7 +798,6 @@ var Perspectives = {
 					ti.query_results.tooltip = Perspectives.strbundle.getString("trustedMultipleByBrowser");
 					Pers_statusbar.setStatus(ti.uri, Pers_statusbar.STATE_SEC,
 						ti.query_results.tooltip);
-
 				}
 			} else if (ti.query_results.summary.indexOf(Perspectives.strbundle.getString("sslKey")) === -1) {
 				// FIXME: need to clear any contrary banners
@@ -803,8 +836,7 @@ var Perspectives = {
 			} else if(ti.query_results.duration < required_duration){
 				// FIXME: need to clear any contrary banners
 				ti.query_results.tooltip = Perspectives.strbundle.
-					getFormattedString("thresholdWarning",
-					[ ti.query_results.duration, required_duration]);
+					getFormattedString("thresholdWarning", [ti.query_results.duration, required_duration]);
 				Pers_statusbar.setStatus(ti.uri, Pers_statusbar.STATE_NSEC,
 					ti.query_results.tooltip);
 				if(!ti.already_trusted && ti.firstLook){
@@ -834,13 +866,15 @@ var Perspectives = {
 			var whitelist = Perspectives.root_prefs.
 				    getCharPref("perspectives.whitelist").split(",");
 			for(var entry in whitelist) {
-				var e = whitelist[entry];
-				if(e.length == 0) {
-					continue;
-				}
-				var r = RegExp(e);
-				if (host.match(r)) {
-					return true;
+				if(whitelist.hasOwnProperty(entry)) {
+					var e = whitelist[entry];
+					if(e.length == 0) {
+						continue;
+					}
+					var r = new RegExp(e);
+					if(host.match(r)) {
+						return true;
+					}
 				}
 			}
 		} catch(e) { /* ignore */ }
@@ -862,7 +896,7 @@ var Perspectives = {
 	//note can use request to suspend the loading
 	notaryListener : {
 
-   		// Note: We intentially do NOT call updateStatus from here, as this
+   		// Note: We intentionally do NOT call updateStatus from here, as this
    		// was causing a bug that caused us to get the previous website's cert
    		// instead of the correct cert.
    		onLocationChange: function(aWebProgress, aRequest, aURI) {
@@ -882,7 +916,7 @@ var Perspectives = {
 					// in those cases getFormattedString() will throw an exception,
 					// which causes the error icon to be displayed.
 					tooltip = Perspectives.strbundle.getFormattedString("contactingNotariesAbout",
-						[ aURI.asciiHost ])
+						[aURI.asciiHost]);
 					// TODO: can we start sending the query from right here, to begin sooner?
 				}
 				Pers_statusbar.setStatus(aURI, state, tooltip);
@@ -993,7 +1027,9 @@ var Perspectives = {
 		// sometimes things blow up because accessing uri.host throws an exception
 		try {
 			var ignore = uri.host;
-			if(!uri.host) throw "";
+			if(!uri.host) {
+				throw "";
+			}
 		} catch(e) {
 			return Perspectives.strbundle.getString("notValidRemoteServer");
 		}
@@ -1106,6 +1142,5 @@ var Perspectives = {
 									false);
 		}
 	}
-
-}
+};
 
diff --git a/plugin/chrome/content/xml_notary_client.js b/plugin/chrome/content/xml_notary_client.js
index b633a1f..4f20b1e 100644
--- a/plugin/chrome/content/xml_notary_client.js
+++ b/plugin/chrome/content/xml_notary_client.js
@@ -20,13 +20,15 @@
 
 // convert an xml '<server>' node to a javascript object
 // In JSON syntax, this object has the following format:
-/* { "signature" : "XXXX",
-     "obs" : [  { "key" : "XXX",
- 		  "timestamps" : [ { "start" : XXX, "end" : YYY } ]
-		}
-	     ]
-   }
-*/
+// { "signature" : "...base64 public key...",
+// , "server"    : "notary.example.com:80"
+// , "obs"       : [ { "key"        : "...hex key..."
+//                   , "key_type"   : "ssl etc."
+//                   , "timestamps" : [ { "start" : 1234567890, end : 9876543210 } ]
+//                 ]
+// , "is_valid"  : null|bool
+// }
+
 var Pers_xml = {
 	parse_server_node: function(reply, expected_version) {
 
@@ -40,7 +42,7 @@ var Pers_xml = {
 			return null;
 		}
 
-		var res = new Object();
+		var res = {};
 		var sig_type = reply.attributes.getNamedItem("sig_type").value;
 		if(sig_type != "rsa-md5") {
 			// in the future, we will support 'rsa-sha256' as well
@@ -50,7 +52,7 @@ var Pers_xml = {
 		}
 		var sig_base64 = reply.attributes.getNamedItem("sig").value;
 		res.signature = Pers_util.add_der_signature_header(sig_base64);
-		res.obs     = new Array();
+		res.obs       = [];
 		for (var j = 0; j < reply.childNodes.length; j++){
 			var keynode = reply.childNodes[j];
 			if (keynode.nodeName != "key"){
@@ -58,8 +60,8 @@ var Pers_xml = {
 			}
 
 			var key_info = {
-				"key" : keynode.attributes.getNamedItem("fp").value,
-				"key_type" : keynode.attributes.getNamedItem("type").value,
+				"key"        : keynode.attributes.getNamedItem("fp"  ).value,
+				"key_type"   : keynode.attributes.getNamedItem("type").value,
 				"timestamps" : []
 			};
 			for (var k = 0; k < keynode.childNodes.length; k++){
@@ -68,18 +70,19 @@ var Pers_xml = {
 					continue;
 				}
 				key_info.timestamps.push({
-					"start" : tsnode.attributes.getNamedItem("start").value,
-					"end" : tsnode.attributes.getNamedItem("end").value
+					"start" : parseInt(tsnode.attributes.getNamedItem("start").value, 10), // static typing ftw!
+					"end"   : parseInt(tsnode.attributes.getNamedItem("end"  ).value, 10)
 				});
             }
 			res.obs.push(key_info);
         }
+		res.is_valid = null;
 		return res;
 	},
 
 
 	// Dumps all data in a server response to a string for easy debugging
-	resultToString: function(server_result,show_sig){
+	resultToString: function(server_result, show_sig){
 		if(Perspectives.strbundle == null) {
 				Perspectives.strbundle = document.getElementById("notary_strings");
 		}
@@ -91,9 +94,9 @@ var Pers_xml = {
 				+ ": '" + o.key + "'\n";
 			for(var k = 0; k < o.timestamps.length; k++){
 				var start_t = o.timestamps[k].start;
-				var end_t = o.timestamps[k].end;
+				var end_t   = o.timestamps[k].end;
 				var start_d = new Date(1000 * start_t).toDateString();
-				var end_d = new Date(1000 * end_t).toDateString();
+				var end_d   = new Date(1000 * end_t  ).toDateString();
 				out += Perspectives.strbundle.getString("keyStart") +
 					":\t" + start_t + " - " + start_d + "\n";
 				out += Perspectives.strbundle.getString("keyEnd") +
@@ -102,7 +105,7 @@ var Pers_xml = {
 					Perspectives.strbundle.getString("keyDays") + ")\n\n";
 			}
 		}
-		if(server_result.obs.length == 0) {
+		if(server_result.obs.length === 0) {
 			out += "[ " + Perspectives.strbundle.getString("noResults") + " ]";
 		}
 		if(show_sig) {
@@ -154,4 +157,4 @@ var Pers_xml = {
 
 		return bin_str;
 	}
-}
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/perspectives-extension.git



More information about the Pkg-mozext-commits mailing list