Commit b15da273 authored by Georg Koppen's avatar Georg Koppen
Browse files

Merge remote-tracking branch 'sysrqb/bug25750_6'

parents 9aa5fd46 51c1dfb7
......@@ -2533,7 +2533,8 @@ function requestMoatCaptcha(aProxySettings, aMeekClientPath, aMeekClientArgs)
aMeekClientPath, aMeekClientArgs)
.then(()=>
{
let bridgeType = TorLauncherUtil.getCharPref(kPrefBridgeDBType);
let bridgeType = TorLauncherUtil.getCharPref(kPrefBridgeDBType,
"obfs4");
moatRequestor.fetchBridges([bridgeType])
.then(aCaptchaInfo =>
{
......
// Copyright (c) 2017, The Tor Project, Inc.
// Copyright (c) 2018, The Tor Project, Inc.
// See LICENSE for licensing information.
//
// vim: set sw=2 sts=2 ts=8 et syntax=javascript:
......@@ -19,6 +19,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherLogger",
function TorProcessService()
{
this.mDefaultPreferencesAreLoaded = TorLauncherUtil.loadDefaultPreferences();
if (!this.mDefaultPreferencesAreLoaded)
{
throw Components.Exception("Setting (some) default preferences failed!",
Cr.NS_ERROR_NOT_INITIALIZED);
}
this.wrappedJSObject = this;
this.mProtocolSvc = Cc["@torproject.org/torlauncher-protocol-service;1"]
.getService(Ci.nsISupports).wrappedJSObject;
......@@ -98,6 +105,13 @@ TorProcessService.prototype =
this.mObsSvc.addObserver(this, kUserQuitTopic, false);
this.mObsSvc.addObserver(this, kBootstrapStatusTopic, false);
if (!this.mDefaultPreferencesAreLoaded)
{
throw Components.Exception("Default preferences not loaded at " +
"profile-after-change notification!",
Cr.NS_ERROR_NOT_INITIALIZED);
}
if (TorLauncherUtil.shouldOnlyConfigureTor)
{
this._controlTor(true, false);
......@@ -272,7 +286,6 @@ TorProcessService.prototype =
contractID: this.kContractID,
classDescription: this.kServiceName,
classID: this.kClassID,
implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
flags: Ci.nsIClassInfo.DOM_OBJECT,
// nsIFactory implementation.
......@@ -305,6 +318,13 @@ TorProcessService.prototype =
TorStartAndControlTor: function(aForceDisableNetwork)
{
if (!this.mDefaultPreferencesAreLoaded)
{
throw Components.Exception("TorLauncher is starting Tor but " +
"the default preferences were not set!",
Cr.NS_ERROR_NOT_INITIALIZED);
}
this._startTor(aForceDisableNetwork);
let isRunningTor = (this.mTorProcessStatus == this.kStatusStarting) ||
(this.mTorProcessStatus == this.kStatusRunning);
......@@ -334,7 +354,7 @@ TorProcessService.prototype =
mQuitSoon: false, // Quit was requested by the user; do so soon.
mLastTorWarningPhase: null,
mLastTorWarningReason: null,
mDefaultPreferencesAreLoaded: false,
// Private Methods /////////////////////////////////////////////////////////
_startTor: function(aForceDisableNetwork)
......@@ -435,7 +455,8 @@ TorProcessService.prototype =
if (socksPortArg)
{
let socksPortFlags = TorLauncherUtil.getCharPref(
"extensions.torlauncher.socks_port_flags");
"extensions.torlauncher.socks_port_flags",
"IPv6Traffic PreferIPv6 KeepAliveIsolateSOCKSAuth");
if (socksPortFlags)
socksPortArg += ' ' + socksPortFlags;
args.push("+__SocksPort");
......@@ -979,7 +1000,7 @@ TorProcessService.prototype =
let stream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
stream.init(aFile, 0x02 | 0x08 | 0x20, /* WRONLY CREATE TRUNCATE */
0600, 0);
0o600, 0);
stream.write(data, data.length);
stream.QueryInterface(Ci.nsISafeOutputStream).finish();
}
......
......@@ -13,6 +13,7 @@ const Cr = Components.results;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherUtil",
"resource://torlauncher/modules/tl-util.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TorLauncherLogger",
......@@ -52,7 +53,7 @@ function TorProtocolService()
this.mControlPort = parseInt(env.get("TOR_CONTROL_PORT"), 10);
let useIPC = !isWindows && TorLauncherUtil.getBoolPref(
"extensions.torlauncher.control_port_use_ipc", true);
"extensions.torlauncher.control_port_use_ipc", false);
if (!this.mControlHost && !this.mControlPort && useIPC)
this.mControlIPCFile = TorLauncherUtil.getTorFile("control_ipc", false);
else
......@@ -156,7 +157,7 @@ function TorProtocolService()
if (useIPC === undefined)
{
useIPC = !isWindows && TorLauncherUtil.getBoolPref(
"extensions.torlauncher.socks_port_use_ipc", true);
"extensions.torlauncher.socks_port_use_ipc", false);
}
// Fill in missing SOCKS info from prefs.
......@@ -182,6 +183,7 @@ function TorProtocolService()
{
let socksPort = TorLauncherUtil.getIntPref("network.proxy.socks_port",
0);
// This pref is set as 0 by default in Firefox, use 9150 if we get 0.
this.mSOCKSPortInfo.port = (socksPort != 0) ? socksPort : 9150;
}
}
......@@ -256,7 +258,6 @@ TorProtocolService.prototype =
contractID: this.kContractID,
classDescription: this.kServiceName,
classID: this.kClassID,
implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
flags: Ci.nsIClassInfo.DOM_OBJECT,
// nsIFactory implementation.
......@@ -637,10 +638,6 @@ TorProtocolService.prototype =
let s = "";
if (this.mTorLog)
{
let dateFmtSvc = Cc["@mozilla.org/intl/scriptabledateformat;1"]
.getService(Ci.nsIScriptableDateFormat);
let dateFormat = dateFmtSvc.dateFormatShort;
let timeFormat = dateFmtSvc.timeFormatSecondsForce24Hour;
let eol = (TorLauncherUtil.isWindows) ? "\r\n" : "\n";
let count = this.mTorLog.length;
if (aCountObj)
......@@ -649,12 +646,16 @@ TorProtocolService.prototype =
{
let logObj = this.mTorLog[i];
let secs = logObj.date.getSeconds();
let timeStr = dateFmtSvc.FormatDateTime("", dateFormat, timeFormat,
logObj.date.getFullYear(), logObj.date.getMonth() + 1,
logObj.date.getDate(), logObj.date.getHours(),
logObj.date.getMinutes(), secs);
let options = { year: '2-digit', month: 'numeric', day: 'numeric',
hour: 'numeric', minute: 'numeric', second: 'numeric',
hour12: false };
let timeStr = new Intl.DateTimeFormat('en-US', options)
.format(logObj.date, options);
if (' ' == timeStr.substr(-1))
timeStr = timeStr.substr(0, timeStr.length - 1);
let fracSecsStr = "" + logObj.date.getMilliseconds();
while (fracSecsStr.length < 3)
fracSecsStr += "0";
......@@ -1506,7 +1507,7 @@ TorProtocolService.prototype =
else
{
var maxEntries =
TorLauncherUtil.getIntPref(this.kPrefMaxTorLogEntries, 0);
TorLauncherUtil.getIntPref(this.kPrefMaxTorLogEntries, 1000);
if ((maxEntries > 0) && (this.mTorLog.length >= maxEntries))
this.mTorLog.splice(0, 1);
}
......
......@@ -39,6 +39,14 @@
<em:maxVersion>*.*.*</em:maxVersion>
</Description>
</em:targetApplication>
<!-- fennec -->
<em:targetApplication>
<Description>
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
<em:minVersion>45.0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
// Copyright (c) 2013, The Tor Project, Inc.
// Copyright (c) 2018, The Tor Project, Inc.
// See LICENSE for licensing information.
// TODO: Based on torbutton-logger.js (pull in copyright and license?)
//
......@@ -108,8 +108,8 @@ let TLLoggerInternal = // Private
{
// Register observer
var prefs = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefBranchInternal)
.QueryInterface(Ci.nsIPrefBranchInternal);
.getService(Ci.nsIPrefBranch)
.QueryInterface(Ci.nsIPrefBranch);
prefs.addObserver("extensions.torlauncher", this, false);
this.mLogLevel = TorLauncherUtil.getIntPref(
......
......@@ -226,6 +226,11 @@ let TorLauncherUtil = // Public
},
// Preferences
loadDefaultPreferences: function()
{
return TLUtilInternal._loadPreferences();
},
getBoolPref: function(aPrefName, aDefaultVal)
{
var rv = (undefined != aDefaultVal) ? aDefaultVal : false;
......@@ -658,9 +663,9 @@ let TorLauncherUtil = // Public
try
{
if ("tordatadir" == aTorFileType)
torFile.create(torFile.DIRECTORY_TYPE, 0700);
torFile.create(torFile.DIRECTORY_TYPE, 0o700);
else
torFile.create(torFile.NORMAL_FILE_TYPE, 0600);
torFile.create(torFile.NORMAL_FILE_TYPE, 0o600);
}
catch (e)
{
......@@ -749,6 +754,9 @@ let TLUtilInternal = // Private
mAppDir: null, // nsIFile (cached; access via this._appDir)
mDataDir: null, // nsIFile (cached; access via this._dataDir)
mIsFirstIPCPathRequest : true,
mNumDefaultPrefsDefined: 0,
mNumDefaultPrefsLoaded: 0,
mDefaultPreferencesLoaded: false,
_init: function()
{
......@@ -756,6 +764,106 @@ let TLUtilInternal = // Private
.getService(Ci.nsIPrefBranch);
},
_getPrefDefaultBranch: function(aBranchName)
{
return Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getDefaultBranch(aBranchName);
},
_setPref: function(aSetPrefFunc, aPrefName, aValue)
{
try
{
aSetPrefFunc(aPrefName, aValue);
}
catch(e)
{
TorLauncherLogger.log(5, "Setting default pref '" + aPrefName +
"' threw exception: " + e);
return false;
}
return true;
},
pref: function (aPrefName, aValue)
{
// Increment this counter for each pref() call.
this.mNumDefaultPrefsDefined += 1;
let lastPeriod = aPrefName.lastIndexOf(".");
// This pref doesn't contain a period (".")
// or the period is the first character.
if (lastPeriod == 0 || lastPeriod == -1)
{
TorLauncherLogger.log(5, "Ignoring invalid pref '" + aPrefName + "'");
return;
}
// This pref has a period at the last character, we can't set
// a default value on a pref root.
if (aPrefName.length == (lastPeriod + 1))
{
TorLauncherLogger.log(5,
"Ignoring invalid pref ending with a period: '" + aPrefName + "'");
return;
}
let prefRoot = aPrefName.substring(0, lastPeriod + 1);
let defaultBranch = this._getPrefDefaultBranch(prefRoot);
let prefName = aPrefName.substring(lastPeriod + 1);
let setPrefFunc;
switch (typeof aValue)
{
case "boolean":
setPrefFunc = defaultBranch.setBoolPref;
if (!this._setPref(setPrefFunc, prefName, aValue))
{
return;
}
break;
case "number":
setPrefFunc = defaultBranch.setIntPref;
if (!this._setPref(setPrefFunc, prefName, aValue))
{
return;
}
break;
case "string":
setPrefFunc = defaultBranch.setCharPref;
if (!this._setPref(setPrefFunc, prefName, aValue))
{
return;
}
break;
default:
TorLauncherLogger.log(5, "Cowardly not setting pref '" +
aPrefName + "' of type '" + (typeof aValue) + "'");
return;
}
// Increment this counter for each pref() call where the default preference
// was successfully set.
this.mNumDefaultPrefsLoaded += 1;
},
_loadPreferences: function()
{
if (this.mDefaultPreferencesLoaded)
{
return this.mDefaultPreferencesLoaded;
}
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
loader.loadSubScript(
"resource://torlauncher/defaults/preferences/prefs.js", this);
this.mDefaultPreferencesLoaded =
(this.mNumDefaultPrefsDefined == this.mNumDefaultPrefsLoaded);
return this.mDefaultPreferencesLoaded;
},
get _stringBundle()
{
if (!this.mStringBundle)
......@@ -883,7 +991,7 @@ let TLUtilInternal = // Private
let d = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
d.initWithPath(aBasePath);
d.append("Tor");
d.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
d.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o700);
return d;
}
catch (e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment