[Pkg-mozext-commits] [itsalltext] 386/459: Made per-document tracker harder to find

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:41 UTC 2015


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

taffit pushed a commit to branch master
in repository itsalltext.

commit e913027f2d88638e3799fd53f899de45d9fb280b
Author: Christian Höltje <docwhat at gerf.org>
Date:   Fri Aug 19 16:36:21 2011 -0400

    Made per-document tracker harder to find
    
    Since I'm using get/setUserData() on the document object, I have
    to make sure that it isn't easily found.  I'm now using a random
    string stored in the preferences.
---
 src/chrome/content/cacheobj.js         | 65 ++++-------------------------
 src/chrome/content/itsalltext.js       | 76 ++++++++++++++++++++++++++++++----
 src/defaults/preferences/itsalltext.js |  1 +
 3 files changed, 78 insertions(+), 64 deletions(-)

diff --git a/src/chrome/content/cacheobj.js b/src/chrome/content/cacheobj.js
index 5fcb2df..0f45045 100644
--- a/src/chrome/content/cacheobj.js
+++ b/src/chrome/content/cacheobj.js
@@ -65,9 +65,9 @@ function CacheObj(node) {
      * web page from knowing what it's connected to.
      * @type String
      */
-    that.uid = that.hashString([ doc.location.toString(),
-                                 Math.random(),
-                                 that.node_id ].join(':'));
+    that.uid = itsalltext.hashString([ doc.location.toString(),
+                                       Math.random(),
+                                       that.node_id ].join(':'));
     // @todo [security] Add a serial to the uid hash.
 
     node.setUserData(itsalltext.MYSTRING + '_UID', that.uid, null);
@@ -77,11 +77,11 @@ function CacheObj(node) {
      * change, the directory that the file is stored in should not!
      */
     host = window.escape(doc.location.hostname);
-    hash = that.hashString([ doc.location.protocol,
-                             doc.location.port,
-                             doc.location.search ? doc.location.search : '?',
-                             doc.location.pathname,
-                             that.node_id].join(':'));
+    hash = itsalltext.hashString([ doc.location.protocol,
+				   doc.location.port,
+				   doc.location.search ? doc.location.search : '?',
+				   doc.location.pathname,
+				   that.node_id].join(':'));
     that.base_filename = [host, hash.slice(0, 10)].join('.');
     /* The current extension.
      * @type String
@@ -771,53 +771,6 @@ CacheObj.prototype.adjust = function () {
 };
 
 /**
- * Creates a mostly unique hash of a string
- * Most of this code is from:
- *    http://developer.mozilla.org/en/docs/nsICryptoHash
- * @param {String} some_string The string to hash.
- * @returns {String} a hashed string.
- */
-CacheObj.prototype.hashString = function (some_string) {
-    var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
-        result = {},
-        data,
-        ch,
-        hash,
-        toHexString,
-        retval = [],
-        i;
-    converter.charset = "UTF-8";
-
-    /* result is the result of the hashing.  It's not yet a string,
-     * that'll be in retval.
-     * result.value will contain the array length
-     */
-    result = {};
-
-    /* data is an array of bytes */
-    data = converter.convertToByteArray(some_string, result);
-    ch   = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
-
-    ch.init(ch.MD5);
-    ch.update(data, data.length);
-    hash = ch.finish(true);
-
-    // return the two-digit hexadecimal code for a byte
-    toHexString = function (charCode) {
-        return ("0" + charCode.toString(36)).slice(-2);
-    };
-
-    // convert the binary hash data to a hex string.
-    for (i in hash) {
-        if (hash.hasOwnProperty(i)) {
-            retval[i] = toHexString(hash.charCodeAt(i));
-        }
-    }
-
-    return (retval.join(""));
-};
-
-/**
  * Returns a cache object
  * Note: These UIDs are only unique for Its All Text.
  * @param {Object} node A dom object node or ID to one.
@@ -843,7 +796,7 @@ CacheObj.get = function (node) {
  */
 CacheObj.make = function (node, create_gumdrop) {
     var cobj = CacheObj.get(node);
-    itsalltext.debug('CacheObj.make(',node,', ', create_gumdrop,') = ',cobj, ' : ', cobj ? cobj.uid : 'null');
+    // Too noisy itsalltext.debug('CacheObj.make(',node,', ', create_gumdrop,') = ',cobj, ' : ', cobj ? cobj.uid : 'null');
     if (!cobj) {
         cobj = new CacheObj(node);
         if (create_gumdrop) {
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index 4e177fd..3683340 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -123,7 +123,8 @@ var ItsAllText = function () {
             gumdrop_position:   'Char',
             fade_time:          'Float',
             extensions:         'Char',
-            hotkey:             'Char'
+            hotkey:             'Char',
+            tracker_id:         'Char',
         },
 
         /**
@@ -198,6 +199,20 @@ var ItsAllText = function () {
 
     };
 
+    that.getTrackerId = function () {
+	var id = that.preferences.tracker_id;
+	if (!id) {
+	    id = [that.MYSTRING,
+		  Math.floor(Math.random()*999999).toString(),
+		  Math.round(new Date().getTime()),
+		 ].join(':')
+	    id = that.hashString(id);
+            that.preferences.private_set('tracker_id', id);
+	}
+	return id;
+    }
+
+
     /**
      * Returns true if the system is running Mac OS X.
      * @returns {boolean} Is this a Mac OS X system?
@@ -326,7 +341,6 @@ var ItsAllText = function () {
 
     // @todo [wish] Profiling and optimization.
 
-
     that.getFromTracker = function (id) {
 	var tracker, doc;
 	if (typeof gBrowser !== 'undefined') {
@@ -335,12 +349,11 @@ var ItsAllText = function () {
 	    // We must be in a XUL window, fall back to simpler method.
 	    doc = window.document;
 	}
-	tracker = doc.getUserData(that.MYSTRING + "_tracker");
+	tracker = doc.getUserData(that.getTrackerId());
 	if (!tracker) {
 	    tracker = {};
-	    doc.setUserData(that.MYSTRING + "_tracker", tracker, null);
+	    doc.setUserData(that.getTrackerId(), tracker, null);
 	}
-	that.debug("getFromTracker:", id, tracker);
 	return tracker[id];
     }
 
@@ -352,12 +365,12 @@ var ItsAllText = function () {
 	    // We must be in a XUL window, fall back to simpler method.
 	    doc = window.document;
 	}
-	tracker = doc.getUserData(that.MYSTRING + "_tracker");
+	tracker = doc.getUserData(that.getTrackerId());
 	if (!tracker) {
 	    tracker = {};
 	}
 	tracker[id] = cobj;
-	doc.setUserData(that.MYSTRING + "_tracker", tracker, null);
+	doc.setUserData(that.getTrackerId(), tracker, null);
 	that.debug("addToTracker:", id, cobj, tracker);
     }
 
@@ -748,13 +761,60 @@ ItsAllText.prototype.hitch = function (object, method) {
 ItsAllText.prototype.listen = function (source, event, listener, opt_capture) {
     opt_capture = !!opt_capture;
     this.unlisten(source, event, listener, opt_capture);
-    this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
+    // this.debug("listen(%o, %o, -, %o)", source, event, opt_capture);
     if (source) {
         source.addEventListener(event, listener, opt_capture);
     }
 };
 
 /**
+ * Creates a mostly unique hash of a string
+ * Most of this code is from:
+ *    http://developer.mozilla.org/en/docs/nsICryptoHash
+ * @param {String} some_string The string to hash.
+ * @returns {String} a hashed string.
+ */
+ItsAllText.prototype.hashString = function (some_string) {
+    var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
+        result = {},
+        data,
+        ch,
+        hash,
+        toHexString,
+        retval = [],
+        i;
+    converter.charset = "UTF-8";
+
+    /* result is the result of the hashing.  It's not yet a string,
+     * that'll be in retval.
+     * result.value will contain the array length
+     */
+    result = {};
+
+    /* data is an array of bytes */
+    data = converter.convertToByteArray(some_string, result);
+    ch   = Components.classes["@mozilla.org/security/hash;1"].createInstance(Components.interfaces.nsICryptoHash);
+
+    ch.init(ch.MD5);
+    ch.update(data, data.length);
+    hash = ch.finish(true);
+
+    // return the two-digit hexadecimal code for a byte
+    toHexString = function (charCode) {
+        return ("0" + charCode.toString(36)).slice(-2);
+    };
+
+    // convert the binary hash data to a hex string.
+    for (i in hash) {
+        if (hash.hasOwnProperty(i)) {
+            retval[i] = toHexString(hash.charCodeAt(i));
+        }
+    }
+
+    return (retval.join(""));
+};
+
+/**
  * @method unlisten
  * @param source {HTMLElement} The element with the event
  * @param event {String} The name of the event.
diff --git a/src/defaults/preferences/itsalltext.js b/src/defaults/preferences/itsalltext.js
index 8c9a35d..1a8d247 100644
--- a/src/defaults/preferences/itsalltext.js
+++ b/src/defaults/preferences/itsalltext.js
@@ -6,3 +6,4 @@ pref("extensions.itsalltext.debug",  false);
 pref("extensions.itsalltext.gumdrop_position", 'lower-right');
 pref("extensions.itsalltext.extensions",  '.txt,.html,.css,.xml,.xsl,.js');
 pref("extensions.itsalltext.hotkey",  '');
+pref("extensions.itsalltext.tracker_id",  '');

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



More information about the Pkg-mozext-commits mailing list