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 bridges support [Client part] #13290

Merged
merged 40 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d34b196
Explicit sandbox attribute for TorLauncher instead of specializtion o…
boocmp Apr 25, 2022
5b4d445
Static strlen for constants.
boocmp Apr 28, 2022
195615d
Using base::GetDeletePathRecursivelyCallback & GetDeleteFileCallback
boocmp Apr 29, 2022
edba071
Removed unnecessary unique_ptr.
boocmp Apr 29, 2022
5fb1781
Added tor.bridges profile pref.
boocmp Apr 29, 2022
da70e98
Component updater for Pluggable transports.
boocmp May 9, 2022
fded69a
Reworked Tor browser test.
boocmp May 10, 2022
0534a7d
Added Tor bridges test
boocmp May 11, 2022
27cd096
Added bridge reset test.
boocmp May 11, 2022
22a52c8
Added built-in bridges list.
boocmp May 11, 2022
b4742b8
Lint.
boocmp May 11, 2022
2b91a1d
GN & deps.
boocmp May 11, 2022
2002a67
NOLINT for built-in bridges.
boocmp May 11, 2022
83086d9
Test data for mac & linux.
boocmp May 11, 2022
f35c714
GN format.
boocmp May 11, 2022
a738e93
Fixing tests.
boocmp May 12, 2022
b16f5cc
Review issues.
boocmp May 17, 2022
a579c00
Different ids on different platforms.
boocmp May 24, 2022
0627150
Added settings page. Not final version.
boocmp Jun 2, 2022
e750114
Added localized strings.
boocmp Jun 2, 2022
de639c4
Request bridge dialog layout.
boocmp Jun 6, 2022
f637e5e
Lint.
boocmp Jun 6, 2022
7185946
Tests compilation.
boocmp Jun 7, 2022
da13aa2
Safe wild image decode.
boocmp Jun 8, 2022
2af0678
Learn more url.
boocmp Jun 13, 2022
2316fa7
Rebased.
boocmp Jun 13, 2022
5741291
Review.
boocmp Jun 29, 2022
023bec2
NOLINT(fn_size) for BraveAddCommonStrings.
boocmp Jun 29, 2022
621d4e6
Moved Tor settings in the separate section.
boocmp Jul 1, 2022
8d57136
Review.
boocmp Jul 5, 2022
4e1328c
Tor settings moved to Privacy page.
boocmp Jul 13, 2022
2eaafdb
Error messages in dev console fixed.
boocmp Jul 20, 2022
5c665df
Unregister bridges component on user action.
boocmp Jul 20, 2022
87f46a9
Fixed unit tests & learn more url.
boocmp Jul 21, 2022
8711961
Renamed isUsingBridges_.
boocmp Jul 22, 2022
e886560
Tor new tab page description and failure messages were added.
boocmp Jul 28, 2022
396e421
Lint.
boocmp Jul 29, 2022
d392909
Test compilation.
boocmp Jul 29, 2022
340df6f
Review.
boocmp Aug 1, 2022
7c79edb
Last tuning.
boocmp Aug 2, 2022
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
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
</message>

<!-- Tor -->
<message name="IDS_BRAVE_TOR_SETTINGS_SECTION" desc="Open Tor settings section">
Tor windows
</message>
<message name="IDS_NEW_TOR_IDENTITY" desc="The text label of a menu item for requesting new Tor identity">
New Tor Identity
</message>
Expand Down
54 changes: 54 additions & 0 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,60 @@
<message name="IDS_SETTINGS_ENABLE_TOR_DESC" desc="Text fragment for enabling tor component">
Tor hides your IP address from the sites you visit.
</message>
<message name="IDS_SETTINGS_TOR_USE_BRIDGES_TITLE" desc="">
Use Bridges
</message>
<message name="IDS_SETTINGS_TOR_USE_BRIDGES_DESC" desc="">
Bridges help you access the Tor Network in place where Tor is blocked. Depending on where you are, one bridge may work better than another.
</message>
<message name="IDS_SETTINGS_TOR_CONNECTION_SETTINGS_TITLE" desc="">
Tor connection settings
</message>
<message name="IDS_SETTINGS_TOR_CONNECTION_SETTINGS_DESC" desc="">
Controls how Private Windows with Tor connect to the Tor network
</message>
<message name="IDS_SETTINGS_TOR_SELECT_BUILT_IN_RADIO" desc="">
Select a built-in bridge
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_BRIDGES_RADIO" desc="">
Request a bridge from torproject.org
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_NEW_BRIDGE_BUTTON" desc="">
Request a New Bridge...
</message>
<message name="IDS_SETTINGS_TOR_PROVIDE_BRIDGES_RADIO" desc="">
Provide a bridge
</message>
<message name="IDS_SETTINGS_TOR_ENTER_BRIDGE_INFO_LABEL" desc="">
Enter bridge information from a trusted source.
</message>
<message name="IDS_SETTINGS_TOR_APPLY_CHANGES_BUTTON" desc="">
Apply changes
</message>
<message name="IDS_SETTINGS_TOR_REQUESTED_BRIDGES_PLACEHOLDER" desc="">
Click on 'Request a New Bridge...' to get bridges
</message>
<message name="IDS_SETTINGS_TOR_PROVIDED_BRIDGES_PLACEHOLDER" desc="">
Type address:port (one per line)
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_BRIDGE_DIALOG_TITLE" desc="">
Request Bridge
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_BRIDGE_DIALOG_WAITING" desc="">
Contacting BridgeDB. Please wait.
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_BRIDGE_DIALOG_SOLVE" desc="">
Solve the CAPTCHA to request a bridge.
</message>
<message name="IDS_SETTINGS_TOR_REQUEST_BRIDGE_DIALOG_ERROR" desc="">
Can't request a CAPTCHA. Try again later.
</message>
<message name="IDS_SETTINGS_TOR_SUBMIT_DIALOG_BUTTON" desc="Text fragment for enabling tor component">
Submit
</message>
<message name="IDS_SETTINGS_TOR_CANCEL_DIALOG_BUTTON" desc="Text fragment for enabling tor component">
Cancel
</message>
<message name="IDS_SETTINGS_AUTO_ONION_LOCATION_TITLE" desc="Text fragment for onion site component">
Automatically redirect .onion sites
</message>
Expand Down
3 changes: 3 additions & 0 deletions browser/brave_browser_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NTPBackgroundImagesService;

namespace tor {
class BraveTorClientUpdater;
class BraveTorPluggableTransportUpdater;
}

namespace ipfs {
Expand Down Expand Up @@ -91,6 +92,8 @@ class BraveBrowserProcess {
local_data_files_service() = 0;
#if BUILDFLAG(ENABLE_TOR)
virtual tor::BraveTorClientUpdater* tor_client_updater() = 0;
virtual tor::BraveTorPluggableTransportUpdater*
tor_pluggable_transport_updater() = 0;
#endif
#if BUILDFLAG(ENABLE_IPFS)
virtual ipfs::BraveIpfsClientUpdater* ipfs_client_updater() = 0;
Expand Down
19 changes: 17 additions & 2 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "brave/browser/brave_browser_process_impl.h"

#include <memory>
#include <string>
#include <utility>

Expand Down Expand Up @@ -65,6 +66,7 @@

#if BUILDFLAG(ENABLE_TOR)
#include "brave/components/tor/brave_tor_client_updater.h"
#include "brave/components/tor/brave_tor_pluggable_transport_updater.h"
#include "brave/components/tor/pref_names.h"
#endif

Expand Down Expand Up @@ -294,11 +296,24 @@ tor::BraveTorClientUpdater* BraveBrowserProcessImpl::tor_client_updater() {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);

tor_client_updater_.reset(new tor::BraveTorClientUpdater(
brave_component_updater_delegate(), local_state(), user_data_dir));
tor_client_updater_ = std::make_unique<tor::BraveTorClientUpdater>(
brave_component_updater_delegate(), local_state(), user_data_dir);
return tor_client_updater_.get();
}

tor::BraveTorPluggableTransportUpdater*
BraveBrowserProcessImpl::tor_pluggable_transport_updater() {
if (!tor_pluggable_transport_updater_) {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);

tor_pluggable_transport_updater_ =
std::make_unique<tor::BraveTorPluggableTransportUpdater>(
brave_component_updater_delegate(), local_state(), user_data_dir);
}
return tor_pluggable_transport_updater_.get();
}

