Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tor profile service #357

Merged
merged 25 commits into from
Sep 14, 2018
Merged

Tor profile service #357

merged 25 commits into from
Sep 14, 2018

Conversation

darkdh
Copy link
Member

@darkdh darkdh commented Aug 24, 2018

fix brave/brave-browser#361
fix brave/brave-browser#360
fix brave/brave-browser#376

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.
  • Add appropriate QA labels (QA/Needed or QA/No-QA-Needed) to include the closed issue in milestone

Test Plan:

  • Manual test

    1. Open Tor window and check tor connectivity by going to https://check.torproject.org/ screen shot 2018-09-12 at 19 44 21
    2. Use fresh profile and "Open Tor Window" will show up only when tor executable is downloaded (see cldoidikboihgcjfkhdeidbpclkineef for mac ,
      cpoalefficncklhjfpglfiplenlpccdb for Windows and
      biahpgbdmdkfgndcmfiipgcebobojjkp for Linux, in user dir)
    3. When https://check.torproject.org/ shows you are connected to tor network, click "New Tor Identity" in app menu and page will refresh and shows different ip address screen shot 2018-09-12 at 19 51 25
    4. Quit Brave and do ps aux |grep <hash based on OS>, there shouldn't be any tor
      process left
    5. Shield should work in both tor window and guest window
  • Unit test

    1. BraveProfileManager
    2. BraveTorNetworkDelegateHelper

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

@darkdh darkdh self-assigned this Aug 24, 2018
@bbondy bbondy changed the title [WIP] Tor profile service WIP: Tor profile service Sep 3, 2018
@darkdh darkdh force-pushed the tor_profile_service branch 4 times, most recently from c43af3c to 187bcbc Compare September 11, 2018 06:56
@darkdh
Copy link
Member Author

darkdh commented Sep 11, 2018

C70 rebased

