-
Notifications
You must be signed in to change notification settings - Fork 905
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
Handle onion-location HTTP header & .onion domain #6762
Changes from all commits
32e4594
04e6ae4
2fcf841
31cb0d2
ba2de91
89c36b0
e01eafe
8faf100
37aa257
5d74b40
6c12465
f14d87a
4494e6a
165c706
15b4acd
f097016
008196f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
CANVAS_DIMENSIONS, 12, | ||
MOVE_TO, 11.5f, 10, | ||
R_CUBIC_TO, -0.28f, 0, -0.5f, -0.22f, -0.5f, -0.5f, | ||
V_LINE_TO, 1, | ||
H_LINE_TO, 2.5f, | ||
CUBIC_TO, 2.22f, 1, 2, 0.78f, 2, 0.5f, | ||
R_CUBIC_TO, 0, -0.28f, 0.22f, -0.5f, 0.5f, -0.5f, | ||
H_LINE_TO, 11, | ||
R_CUBIC_TO, 0.55f, 0, 1, 0.45f, 1, 1, | ||
R_V_LINE_TO, 8.5f, | ||
R_CUBIC_TO, 0, 0.28f, -0.22f, 0.5f, -0.5f, 0.5f, | ||
CLOSE, | ||
MOVE_TO, 10, 3, | ||
R_V_LINE_TO, 8, | ||
R_CUBIC_TO, 0, 0.55f, -0.45f, 1, -1, 1, | ||
H_LINE_TO, 1, | ||
R_CUBIC_TO, -0.55f, 0, -1, -0.45f, -1, -1, | ||
V_LINE_TO, 3, | ||
R_CUBIC_TO, 0, -0.55f, 0.45f, -1, 1, -1, | ||
R_H_LINE_TO, 8, | ||
R_CUBIC_TO, 0.55f, 0, 1, 0.45f, 1, 1, | ||
CLOSE, | ||
R_MOVE_TO, -9, 8, | ||
R_H_LINE_TO, 8, | ||
R_LINE_TO, 0, -6, | ||
H_LINE_TO, 1, | ||
R_V_LINE_TO, 6, | ||
CLOSE, | ||
R_MOVE_TO, 0, -7, | ||
R_H_LINE_TO, 8, | ||
V_LINE_TO, 3, | ||
H_LINE_TO, 1, | ||
R_V_LINE_TO, 1, | ||
CLOSE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,13 @@ | |
disabled="[[disableTorOption_]]" | ||
on-settings-boolean-control-change="onTorEnabledChange_"> | ||
</settings-toggle-button> | ||
<settings-toggle-button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like bad spacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 08ec907 |
||
pref="{{prefs.tor.auto_onion_location}}" | ||
class="cr-row" | ||
label="$i18n{autoOnionLocationLabel}" | ||
sub-label="$i18n{autoOnionLocationDesc}" | ||
disabled="[[!torEnabled_]]"> | ||
</settings-toggle-button> | ||
</if> | ||
<settings-toggle-button id="webTorrentEnabled" | ||
class="cr-row" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/tor/onion_location_navigation_throttle.h" | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include "base/bind.h" | ||
#include "brave/browser/profiles/profile_util.h" | ||
#include "brave/browser/tor/onion_location_tab_helper.h" | ||
#include "brave/browser/tor/tor_profile_service.h" | ||
#include "brave/common/tor/pref_names.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/profiles/profile_window.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_finder.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
namespace tor { | ||
|
||
namespace { | ||
|
||
bool GetOnionLocation(const net::HttpResponseHeaders* headers, | ||
std::string* onion_location) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 08ec907 |
||
DCHECK(onion_location); | ||
|
||
onion_location->clear(); | ||
std::string name = "onion-location"; | ||
|
||
if (!headers || !headers->EnumerateHeader(nullptr, name, onion_location)) | ||
return false; | ||
return true; | ||
} | ||
|
||
void OnTorProfileCreated(GURL onion_location, | ||
Profile* profile, | ||
Profile::CreateStatus status) { | ||
if (status != Profile::CreateStatus::CREATE_STATUS_INITIALIZED) | ||
return; | ||
Browser* browser = chrome::FindTabbedBrowser(profile, true); | ||
if (!browser) | ||
return; | ||
content::OpenURLParams open_tor(onion_location, content::Referrer(), | ||
WindowOpenDisposition::OFF_THE_RECORD, | ||
ui::PAGE_TRANSITION_TYPED, false); | ||
browser->OpenURL(open_tor); | ||
} | ||
|
||
} // namespace | ||
|
||
// static | ||
std::unique_ptr<OnionLocationNavigationThrottle> | ||
OnionLocationNavigationThrottle::MaybeCreateThrottleFor( | ||
content::NavigationHandle* navigation_handle) { | ||
if (tor::TorProfileService::IsTorDisabled() || | ||
!navigation_handle->IsInMainFrame()) | ||
return nullptr; | ||
return std::make_unique<OnionLocationNavigationThrottle>(navigation_handle); | ||
} | ||
|
||
OnionLocationNavigationThrottle::OnionLocationNavigationThrottle( | ||
content::NavigationHandle* navigation_handle) | ||
: content::NavigationThrottle(navigation_handle) { | ||
profile_ = Profile::FromBrowserContext( | ||
navigation_handle->GetWebContents()->GetBrowserContext()); | ||
} | ||
|
||
OnionLocationNavigationThrottle::~OnionLocationNavigationThrottle() {} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
OnionLocationNavigationThrottle::WillProcessResponse() { | ||
auto* headers = navigation_handle()->GetResponseHeaders(); | ||
std::string onion_location; | ||
// The webpage defining the Onion-Location header must not be an onionsite. | ||
// https://gitweb.torproject.org/tor-browser-spec.git/plain/proposals/100-onion-location-header.txt | ||
if (headers && GetOnionLocation(headers, &onion_location) && | ||
!navigation_handle()->GetURL().DomainIs("onion")) { | ||
bbondy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If user prefers opening it automatically | ||
if (profile_->GetPrefs()->GetBoolean(prefs::kAutoOnionLocation)) { | ||
profiles::SwitchToTorProfile( | ||
base::BindRepeating(&OnTorProfileCreated, GURL(onion_location))); | ||
// We do not close last tab of the window | ||
Browser* browser = chrome::FindBrowserWithProfile(profile_); | ||
if (browser && browser->tab_strip_model()->count() > 1) | ||
navigation_handle()->GetWebContents()->ClosePage(); | ||
} else { | ||
OnionLocationTabHelper::SetOnionLocation( | ||
navigation_handle()->GetWebContents(), GURL(onion_location)); | ||
} | ||
} else { | ||
OnionLocationTabHelper::SetOnionLocation( | ||
navigation_handle()->GetWebContents(), GURL()); | ||
} | ||
return content::NavigationThrottle::PROCEED; | ||
} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
OnionLocationNavigationThrottle::WillStartRequest() { | ||
// Open .onion site in Tor window | ||
if (!brave::IsTorProfile(profile_)) { | ||
GURL url = navigation_handle()->GetURL(); | ||
if (url.SchemeIsHTTPOrHTTPS() && url.DomainIs("onion")) { | ||
profiles::SwitchToTorProfile( | ||
base::BindRepeating(&OnTorProfileCreated, std::move(url))); | ||
return content::NavigationThrottle::CANCEL_AND_IGNORE; | ||
} | ||
} | ||
return content::NavigationThrottle::PROCEED; | ||
} | ||
|
||
const char* OnionLocationNavigationThrottle::GetNameForLogging() { | ||
return "OnionLocationNavigationThrottle"; | ||
} | ||
|
||
} // namespace tor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_TOR_ONION_LOCATION_NAVIGATION_THROTTLE_H_ | ||
#define BRAVE_BROWSER_TOR_ONION_LOCATION_NAVIGATION_THROTTLE_H_ | ||
|
||
#include <memory> | ||
|
||
#include "chrome/browser/profiles/profile.h" | ||
#include "content/public/browser/navigation_throttle.h" | ||
|
||
class Profile; | ||
|
||
namespace content { | ||
class NavigationHandle; | ||
} // namespace content | ||
|
||
namespace tor { | ||
|
||
class OnionLocationNavigationThrottle : public content::NavigationThrottle { | ||
public: | ||
static std::unique_ptr<OnionLocationNavigationThrottle> | ||
MaybeCreateThrottleFor(content::NavigationHandle* navigation_handle); | ||
explicit OnionLocationNavigationThrottle( | ||
content::NavigationHandle* navigation_handle); | ||
~OnionLocationNavigationThrottle() override; | ||
|
||
// content::NavigationThrottle implementation: | ||
ThrottleCheckResult WillProcessResponse() override; | ||
ThrottleCheckResult WillStartRequest() override; | ||
const char* GetNameForLogging() override; | ||
|
||
private: | ||
Profile* profile_; | ||
|
||
OnionLocationNavigationThrottle(const OnionLocationNavigationThrottle&) = | ||
delete; | ||
OnionLocationNavigationThrottle& operator=( | ||
const OnionLocationNavigationThrottle&) = delete; | ||
}; | ||
|
||
} // namespace tor | ||
|
||
#endif // BRAVE_BROWSER_TOR_ONION_LOCATION_NAVIGATION_THROTTLE_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in b7daf7b5130287c1ef8cffae28104cfa0c189ca5