[or-cvs] r18766: {torbutton} Implement environment variable-based TZ spoofing. This shoul (in torbutton/trunk/src: chrome/content defaults/preferences)

mikeperry at seul.org mikeperry at seul.org
Thu Mar 5 04:33:32 UTC 2009


Author: mikeperry
Date: 2009-03-04 23:33:31 -0500 (Wed, 04 Mar 2009)
New Revision: 18766

Modified:
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/defaults/preferences/preferences.js
Log:

Implement environment variable-based TZ spoofing.  This should
just be a stopgap until we can get a more extensive firefox
patch in to support tz spoofing in Firefox itself.



Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2009-03-04 17:29:38 UTC (rev 18765)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2009-03-05 04:33:31 UTC (rev 18766)
@@ -724,6 +724,70 @@
     }
 }
 
+function torbutton_set_timezone(mode, startup) {
+    /*
+     * XXX: Windows doesn't call tzset() automatically.. Linux and MacOS
+     * both do though.. :(
+     */
+    // XXX: Test: 
+    //  1. odd timezones like IST and IST+13:30
+    //  2. negative offsets
+    //  3. Windows-style spaced names
+    var environ = Components.classes["@mozilla.org/process/environment;1"]
+                   .getService(Components.interfaces.nsIEnvironment);
+        
+    torbutton_log(3, "Setting timezone at "+startup+" for mode "+mode);
+
+    // For TZ info, see:
+    // http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg21150296
+    // and 
+    // http://msdn.microsoft.com/en-us/library/90s5c885.aspx
+    if(startup) {
+        // Save Date() string to pref
+        var d = new Date();
+        var offset = d.getTimezoneOffset();
+        var offStr = "";
+        if(d.getTimezoneOffset() < 0) {
+            offset = -offset;
+            offStr = "-";
+        } else {
+            offStr = "+";
+        }
+        
+        if(offset/60 < 10) {
+            offStr += "0";
+        }
+        offStr += (offset/60)+":";
+        if((offset%60) < 10) {
+            offStr += "0";
+        }
+        offStr += (offset%60);
+
+        // Regex match for 3 letter code
+        var re = new RegExp('\\((\\S+)\\)', "gm");
+        match = re.exec(d.toString());
+        // Parse parens. If parseable, use. Otherwise set TZ=""
+        var set = ""
+        if(match) {
+            set = match[1]+offStr;
+        } else {
+            torbutton_log(3, "Skipping timezone storage");
+        }
+        m_tb_prefs.setCharPref("extensions.torbutton.tz_string", set);
+    }
+
+    if(mode) {
+        torbutton_log(2, "Setting timezone to UTC");
+        environ.set("TZ", "UTC");
+    } else {
+        // 1. If startup TZ string, reset.
+        torbutton_log(2, "Unsetting timezone.");
+        // FIXME: Tears.. This will not update during daylight switch for linux+mac users
+        // Windows users will be fine though, because tz_string should be empty for them
+        environ.set("TZ", m_tb_prefs.getCharPref("extensions.torbutton.tz_string"));
+    }
+}
+
 // NOTE: If you touch any additional prefs in here, be sure to update
 // the list in torbutton_util.js::torbutton_reset_browser_prefs()
 function torbutton_update_status(mode, force_update) {
@@ -750,6 +814,7 @@
         torprefs.setBoolPref("tor_enabled", mode);
     }
 
+    /*
     if(m_tb_ff3 
             && !m_tb_prefs.getBoolPref("extensions.torbutton.warned_ff3")
             && mode && changed) {
@@ -762,7 +827,7 @@
             return;
         }
         m_tb_prefs.setBoolPref("extensions.torbutton.warned_ff3", true);
-    }
+    }*/
     
     // Toggle JS state early, since content window JS runs in a different
     // thread
@@ -1047,21 +1112,8 @@
     torbutton_setIntPref("browser.bookmarks.livemark_refresh_seconds", 
             "livemark_refresh", 31536000, mode, changed);
 
-    /*
-     * XXX: Windows doesn't call tzset() automatically.. Linux and MacOS
-     * both do though.. :(
-    var environ = Components.classes["@mozilla.org/process/environment;1"]
-                   .getService(Components.interfaces.nsIEnvironment);
+    torbutton_set_timezone(mode, false);
 
-    if(mode) {
-        torbutton_log(2, "Setting timezone to UTC");
-        environ.set("TZ", "UTC");
-    } else {
-        torbutton_log(2, "Unsetting timezone.");
-        environ.set("TZ", "PST+7:00");
-    }
-    */
-
     // This call also has to be here for 3rd party proxy changers.
     torbutton_close_on_toggle(mode);
 
@@ -2165,6 +2217,8 @@
        
         torbutton_do_main_window_startup();
 
+        torbutton_set_timezone(torbutton_check_status(), true);
+
         // XXX: This is probably better done by reimplementing the 
         // component.
         if(m_tb_prefs.getBoolPref("extensions.torbutton.block_remoting")) {

Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js	2009-03-04 17:29:38 UTC (rev 18765)
+++ torbutton/trunk/src/defaults/preferences/preferences.js	2009-03-05 04:33:31 UTC (rev 18766)
@@ -131,6 +131,7 @@
 pref("extensions.torbutton.block_remoting",false);
 pref("extensions.torbutton.tor_memory_jar",false);
 pref("extensions.torbutton.nontor_memory_jar",false);
+pref("extensions.torbutton.tz_string","");
 
 // User agent prefs:
 pref("extensions.torbutton.appname_override","Netscape");



More information about the tor-commits mailing list