Skip to content

Remove VPN services; only install after customer purchases (uplift to 1.63.x) #21680

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

Closed
Closed
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ VERSION text eol=lf
# These files should have CRLF
win_build_output/midl/brave/**/*.c text eol=crlf
win_build_output/midl/brave/**/*.h text eol=crlf
win_build_output/midl/chrome/**/*.c text eol=crlf
win_build_output/midl/chrome/**/*.h text eol=crlf


win_build_output/midl/google_update/*/*.c text eol=crlf
Expand Down
21 changes: 20 additions & 1 deletion browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@
#endif

#if BUILDFLAG(ENABLE_BRAVE_VPN)
#include "brave/browser/brave_vpn/vpn_utils.h"
#include "brave/components/brave_vpn/browser/connection/brave_vpn_os_connection_api.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#if BUILDFLAG(IS_WIN)
#include "brave/browser/brave_vpn/win/vpn_utils_win.h"
#endif
#endif

using brave_component_updater::BraveComponent;
Expand Down Expand Up @@ -505,8 +510,22 @@ BraveBrowserProcessImpl::brave_vpn_os_connection_api() {
return brave_vpn_os_connection_api_.get();
}

// Currently, service installer only used on Windows.
// Installs registers IKEv2 service (for DNS) and our WireGuard impl.
// NOTE: Install only happens if person has purchased the product.
auto service_installer =
#if BUILDFLAG(IS_WIN)
base::BindRepeating(&brave_vpn::InstallVpnSystemServices);
#else
base::NullCallback();
#endif

brave_vpn_os_connection_api_ = brave_vpn::CreateBraveVPNConnectionAPI(
shared_url_loader_factory(), local_state(), chrome::GetChannel());
shared_url_loader_factory(), local_state(), service_installer);
if (brave_vpn_os_connection_api_) {
brave_vpn_os_connection_api_->set_target_vpn_entry_name(
brave_vpn::GetBraveVPNEntryName(chrome::GetChannel()));
}
return brave_vpn_os_connection_api_.get();
}
#endif
Expand Down
25 changes: 25 additions & 0 deletions browser/brave_vpn/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

import("//brave/components/brave_vpn/common/buildflags/buildflags.gni")

assert(enable_brave_vpn)

source_set("brave_vpn") {
sources = [
"vpn_utils.cc",
"vpn_utils.h",
]

deps = [
"//brave/browser/profiles",
"//brave/components/brave_vpn/browser/connection:api",
"//brave/components/brave_vpn/common",
"//brave/components/brave_vpn/common/buildflags",
"//components/prefs",
"//components/user_prefs",
"//services/network/public/cpp",
]
}
2 changes: 2 additions & 0 deletions browser/brave_vpn/brave_vpn_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#if BUILDFLAG(IS_WIN)
#include "brave/browser/brave_vpn/dns/brave_vpn_dns_observer_factory_win.h"
#include "brave/browser/brave_vpn/dns/brave_vpn_dns_observer_service_win.h"
#include "brave/browser/brave_vpn/win/brave_vpn_service_delegate_win.h"
#include "brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_factory_win.h"
#include "brave/browser/brave_vpn/win/brave_vpn_wireguard_observer_service_win.h"
#endif
Expand Down Expand Up @@ -65,6 +66,7 @@ std::unique_ptr<KeyedService> BuildVpnService(
shared_url_loader_factory, local_state,
user_prefs::UserPrefs::Get(context), callback);
#if BUILDFLAG(IS_WIN)
vpn_service->set_delegate(std::make_unique<BraveVPNServiceDelegateWin>());
if (brave_vpn::IsBraveVPNWireguardEnabled(g_browser_process->local_state())) {
auto* observer_service =
brave_vpn::BraveVpnWireguardObserverFactory::GetInstance()
Expand Down
1 change: 0 additions & 1 deletion browser/brave_vpn/dns/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ source_set("unit_tests") {
"//chrome/test:test_support",
"//net",
"//testing/gtest",
"//third_party/abseil-cpp:absl",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#include <vector>

#include "base/strings/string_util.h"
#include "brave/browser/brave_vpn/win/brave_vpn_helper/brave_vpn_helper_utils.h"
#include "brave/browser/ui/views/brave_vpn/brave_vpn_dns_settings_notificiation_dialog_view.h"
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_constants.h"
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_state.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#include "brave/components/brave_vpn/common/pref_names.h"
#include "brave/components/brave_vpn/common/win/utils.h"
Expand Down
11 changes: 6 additions & 5 deletions browser/brave_vpn/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ if (enable_brave_vpn) {
brave_browser_brave_vpn_sources += [
"//brave/browser/brave_vpn/brave_vpn_service_factory.cc",
"//brave/browser/brave_vpn/brave_vpn_service_factory.h",
"//brave/browser/brave_vpn/vpn_utils.cc",
"//brave/browser/brave_vpn/vpn_utils.h",
]

if (is_win) {
brave_browser_brave_vpn_sources += [
"//brave/browser/brave_vpn/dns/brave_vpn_dns_observer_factory_win.cc",
Expand All @@ -30,17 +29,19 @@ if (enable_brave_vpn) {
brave_browser_brave_vpn_deps += [
"//brave/app:brave_generated_resources_grit",
"//brave/browser:browser_process",
"//brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper:common",
"//brave/browser/brave_vpn/win",
"//brave/browser/brave_vpn/win:wireguard_utils",
"//brave/browser/brave_vpn/win/brave_vpn_helper:common",
"//brave/components/brave_vpn/common/win",
"//brave/components/brave_vpn/common/wireguard/win",
"//chrome/common:constants",
"//components/prefs",
"//net",
"//third_party/abseil-cpp:absl",
]
}

brave_browser_brave_vpn_deps += [
"//base",
"//brave/browser/brave_vpn",
"//brave/components/brave_vpn/browser",
"//chrome/browser/profiles:profile",
"//components/keyed_service/content",
Expand Down
37 changes: 37 additions & 0 deletions browser/brave_vpn/vpn_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,49 @@
#include "brave/browser/brave_vpn/vpn_utils.h"

#include "brave/browser/profiles/profile_util.h"
#include "brave/components/brave_vpn/browser/connection/brave_vpn_os_connection_api.h"
#include "brave/components/brave_vpn/common/brave_vpn_utils.h"
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
#include "build/build_config.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

namespace brave_vpn {

// Defined in each platform's connection api.
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNIKEv2ConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs,
base::RepeatingCallback<bool()> service_installer);

#if BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD)
// Defined in each platform's connection api.
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNWireguardConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs,
base::RepeatingCallback<bool()> service_installer);
#endif

std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs,
base::RepeatingCallback<bool()> service_installer) {
#if BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD)
if (IsBraveVPNWireguardEnabled(local_prefs)) {
return CreateBraveVPNWireguardConnectionAPI(url_loader_factory, local_prefs,
service_installer);
}
#endif
#if BUILDFLAG(IS_ANDROID)
// Android doesn't use connection api.
return nullptr;
#else
return CreateBraveVPNIKEv2ConnectionAPI(url_loader_factory, local_prefs,
service_installer);
#endif
}

bool IsAllowedForContext(content::BrowserContext* context) {
return brave::IsRegularProfile(context) &&
brave_vpn::IsBraveVPNFeatureEnabled();
Expand Down
17 changes: 17 additions & 0 deletions browser/brave_vpn/vpn_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@
#ifndef BRAVE_BROWSER_BRAVE_VPN_VPN_UTILS_H_
#define BRAVE_BROWSER_BRAVE_VPN_VPN_UTILS_H_

#include <memory>

#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"

namespace content {
class BrowserContext;
} // namespace content

namespace network {
class SharedURLLoaderFactory;
} // namespace network

class PrefService;

namespace brave_vpn {

class BraveVPNOSConnectionAPI;

bool IsBraveVPNEnabled(content::BrowserContext* context);
bool IsAllowedForContext(content::BrowserContext* context);
std::unique_ptr<BraveVPNOSConnectionAPI> CreateBraveVPNConnectionAPI(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_prefs,
base::RepeatingCallback<bool()> service_installer);

} // namespace brave_vpn

Expand Down
57 changes: 55 additions & 2 deletions browser/brave_vpn/win/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,63 @@ assert(enable_brave_vpn && is_win)

source_set("unit_tests") {
testonly = true
sources = [ "brave_vpn_wireguard_observer_service_win_unittest.cc" ]
sources = [
"brave_vpn_wireguard_observer_service_win_unittest.cc",
"storage_utils_unittest.cc",
]

deps = [
":wireguard_utils",
"//base",
"//chrome/test:test_support",
"//components/version_info:channel",
"//testing/gtest",
"//third_party/abseil-cpp:absl",
]
}

source_set("win") {
sources = [
"brave_vpn_service_delegate_win.cc",
"brave_vpn_service_delegate_win.h",
"brave_vpn_wireguard_connection_api_win.cc",
"brave_vpn_wireguard_connection_api_win.h",
"vpn_utils_win.cc",
"vpn_utils_win.h",
]

deps = [
":wireguard_utils",
"//base",
"//brave/components/brave_vpn/browser",
"//brave/components/brave_vpn/browser/connection/wireguard",
"//brave/components/brave_vpn/browser/connection/wireguard/credentials",
"//brave/components/brave_vpn/common/win",
"//chrome/elevation_service:public_headers",
"//chrome/install_static:install_static_util",
"//components/keyed_service/core",
]
}

source_set("wireguard_utils") {
sources = [
"service_commands.cc",
"service_commands.h",
"service_constants.h",
"service_details.cc",
"service_details.h",
"storage_utils.cc",
"storage_utils.h",
"wireguard_utils_win.cc",
"wireguard_utils_win.h",
]

deps = [
"//base",
"//brave/components/brave_vpn/common/buildflags",
"//brave/components/brave_vpn/common/win",
"//brave/components/brave_vpn/common/wireguard",
"//brave/components/brave_vpn/common/wireguard/win:brave_wireguard_manager_idl",
"//chrome/common:channel_info",
"//components/version_info",
]
}
3 changes: 3 additions & 0 deletions browser/brave_vpn/win/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
'+chrome/elevation_service/elevation_service_idl.h',
]
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ config("no-missing-braces") {
source_set("common") {
sources = [
"brave_vpn_helper_constants.h",
"brave_vpn_helper_state.cc",
"brave_vpn_helper_state.h",
"brave_vpn_helper_utils.cc",
"brave_vpn_helper_utils.h",
]

deps = [
"//base",
"//brave/components/brave_vpn/common",
"//brave/components/brave_vpn/common/buildflags",
"//brave/components/brave_vpn/common/win",
"//chrome/common:channel_info",
"//chrome/install_static:install_static_util",
"//chrome/installer/util:with_no_strings",
"//components/version_info",
]
}

Expand All @@ -49,16 +52,15 @@ source_set("lib") {
deps = [
":common",
"//base",
"//brave/browser/brave_vpn/win:wireguard_utils",
"//brave/components/brave_vpn/browser/connection/ikev2/win:ras_utils",
"//brave/components/brave_vpn/common",
"//brave/components/brave_vpn/common/win",
"//brave/components/brave_vpn/common/wireguard/win",
"//third_party/abseil-cpp:absl",
"//chrome/common:channel_info",
"//components/version_info:channel",
]

libs = [
"Fwpuclnt.lib",
"Iphlpapi.lib",
"fwpuclnt.lib",
"iphlpapi.lib",
"rasapi32.lib",
]
}
Expand All @@ -73,11 +75,11 @@ executable("brave_vpn_helper") {
]

deps = [
":common",
":lib",
":version_resources",
"//base",
"//base:base_static",
"//brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper:common",
"//brave/components/brave_vpn/common",
"//build/win:default_exe_manifest",
"//chrome/install_static:install_static_util",
Expand All @@ -86,9 +88,6 @@ executable("brave_vpn_helper") {
"//components/crash/core/app:run_as_crashpad_handler",
"//components/version_info:channel",
]
libs = [
"userenv.lib", # For GetUserProfileDirectoryW()
]
}

process_version_rc_template("version_resources") {
Expand All @@ -109,6 +108,5 @@ source_set("unit_tests") {
"//brave/components/brave_vpn/browser/connection/ikev2/win:ras_utils",
"//brave/components/brave_vpn/common",
"//testing/gtest",
"//third_party/abseil-cpp:absl",
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_rules = [
"+chrome/installer/util",
"+chrome/install_static"
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_CONNECTION_IKEV2_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_
#define BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_CONNECTION_IKEV2_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_
#ifndef BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_
#define BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_

namespace brave_vpn {

Expand All @@ -15,4 +15,4 @@ class BraveVpnDnsDelegate {

} // namespace brave_vpn

#endif // BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_CONNECTION_IKEV2_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_
#endif // BRAVE_BROWSER_BRAVE_VPN_WIN_BRAVE_VPN_HELPER_BRAVE_VPN_DNS_DELEGATE_H_
Loading