@darkdh darkdh changed the title WIP: Tor profile service Tor profile service Sep 11, 2018
@darkdh darkdh requested a review from bbondy September 11, 2018 06:56
tor::TorProfileService* TorProfileServiceFactory::GetForProfile(
Profile* profile) {
if (profile->IsOffTheRecord())
return NULL;
Copy link
Member

Choose a reason for hiding this comment

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

nit: prefer nullptr since that's the standard.

Brians-iMac-Pro-2:src brianbondy$ git grep return\ NULL | wc -l
3843
Brians-iMac-Pro-2:src brianbondy$ git grep return\ nullptr | wc -l
12074

"//components/keyed_service/content",
"//components/keyed_service/core",
# for profile.h
"//components/domain_reliability",
Copy link
Member

Choose a reason for hiding this comment

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

I think alphabetical is preferred?

@diracdeltas
Copy link
Member

if i understand correctly, this doesn't actually provide a Tor binary yet? FYI we will be updating to Tor 0.3.4 soon so i recommend testing with that: brave/tor_build_scripts#23

@bbondy
Copy link
Member

bbondy commented Sep 11, 2018

Tor binary is already provided as a crx installation, works the same way extension install works.

@bbondy
Copy link
Member

bbondy commented Sep 11, 2018

@darkdh
Copy link
Member Author

darkdh commented Sep 11, 2018

And we access it through TorClientUpdater #316

Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

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

Nothing major, awesome work!

void TorProxyConfigService::TorSetProxy(
net::ProxyResolutionService* service,
const std::string& tor_proxy,
const std::string& site_url,
Copy link
Member

Choose a reason for hiding this comment

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

Since we bind these parameters, this will cause various crashes. These must be std::string and not a const std::string&

if (url.scheme.is_valid()) {
scheme_ =
std::string(tor_proxy.begin() + url.scheme.begin,
tor_proxy.begin() + url.scheme.begin + url.scheme.len);
Copy link
Member

Choose a reason for hiding this comment

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

Can all of these be expressed more simply like this?
scheme_ = tor_proxy.substr(url.scheme.begin, url.scheme.len);

tor_proxy.begin() + url.port.begin + url.port.len);
}
std::string proxy_url;
if (tor_proxy_map && !username.empty()) {
Copy link
Member

Choose a reason for hiding this comment

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

What is the right thing to do if host_ is not filled or port_ is not filled?

Copy link
Member Author

Choose a reason for hiding this comment

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

it actually doesn't matter here because the config will remain empty but I will still do a early return when scheme_ or host_ or port_ is empty.

Copy link
Member

Choose a reason for hiding this comment

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

ok

// map, the old entry in the queue will cease to affect it because
// the timestamps won't match, and they will simultaneously create a
// new entry in the queue.
map_.erase(username);
Copy link
Member

Choose a reason for hiding this comment

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

Should we wrap this to check if it exists in the map first? I think it will cause a crash if it doesn't if there was no Get called.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't get it, if you are able to call TorProxyMap::Erase that means you have TorProxyMap instance which always has a std::map<std::string, std::pair<std::string, base::Time> > in it. Even if you specify non existent key, the erase operation just return 0. There shouldn't be any crashes.

Copy link
Member

Choose a reason for hiding this comment

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

ok

static void TorSetProxy(
net::ProxyResolutionService* service,
const std::string& tor_proxy,
const std::string& site_url,
Copy link
Member

Choose a reason for hiding this comment

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

Update to std::string.

diff --git a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
index a053f001493dc3815ee9bb0a6d4526bfe65718dd..348a783485741370796073076cbbf78666911665 100644
--- a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
Copy link
Member

Choose a reason for hiding this comment

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

I prefer a subclass for the tooltip patch since I envision multiple different types of things here in the future.

service_manager::switches::kNoSandbox)) {
base::LaunchOptions options;
options.handles_to_inherit = handles_to_inherit;
+ options.start_hidden = true;
Copy link
Member

Choose a reason for hiding this comment

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

are there any other process types started here which we don't want hidden?

Copy link
Member Author

Choose a reason for hiding this comment

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

for now, we only want to hide utility process type for audio service and tor launcher service specifically

Copy link
Member

Choose a reason for hiding this comment

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

do you know for sure nothing else uses this code path though?

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like all child process on Window will enter this function but only non sandboxed child process would hit this block

Copy link
Member Author

Choose a reason for hiding this comment

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

and in that case, you will see the popup terminal window so that would be only audio service and tor launcher service for now

Copy link
Member Author

Choose a reason for hiding this comment

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

we can also enable service_manager::features::kAudioServiceSandbox and I can add this specifically for tor launcher service

Copy link
Member Author

Choose a reason for hiding this comment

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

Audio Service part is updated in the issue.
brave/brave-browser#714 (comment)

// artificial and background page shouldn't be created in it.
// http://crbug.com/329498
- return is_normal_session || profile->IsOffTheRecord();
+ return is_normal_session || profile->IsOffTheRecord() || profile->IsTorProfile();
Copy link
Member

Choose a reason for hiding this comment

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

Can we allow it for guest profiles here too? Or is there some problem why it's disallowed?

I think we can add this to fixed list if so:
brave/brave-browser#376

<message name="IDS_PROFILES_OPEN_TOR_PROFILE_BUTTON" desc="Button in the avatar menu bubble view to open a tor window.">
Open Tor Window
</message>
<message name="IDS_PROFILES_TOR_PROFILE_NAME" desc="Name of the tor profile.">
Copy link
Member

Choose a reason for hiding this comment

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

nit: I know it's only a description, but capitalization might help a localizer to know it's a name.

void TorProfileServiceImpl::SetNewTorCircuit(const GURL& request_url) {}
void TorProfileServiceImpl::SetNewTorCircuitOnIOThread(
const scoped_refptr<net::URLRequestContextGetter>& getter,
const std::string& host) {
Copy link
Member

Choose a reason for hiding this comment

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

Use std::string host here or it can introduce crashes.

@darkdh darkdh force-pushed the tor_profile_service branch from 0d0dcb7 to 30abf5c Compare September 12, 2018 00:14
// This needs to run after ChromeTestSuite::Initialize which calls content's
// intialization which calls base's which initializes ICU.
InitializeResourceBundle();
+ brave::InitializeResourceBundle();
Copy link
Member

Choose a reason for hiding this comment

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

Pls move to brave_unit_test_suite.cc after the Initialize call.

@darkdh darkdh force-pushed the tor_profile_service branch 2 times, most recently from 13c5cb5 to 243c5f3 Compare September 12, 2018 04:58
@diracdeltas
Copy link
Member

defer my review to @riastradh-brave

@darkdh darkdh force-pushed the tor_profile_service branch from fd1613b to 3e43852 Compare September 12, 2018 22:10
@diracdeltas
Copy link
Member

doesn't block but i opened brave/brave-core-crx-packager#24 for updating the tor version

@darkdh
Copy link
Member Author

darkdh commented Sep 13, 2018

build and browser/unit tests pass on all platforms. Also manually verify tor function works

namespace {
void BraveLaunchOption(base::CommandLine* cmd_line,
base::LaunchOptions *options) {
// tor::swtiches::kTorExecutablePath
Copy link
Member

Choose a reason for hiding this comment

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

so why not just use tor::swtiches::kTorExecutablePath like the comment says?

Copy link
Member Author

Choose a reason for hiding this comment

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

that will have to patch the BUILD.gn and also leads to circular deps.
Probably can do when we migrate to components/tor

bbondy
bbondy previously approved these changes Sep 13, 2018
Copy link
Member

@bbondy bbondy left a comment

Choose a reason for hiding this comment

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

incremental commits lgtm

Note: brave::InitializeResourceBundle cannot be called per unit test
suites, it can only be called each unittest run or it will lead to
duplicate resources
1. const std::string => std::string in bind function
2. Tor resource strings descrition
3. Use substr(...)
4. Early return when scheme_, host_ or port_ is empty
5. nits
to prevent it from generating new terminal window on Windows
@darkdh darkdh force-pushed the tor_profile_service branch 2 times, most recently from 5735691 to e81c259 Compare September 13, 2018 19:42
Copy link
Contributor

@riastradh-brave riastradh-brave left a comment

Choose a reason for hiding this comment

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

LGTM, sorry this took so long! A lot of the logic is essentially the same as in muon. The organization into keyed services is cleaner, as we discussed with brianjohnson.

args.AppendArg("--cookieauthentication");
args.AppendArg("1");
args.AppendArg("--cookieauthfile");
args.AppendArgPath(tor_watch_path.AppendASCII("control_auth_cookie"));
Copy link
Contributor

Choose a reason for hiding this comment

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

These are all basically the same as in muon, looks fine to me.

@darkdh darkdh merged commit 84a4955 into master Sep 14, 2018
@bbondy
Copy link
Member

bbondy commented Sep 14, 2018

🎉 👍 💯

bbondy pushed a commit that referenced this pull request Sep 14, 2018
@bbondy
Copy link
Member

bbondy commented Sep 14, 2018

0.55.x 0e45986
master 84a4955

@bsclifton bsclifton deleted the tor_profile_service branch September 14, 2018 16:21
@bsclifton
Copy link
Member

😻

cezaraugusto added a commit that referenced this pull request Sep 15, 2018
-
interface follow-up of #357
@bbondy bbondy added this to the 0.55.x - Release milestone Jan 14, 2019
fmarier pushed a commit that referenced this pull request Oct 29, 2019
Bump patch version for new internal build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants