[Pkg-mozext-commits] [perspectives-extension] 08/72: Remove duplicate notaries and warn on mismatching public keys. Fixes #56.

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 cddcc07750272e56ac5040ee1cebfba164cf388e
Author: Gerold Meisinger <gerold.meisinger at gmail.com>
Date:   Sun Jun 15 21:43:32 2014 +0100

    Remove duplicate notaries and warn on mismatching public keys.
    Fixes #56.
---
 plugin/chrome/content/common.js                | 107 +++++++++++++++++--------
 plugin/chrome/content/notaries.js              |  17 ++--
 plugin/chrome/locale/de/notaries.properties    |   1 +
 plugin/chrome/locale/en-US/notaries.properties |   1 +
 plugin/chrome/locale/es-MX/notaries.properties |   1 +
 plugin/chrome/locale/fi/notaries.properties    |   1 +
 plugin/chrome/locale/fr/notaries.properties    |   1 +
 plugin/chrome/locale/nl/notaries.properties    |   1 +
 plugin/chrome/locale/pl/notaries.properties    |   1 +
 plugin/chrome/locale/zh-CN/notaries.properties |   1 +
 10 files changed, 90 insertions(+), 42 deletions(-)

diff --git a/plugin/chrome/content/common.js b/plugin/chrome/content/common.js
index 22d0fb3..2b6f6d7 100644
--- a/plugin/chrome/content/common.js
+++ b/plugin/chrome/content/common.js
@@ -21,11 +21,11 @@ var Pers_debug = {
 	d_print_all : false,
 
 	d_print_flags : {
-		"policy" : false,
-		"query" : false,
+		"policy"    : false,
+		"query"     : false,
 		"querylarge": false, //big response strings and XML; separating this from query lines makes for easier debugging
-		"main" : false,
-		"error" :  false
+		"main"      : false,
+		"error"     : false
 	},
 
 	d_print: function(flag,line) {
@@ -72,11 +72,13 @@ var Pers_util = {
   		return str;
 	},
 
+	// never used?
 	loadNotaryListFromURI: function(uri) {
 		return this.loadNotaryListFromString(this.readFileFromURI(uri));
 	},
 
 	loadNotaryListFromString: function(str_data) {
+		var ret = [];
 		var start_arr = str_data.split("\n");
 		var filtered_arr = [];
 		// the Perspectives object isn't always loaded here, so use our own
@@ -86,44 +88,81 @@ var Pers_util = {
 		}
 
 		for(var i = 0; i < start_arr.length; i++) {
-        		if (start_arr[i].length > 0 && start_arr[i][0] != "#") {
-        			// ignore lines that contain only whitespace -
-        			// makes the file easier to parse cross-platform
-        			if (/^\s+$/g.test(start_arr[i]) === false) {
-        				filtered_arr.push(start_arr[i]);
-        			}
-        		}
+			if (start_arr[i].length > 0 && start_arr[i][0] != "#") {
+				// ignore lines that contain only whitespace -
+				// makes the file easier to parse cross-platform
+				if (/^\s+$/g.test(start_arr[i]) === false) {
+					filtered_arr.push(start_arr[i]);
+				}
+			}
 		}
-       		var i = 0;
+
+		var i = 0;
 		var notary_list = [];
-        	while (i < filtered_arr.length) {
+		while (i < filtered_arr.length) {
 			var host = filtered_arr[i];
-            		var notary_server = { "host" : host };
-            		i += 1;
-
-            		var begin_string = "BEGIN PUBLIC KEY";
-            		if (i >= filtered_arr.length || filtered_arr[i].indexOf(begin_string) === -1) {
-            			throw(Pers_util.notarystr.getFormattedString("errorParsingNotaryEntry", [ host ]) +
-            				' - ' + Pers_util.notarystr.getFormattedString("couldNotFindLine", [ begin_string ]));
-            		}
-            		i += 1;
-
-            		var key = "";
-            		var end_string = "END PUBLIC KEY";
-            		while (i < filtered_arr.length && filtered_arr[i].indexOf(end_string) === -1) {
-                		key += filtered_arr[i];
-                		i += 1;
+			var notary_server = { "host" : host };
+			i += 1;
+
+			var begin_string = "BEGIN PUBLIC KEY";
+			if (i >= filtered_arr.length || filtered_arr[i].indexOf(begin_string) === -1) {
+				throw(Pers_util.notarystr.getFormattedString("errorParsingNotaryEntry", [ host ]) +
+					' - ' + Pers_util.notarystr.getFormattedString("couldNotFindLine", [ begin_string ]));
+			}
+			i += 1;
+
+			var key = "";
+			var end_string = "END PUBLIC KEY";
+			while (i < filtered_arr.length && filtered_arr[i].indexOf(end_string) === -1) {
+				key += filtered_arr[i];
+				i += 1;
 				if(i == filtered_arr.length) {
 					throw(Pers_util.notarystr.getFormattedString("errorParsingNotaryEntry", [ host ]) +
 						' - ' +  Pers_util.notarystr.getFormattedString("couldNotFindLine", [ end_string ]));
 				}
-            		}
+			}
+
+			i += 1; // consume the 'END PUBLIC KEY' line
+			notary_server.public_key = key;
+			notary_list.push(notary_server);
+		}
+
+		// remove duplicate notaries and cleanup string or warn if public keys for duplicates don't match
+		if(notary_list.length > 1) {
+			var sortedNotaries = notary_list.sort(function(notaryA, notaryB) {
+				return notaryA.host.localeCompare(notaryB.host)
+			});
+
+			var filteredNotaries = [sortedNotaries[0]];
+			var unmatchedHosts   = [];
+			var prevDuplicate = false;
+			for(var i = 1; i < sortedNotaries.length; i++) {
+				var notaryA = sortedNotaries[i - 1];
+				var notaryB = sortedNotaries[i    ];
+				if(notaryA.host !== notaryB.host) {
+					filteredNotaries.push(notaryB);
+					prevDuplicate = false;
+				} else {
+					if(!prevDuplicate) {
+						if(notaryA.public_key !== notaryB.public_key) {
+							unmatchedHosts.push(notaryA.host);
+						}
+					}
+
+					prevDuplicate = true;
+				}
+			}
+
+			if(unmatchedHosts.length === 0) {
+				ret = filteredNotaries;
+			} else {
+				throw Pers_util.notarystr.getFormattedString("duplicateNotariesUnmatchedError", [unmatchedHosts.join(", ")]);
+			}
+		} else {
+			ret = notary_list;
+		}
 
-            		i += 1; // consume the 'END PUBLIC KEY' line
-            		notary_server.public_key = key;
-            		notary_list.push(notary_server);
-        	}
-		return notary_list;
+		return ret;
 	},
 
 	// stolen from: http://stackoverflow.com/questions/130404/javascript-data-formatting-pretty-printer
diff --git a/plugin/chrome/content/notaries.js b/plugin/chrome/content/notaries.js
index 1acd50a..a6ac713 100644
--- a/plugin/chrome/content/notaries.js
+++ b/plugin/chrome/content/notaries.js
@@ -230,17 +230,18 @@ var Perspectives = {
 			var list_txt = Perspectives.root_prefs.getCharPref("perspectives.additional_notary_list");
 			var additional_notaries = Pers_util.loadNotaryListFromString(list_txt);
 			all_notaries = all_notaries.concat(additional_notaries);
+
+			var use_default_notaries = Perspectives.root_prefs.getBoolPref("perspectives.use_default_notary_list");
+			if(use_default_notaries) {
+				var default_notaries = Pers_util.loadNotaryListFromString(
+					Perspectives.root_prefs.getCharPref("perspectives.default_notary_list"));
+				all_notaries = all_notaries.concat(default_notaries);
+			}
+
+			return all_notaries;
 		} catch(e) {
 			Pers_debug.d_print("error", "Error parsing additional notaries: " + e);
 		}
-		var use_default_notaries = Perspectives.root_prefs.getBoolPref("perspectives.use_default_notary_list");
-		if(use_default_notaries) {
-
-			var default_notaries = Pers_util.loadNotaryListFromString(
-						this.root_prefs.getCharPref("perspectives.default_notary_list"));
-			all_notaries = all_notaries.concat(default_notaries);
-		}
-		return all_notaries;
 	},
 
 
diff --git a/plugin/chrome/locale/de/notaries.properties b/plugin/chrome/locale/de/notaries.properties
index b2d8639..74b035b 100644
--- a/plugin/chrome/locale/de/notaries.properties
+++ b/plugin/chrome/locale/de/notaries.properties
@@ -15,6 +15,7 @@ needsPermission=Perspectives: Keine Informationen. Entsprechend der Einstellunge
 internalError=Perspectives: Ein interner Fehler ist aufgetreten: %1$S
 updateDefaultListFileError=Unerwarteter Fehler beim Aktualisieren der Standard-Notarliste mittels Datei: %1$S
 updateDefaultListWebError=Unerwarteter Fehler beim Aktualisieren der Standard-Notarliste über Web: %1$S
+duplicateNotariesUnmatchedError=Die folgenden Notare kommen mehrfach vor, aber verwenden unterschiedliche öffentliche Schlüssel ("public keys"): %1$S. Bitte ausbessern!
 loadingCreditsError=Fehler beim Laden der Mitwirkenden: %1$S
 #
 noRepliesWarning=Warnung: Perspectives hat von den Notaren keine Antwort bekommen.
diff --git a/plugin/chrome/locale/en-US/notaries.properties b/plugin/chrome/locale/en-US/notaries.properties
index 771e369..e9845ec 100644
--- a/plugin/chrome/locale/en-US/notaries.properties
+++ b/plugin/chrome/locale/en-US/notaries.properties
@@ -16,6 +16,7 @@ needsPermission=Perspectives: No Information. Your preferences indicate that Per
 internalError=Perspectives: An internal error occurred: %1$S.
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S.
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S.
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 noRepliesWarning=Warning: Perspectives received no Notary replies.
 inconsistentWarning=Warning: Perspectives has NOT seen this certificate consistently.
diff --git a/plugin/chrome/locale/es-MX/notaries.properties b/plugin/chrome/locale/es-MX/notaries.properties
index c8bfbba..883f075 100644
--- a/plugin/chrome/locale/es-MX/notaries.properties
+++ b/plugin/chrome/locale/es-MX/notaries.properties
@@ -16,6 +16,7 @@ internalError=Perspectives: Ha ocurrido un error interno: %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=Advertencia: Perspectives no ha recibido respuesta de las notarías.
diff --git a/plugin/chrome/locale/fi/notaries.properties b/plugin/chrome/locale/fi/notaries.properties
index 03965b9..03d6973 100644
--- a/plugin/chrome/locale/fi/notaries.properties
+++ b/plugin/chrome/locale/fi/notaries.properties
@@ -17,6 +17,7 @@ internalError=Perspectives: An internal error occurred: %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=Warning: Perspectives received no Notary replies.
diff --git a/plugin/chrome/locale/fr/notaries.properties b/plugin/chrome/locale/fr/notaries.properties
index 943e895..dc57719 100644
--- a/plugin/chrome/locale/fr/notaries.properties
+++ b/plugin/chrome/locale/fr/notaries.properties
@@ -16,6 +16,7 @@ internalError=Perspectives : une erreur interne s'est produite : %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=Attention : Perspectives n'a pas reçu de réponses des Notaires.
diff --git a/plugin/chrome/locale/nl/notaries.properties b/plugin/chrome/locale/nl/notaries.properties
index 0c111b9..f6fa0c2 100644
--- a/plugin/chrome/locale/nl/notaries.properties
+++ b/plugin/chrome/locale/nl/notaries.properties
@@ -16,6 +16,7 @@ internalError=Perspectives: An internal error occurred: %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=Warning: Perspectives received no Notary replies.
diff --git a/plugin/chrome/locale/pl/notaries.properties b/plugin/chrome/locale/pl/notaries.properties
index 0c0a89e..b11f5fc 100644
--- a/plugin/chrome/locale/pl/notaries.properties
+++ b/plugin/chrome/locale/pl/notaries.properties
@@ -17,6 +17,7 @@ internalError=Perspectives: Wystąpił błąd wewnętrzny: %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=Uwaga: Perspectives nie otrzymało żadnej odpowiedzi od notariuszy.
diff --git a/plugin/chrome/locale/zh-CN/notaries.properties b/plugin/chrome/locale/zh-CN/notaries.properties
index bf28ecb..debe232 100644
--- a/plugin/chrome/locale/zh-CN/notaries.properties
+++ b/plugin/chrome/locale/zh-CN/notaries.properties
@@ -16,6 +16,7 @@ internalError=Perspectives:发生内部错误: %1$S
 # TODO: translate
 updateDefaultListFileError=Unexpected error updating default notary list from file: %1$S
 updateDefaultListWebError=Unexpected error updating default notary list from web: %1$S
+duplicateNotariesUnmatchedError=The following duplicate notaries have mismatching public keys: %1$S. Please resolve!
 loadingCreditsError=Error loading credits: %1$S
 #
 noRepliesWarning=警告:Perspectives 未收到Notary的回复。

-- 
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