void BraveBrowserProcessImpl::OnTorEnabledChanged() {
// Update all browsers' tor command status.
for (Browser* browser : *BrowserList::GetInstance()) {
Expand Down
6 changes: 6 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/speedreader/common/buildflags.h"
#include "brave/components/tor/brave_tor_pluggable_transport_updater.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/browser_process_impl.h"
#include "extensions/buildflags/buildflags.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ class NTPBackgroundImagesService;

namespace tor {
class BraveTorClientUpdater;
class BraveTorPluggableTransportUpdater;
}

namespace ipfs {
Expand Down Expand Up @@ -102,6 +104,8 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
override;
#if BUILDFLAG(ENABLE_TOR)
tor::BraveTorClientUpdater* tor_client_updater() override;
tor::BraveTorPluggableTransportUpdater* tor_pluggable_transport_updater()
override;
#endif
#if BUILDFLAG(ENABLE_IPFS)
ipfs::BraveIpfsClientUpdater* ipfs_client_updater() override;
Expand Down Expand Up @@ -160,6 +164,8 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
#endif
#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<tor::BraveTorClientUpdater> tor_client_updater_;
std::unique_ptr<tor::BraveTorPluggableTransportUpdater>
tor_pluggable_transport_updater_;
#endif
#if BUILDFLAG(ENABLE_IPFS)
std::unique_ptr<ipfs::BraveIpfsClientUpdater> ipfs_client_updater_;
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
#if BUILDFLAG(ENABLE_TOR)
(*s_brave_allowlist)[tor::prefs::kAutoOnionRedirect] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[tor::prefs::kBridgesConfig] =
settings_api::PrefType::PREF_TYPE_DICTIONARY;
#endif
(*s_brave_allowlist)[prefs::kWebRTCIPHandlingPolicy] =
settings_api::PrefType::PREF_TYPE_STRING;
Expand Down
25 changes: 24 additions & 1 deletion browser/extensions/brave_extension_management.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_manager.h"
#include "brave/components/tor/brave_tor_client_updater.h"
#include "brave/components/tor/brave_tor_pluggable_transport_updater.h"
#include "brave/components/tor/pref_names.h"
#endif

Expand All @@ -53,6 +54,11 @@ BraveExtensionManagement::BraveExtensionManagement(Profile* profile)
tor::prefs::kTorDisabled,
base::BindRepeating(&BraveExtensionManagement::OnTorDisabledChanged,
base::Unretained(this)));
local_state_pref_change_registrar_.Add(
tor::prefs::kBridgesConfig,
base::BindRepeating(
&BraveExtensionManagement::OnTorPluggableTransportChanged,
base::Unretained(this)));
#endif
// Make IsInstallationExplicitlyAllowed to be true
#if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED)
Expand Down Expand Up @@ -85,7 +91,23 @@ void BraveExtensionManagement::OnTorDisabledChanged() {
#if BUILDFLAG(ENABLE_TOR)
if (TorProfileServiceFactory::IsTorDisabled()) {
TorProfileManager::GetInstance().CloseAllTorWindows();
g_brave_browser_process->tor_client_updater()->Cleanup();
if (g_brave_browser_process->tor_client_updater()) {
g_brave_browser_process->tor_client_updater()->Cleanup();
}
if (g_brave_browser_process->tor_pluggable_transport_updater()) {
g_brave_browser_process->tor_pluggable_transport_updater()->Cleanup();
}
}
#endif
}

void BraveExtensionManagement::OnTorPluggableTransportChanged() {
#if BUILDFLAG(ENABLE_TOR)
if (TorProfileServiceFactory::GetTorBridgesConfig().use_bridges ==
tor::BridgesConfig::Usage::kNotUsed) {
if (g_brave_browser_process->tor_pluggable_transport_updater()) {
g_brave_browser_process->tor_pluggable_transport_updater()->Cleanup();
}
}
#endif
}
Expand All @@ -94,6 +116,7 @@ void BraveExtensionManagement::Cleanup(content::BrowserContext* context) {
// BrowserPolicyConnector enforce policy earlier than this constructor so we
// have to manully cleanup tor executable when tor is disabled by gpo
OnTorDisabledChanged();
OnTorPluggableTransportChanged();

#if BUILDFLAG(ENABLE_IPFS)
// Remove ipfs executable if it is disabled by GPO.
Expand Down
1 change: 1 addition & 0 deletions browser/extensions/brave_extension_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BraveExtensionManagement : public ExtensionManagement,
UnloadedExtensionReason reason) override;

void OnTorDisabledChanged();
void OnTorPluggableTransportChanged();
void Cleanup(content::BrowserContext* browser_context);

PrefChangeRegistrar local_state_pref_change_registrar_;
Expand Down
4 changes: 4 additions & 0 deletions browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ preprocess_if_expr("preprocess") {
"brave_reset_page/brave_reset_profile_dialog_behavior.js",
"brave_routes.js",
"brave_sync_page/brave_sync_browser_proxy.js",
"brave_tor_page/brave_tor_browser_proxy.js",
"default_brave_shields_page/brave_adblock_browser_proxy.js",
]
}
Expand Down Expand Up @@ -162,6 +163,8 @@ preprocess_if_expr("preprocess_generated") {
"brave_sync_page/brave_sync_page.js",
"brave_sync_page/brave_sync_setup.js",
"brave_sync_page/brave_sync_subpage.js",
"brave_tor_page/brave_tor_bridges_dialog.js",
"brave_tor_page/brave_tor_subpage.js",
"brave_wallet_page/add_wallet_network_dialog.js",
"brave_wallet_page/brave_wallet_browser_proxy.m.js",
"brave_wallet_page/brave_wallet_page.js",
Expand Down Expand Up @@ -192,6 +195,7 @@ group("web_modules") {
"brave_rewards_page:web_modules",
"brave_search_engines_page:web_modules",
"brave_sync_page:web_modules",
"brave_tor_page:web_modules",
"brave_wallet_page:web_modules",
"default_brave_shields_page:web_modules",
"getting_started_page:web_modules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ cr.define('settings', function () {
*/
setWebTorrentEnabled (value) {}
setHangoutsEnabled (value) {}
setTorEnabled (value) {}
isTorEnabled () {}
isTorManaged () {}
setWidevineEnabled() {}
isWidevineEnabled() {}
getRestartNeeded () {}
Expand All @@ -42,18 +39,6 @@ cr.define('settings', function () {
chrome.send('setMediaRouterEnabled', [value])
}

setTorEnabled (value) {
chrome.send('setTorEnabled', [value])
}

isTorEnabled () {
return cr.sendWithPromise('isTorEnabled')
}

isTorManaged () {
return cr.sendWithPromise('isTorManaged')
}

setWidevineEnabled (value) {
chrome.send('setWidevineEnabled', [value])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,6 @@
pref="{{prefs.brave.ens.resolve_method}}"
menu-options="[[ensResolveMethod_]]">
</div>
<if expr="enable_tor">
<settings-toggle-button id="torEnabled"
class="cr-row"
pref="[[torEnabledPref_]]"
label="$i18n{torEnabledLabel}"
sub-label="$i18n{torEnabledDesc}"
disabled="[[disableTorOption_]]"
on-settings-boolean-control-change="onTorEnabledChange_">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.tor.auto_onion_location}}"
class="cr-row"
label="$i18n{autoOnionLocationLabel}"
sub-label="$i18n{autoOnionLocationDesc}"
disabled="[[!torEnabledPref_.value]]">
</settings-toggle-button>
</if>
<settings-toggle-button id="webTorrentEnabled"
class="cr-row"
pref="{{prefs.brave.webtorrent_enabled}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,8 @@ Polymer({

properties: {
showRestartToast_: Boolean,
disableTorOption_: Boolean,
unstoppableDomainsResolveMethod_: Array,
ensResolveMethod_: Array,
torEnabledPref_: {
type: Object,
value() {
// TODO(dbeam): this is basically only to appease PrefControlMixin.
// Maybe add a no-validate attribute instead? This makes little sense.
return {};
},
},
widevineEnabledPref_: {
type: Object,
value() {
Expand All @@ -64,7 +55,6 @@ Polymer({
this.openKeyboardShortcutsPage_ = this.openKeyboardShortcutsPage_.bind(this)
this.onWidevineEnabledChange_ = this.onWidevineEnabledChange_.bind(this)
this.restartBrowser_ = this.restartBrowser_.bind(this)
this.onTorEnabledChange_ = this.onTorEnabledChange_.bind(this)

this.addWebUIListener('brave-needs-restart-changed', (needsRestart) => {
this.showRestartToast_ = needsRestart
Expand All @@ -73,9 +63,6 @@ Polymer({
this.browserProxy_.getRestartNeeded().then(show => {
this.showRestartToast_ = show;
});
this.browserProxy_.isTorManaged().then(managed => {
this.disableTorOption_ = managed
})
this.browserProxy_.getDecentralizedDnsResolveMethodList().then(list => {
this.unstoppableDomainsResolveMethod_ = list
})
Expand All @@ -85,10 +72,6 @@ Polymer({

// PrefControlMixin checks for a pref being valid, so have to fake it,
// same as upstream.
const setTorEnabledPref = (enabled) => this.setTorEnabledPref_(enabled);
this.addWebUIListener('tor-enabled-changed', setTorEnabledPref);
this.browserProxy_.isTorEnabled().then(setTorEnabledPref);

const setWidevineEnabledPref = (enabled) => this.setWidevineEnabledPref_(enabled);
this.addWebUIListener('widevine-enabled-changed', setWidevineEnabledPref);
this.browserProxy_.isWidevineEnabled().then(setWidevineEnabledPref);
Expand All @@ -107,19 +90,6 @@ Polymer({
window.open("chrome://restart", "_self");
},

setTorEnabledPref_: function (enabled) {
const pref = {
key: '',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: enabled,
};
this.torEnabledPref_ = pref;
},

onTorEnabledChange_: function() {
this.browserProxy_.setTorEnabled(this.$.torEnabled.checked);
},

setWidevineEnabledPref_: function (enabled) {
const pref = {
key: '',
Expand Down
Loading