Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Pass socks port, data directory to tor subprocess #553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ mate::Handle<api::Session> SessionFromOptions(v8::Isolate* isolate,
if (options.Get("tor_path", &tor_path)) {
session_options.SetString("tor_path", tor_path);
}
std::string tor_data_dir;
if (options.Get("tor_data_dir", &tor_data_dir)) {
session_options.SetString("tor_data_dir", tor_data_dir);
}
session = Session::FromPartition(isolate, partition, session_options);
} else {
// Use the default session if not specified.
Expand Down
33 changes: 32 additions & 1 deletion brave/browser/brave_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,43 @@ BraveBrowserContext::BraveBrowserContext(
std::string tor_proxy;
std::string tor_path;
if (options.GetString("tor_proxy", &tor_proxy)) {
url::Parsed url;
url::ParseStandardURL(
tor_proxy.c_str(),
std::min(tor_proxy.size(),
static_cast<size_t>(std::numeric_limits<int>::max())),
&url);
std::string tor_host, tor_port;
if (url.host.is_valid()) {
tor_host =
std::string(tor_proxy.begin() + url.host.begin,
tor_proxy.begin() + url.host.begin + url.host.len);
}
if (url.port.is_valid()) {
tor_port =
std::string(tor_proxy.begin() + url.port.begin,
tor_proxy.begin() + url.port.begin + url.port.len);
}
tor_proxy_ = GURL(tor_proxy);
if (!tor_process_.IsValid()) {
if (options.GetString("tor_path", &tor_path)) {
base::FilePath tor(tor_path);
base::CommandLine cmdline(tor);
tor_process_ = base::LaunchProcess(cmdline, base::LaunchOptions());
base::LaunchOptions launchopts;
cmdline.AppendArg("--ignore-missing-torrc");
cmdline.AppendArg("-f");
cmdline.AppendArg("/nonexistent");
cmdline.AppendArg("--defaults-torrc");
cmdline.AppendArg("/nonexistent");
cmdline.AppendArg("--SocksPort");
cmdline.AppendArg(tor_host + ":" + tor_port);
std::string datadir;
if (options.GetString("tor_data_dir", &datadir)) {
cmdline.AppendArg("--DataDirectory");
cmdline.AppendArg(datadir);
}
launchopts.kill_on_parent_death = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be guarded by #if defined(OS_LINUX), I will do changes
and all the platforms will have https://github.com/brave/muon/pull/473/files#diff-df5c427fd693f9ebb2e5952cf0e9c8c7R248 to ensure the child process is terminated when parent is down

tor_process_ = base::LaunchProcess(cmdline, launchopts);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/browser/api/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ const createTab = function (createProperties, cb) {
parent_partition: createProperties.parent_partition,
isolated_storage: createProperties.isolated_storage,
tor_proxy: createProperties.tor_proxy,
tor_path: createProperties.tor_path
tor_path: createProperties.tor_path,
tor_data_dir: createProperties.tor_data_dir
})
// don't pass the partition info through
delete createProperties.partition
Expand Down