Skip to content

Commit 1db6b1f

Browse files
authored
Install/uninstall brave vpn wireguard service (#18565)
1 parent 54fbf11 commit 1db6b1f

File tree

13 files changed

+229
-21
lines changed

13 files changed

+229
-21
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ node_modules/
1616
patches/**/*.patchinfo
1717
/third_party/android_deps/libs/com_google_android_play_core/core-1.10.0.aar
1818
/third_party/argon2/src
19+
/third_party/brave-vpn-wireguard-nt-dlls/
20+
/third_party/brave-vpn-wireguard-tunnel-dlls/
1921
/third_party/bip39wally-core-native/
2022
/third_party/ethash/src
2123
/third_party/bitcoin-core/src

DEPS

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ hooks = [
6767
'condition': 'checkout_mac and download_prebuilt_sparkle',
6868
'action': ['vpython3', 'build/mac/download_sparkle.py', '1.24.3'],
6969
},
70+
{
71+
'name': 'wireguard_nt',
72+
'pattern': '.',
73+
'condition': 'checkout_win',
74+
'action': ['vpython3', 'build/win/download_brave_vpn_wireguard_binaries.py', '0.10.1', 'brave-vpn-wireguard-nt-dlls'],
75+
},
76+
{
77+
'name': 'wireguard_tunnel',
78+
'pattern': '.',
79+
'condition': 'checkout_win',
80+
'action': ['vpython3', 'build/win/download_brave_vpn_wireguard_binaries.py', 'v0.5.3', 'brave-vpn-wireguard-tunnel-dlls'],
81+
},
7082
{
7183
'name': 'download_rust_deps',
7284
'pattern': '.',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env vpython3
2+
3+
# Copyright (c) 2023 The Brave Authors. All rights reserved.
4+
# This Source Code Form is subject to the terms of the Mozilla Public
5+
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
6+
# You can obtain one at https://mozilla.org/MPL/2.0/.
7+
8+
import argparse
9+
import os
10+
11+
from deps_config import DEPS_PACKAGES_URL
12+
import deps
13+
14+
15+
def get_download_url(version, library):
16+
return DEPS_PACKAGES_URL + \
17+
'/brave-vpn-wireguard-dlls/' + library + '-' + \
18+
version + '.zip'
19+
20+
21+
def get_library_path(library):
22+
return os.path.join(os.getcwd(), *['third_party', library])
23+
24+
25+
def get_library_revision_path(library):
26+
return os.path.join(get_library_path(library), '.revision')
27+
28+
29+
def main():
30+
args = parse_args()
31+
if args.revision != get_current_revision(args.library):
32+
url = get_download_url(args.revision, args.library)
33+
target_path = get_library_path(args.library)
34+
print('url:{} to {}'.format(url, target_path))
35+
deps.DownloadAndUnpack(url, target_path)
36+
set_current_revision(args.revision, args.library)
37+
38+
39+
def parse_args():
40+
parser = argparse.ArgumentParser(description='Download Wireguard binaries.')
41+
parser.add_argument('revision')
42+
parser.add_argument('library')
43+
return parser.parse_args()
44+
45+
46+
def get_current_revision(library):
47+
try:
48+
with open(get_library_revision_path(library)) as f:
49+
return f.read()
50+
except FileNotFoundError:
51+
return None
52+
53+
54+
def set_current_revision(value, library):
55+
with open(get_library_revision_path(library), 'w') as f:
56+
f.write(value)
57+
58+
59+
if __name__ == '__main__':
60+
main()

chromium_src/chrome/installer/DEPS

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include_rules = [
22
"+brave/components/brave_vpn/browser/connection/ikev2/win",
3+
"+brave/components/brave_vpn/browser/connection/wireguard/win",
34
"+brave/components/brave_vpn/common/buildflags",
45
"+brave/installer",
56
"+chrome/common",

chromium_src/chrome/installer/setup/install_worker.cc

+31-8
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,32 @@
3232
#if BUILDFLAG(ENABLE_BRAVE_VPN)
3333
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_constants.h"
3434
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_state.h"
35+
#include "brave/components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service/service_constants.h"
3536

3637
namespace {
3738

38-
base::FilePath GetBraveVPNServicePath(const base::FilePath& target_path,
39-
const base::Version& version) {
39+
// All BraveVpn services have support of "install" switch to make registration.
40+
constexpr char kBraveVpnServiceInstall[] = "install";
41+
42+
base::FilePath GetBraveVPNHelperPath(const base::FilePath& target_path,
43+
const base::Version& version) {
4044
return target_path.AppendASCII(version.GetString())
4145
.Append(brave_vpn::kBraveVPNHelperExecutable);
4246
}
4347

44-
bool ConfigureBraveVPNServiceAutoRestart(const base::FilePath& exe_path,
45-
const CallbackWorkItem&) {
48+
bool InstallBraveVPNService(const base::FilePath& exe_path,
49+
const CallbackWorkItem&) {
4650
if (!base::PathExists(exe_path)) {
4751
return false;
4852
}
4953
base::CommandLine cmd(exe_path);
50-
cmd.AppendSwitch(brave_vpn::kBraveVpnHelperInstall);
54+
cmd.AppendSwitch(kBraveVpnServiceInstall);
5155
base::LaunchOptions options = base::LaunchOptions();
5256
options.wait = true;
5357
return base::LaunchProcess(cmd, base::LaunchOptions()).IsValid();
5458
}
5559

56-
// Adds work items to register the Vpn Service with Windows. Only for
60+
// Adds work items to register brave vpn helper service for Windows. Only for
5761
// system level installs.
5862
void AddBraveVPNHelperServiceWorkItems(const base::FilePath& vpn_service_path,
5963
WorkItemList* list) {
@@ -72,14 +76,33 @@ void AddBraveVPNHelperServiceWorkItems(const base::FilePath& vpn_service_path,
7276
install_service_work_item->set_best_effort(true);
7377
list->AddWorkItem(install_service_work_item);
7478
list->AddCallbackWorkItem(
75-
base::BindOnce(&ConfigureBraveVPNServiceAutoRestart, vpn_service_path),
79+
base::BindOnce(&InstallBraveVPNService, vpn_service_path),
80+
base::NullCallback());
81+
}
82+
83+
// Adds work items to register brave vpn wireguard service for Windows. Only for
84+
// system level installs.
85+
void AddBraveVPNWireguardServiceWorkItems(
86+
const base::FilePath& wireguard_service_path,
87+
WorkItemList* list) {
88+
DCHECK(::IsUserAnAdmin());
89+
if (wireguard_service_path.empty()) {
90+
VLOG(1) << "The path to brave_vpn_wireguard_service.exe is invalid.";
91+
return;
92+
}
93+
list->AddCallbackWorkItem(
94+
base::BindOnce(&InstallBraveVPNService, wireguard_service_path),
7695
base::NullCallback());
7796
}
7897

7998
} // namespace
8099

81100
#define GetElevationServicePath GetElevationServicePath(target_path, new_version), install_list); \
82-
AddBraveVPNHelperServiceWorkItems(GetBraveVPNServicePath
101+
AddBraveVPNWireguardServiceWorkItems( \
102+
brave_vpn::GetBraveVPNWireguardServiceInstallationPath(target_path, \
103+
new_version), \
104+
install_list); \
105+
AddBraveVPNHelperServiceWorkItems(GetBraveVPNHelperPath
83106
#endif // BUILDFLAG(ENABLE_BRAVE_VPN)
84107
#include "src/chrome/installer/setup/install_worker.cc"
85108
#if BUILDFLAG(ENABLE_BRAVE_VPN)

chromium_src/chrome/installer/setup/sources.gni

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (is_win) {
1717
brave_chromium_src_chrome_installer_setup_deps += [
1818
"//brave/components/brave_vpn/browser/connection/ikev2/win:ras_utils",
1919
"//brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper:common",
20+
"//brave/components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service:common",
2021
]
2122
}
2223
if (is_official_build) {

chromium_src/chrome/installer/setup/uninstall.cc

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_constants.h"
1010
#include "brave/components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/brave_vpn_helper_state.h"
1111
#include "brave/components/brave_vpn/browser/connection/ikev2/win/ras_utils.h"
12+
#include "brave/components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service/service_constants.h"
1213
#endif
1314
#define UninstallProduct UninstallProduct_ChromiumImpl
1415

@@ -72,6 +73,13 @@ InstallStatus UninstallProduct(const ModifyParams& modify_params,
7273
LOG(WARNING) << "Failed to delete "
7374
<< brave_vpn::GetBraveVpnHelperServiceName();
7475
}
76+
if (!InstallServiceWorkItem::DeleteService(
77+
brave_vpn::GetBraveVpnWireguardServiceName(),
78+
brave_vpn::GetBraveVpnWireguardServiceRegistryStoragePath(), {},
79+
{})) {
80+
LOG(WARNING) << "Failed to delete "
81+
<< brave_vpn::GetBraveVpnWireguardServiceName();
82+
}
7583
}
7684
brave_vpn::ras::RemoveEntry(brave_vpn::GetBraveVPNConnectionName());
7785
#endif

components/brave_vpn/browser/connection/ikev2/win/brave_vpn_helper/BUILD.gn

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ source_set("common") {
2424
"brave_vpn_helper_state.h",
2525
]
2626

27-
public_deps = [ "//brave/components/brave_vpn/common/buildflags" ]
28-
2927
deps = [
3028
"//base",
3129
"//brave/components/brave_vpn/browser/connection/common/win",
3230
"//brave/components/brave_vpn/common",
31+
"//brave/components/brave_vpn/common/buildflags",
3332
"//chrome/install_static:install_static_util",
3433
]
3534
}

components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service/BUILD.gn

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import("//chrome/process_version_rc_template.gni")
1010

1111
assert(is_win)
1212

13+
copy("brave_vpn_wireguard_binaries") {
14+
sources = [
15+
"//brave/third_party/brave-vpn-wireguard-nt-dlls/${target_cpu}/wireguard.dll",
16+
"//brave/third_party/brave-vpn-wireguard-tunnel-dlls/${target_cpu}/tunnel.dll",
17+
]
18+
outputs = [ "$root_out_dir/{{source_file_part}}" ]
19+
}
20+
1321
midl("brave_wireguard_manager_idl") {
1422
sources = [ "brave_wireguard_manager_idl.idl" ]
1523

@@ -21,7 +29,7 @@ source_set("common") {
2129
"service_constants.cc",
2230
"service_constants.h",
2331
]
24-
32+
public_deps = [ "//brave/components/brave_vpn/common/buildflags" ]
2533
deps = [
2634
"//base",
2735
"//chrome/install_static:install_static_util",
@@ -45,6 +53,7 @@ executable("brave_vpn_wireguard_service") {
4553
]
4654

4755
deps = [
56+
":brave_vpn_wireguard_binaries",
4857
":common",
4958
":version_resources",
5059
"//base",

components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service/service_constants.cc

+88-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,85 @@
88
#include <guiddef.h>
99

1010
#include "base/containers/cxx20_erase.h"
11+
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
12+
#include "build/build_config.h"
1113
#include "chrome/install_static/install_util.h"
1214

1315
namespace brave_vpn {
1416

1517
namespace {
18+
// Registry path to Wireguard vpn service storage.
19+
constexpr wchar_t kBraveVpnWireguardServiceRegistryStoragePath[] =
20+
L"Software\\BraveSoftware\\Vpn\\";
21+
22+
// The service installed to %(VersionDir)s\BraveVpnWireguardService
23+
constexpr wchar_t kBraveVpnWireguardServiceSubFolder[] =
24+
L"BraveVpnWireguardService";
25+
26+
#if BUILDFLAG(CHANNEL_NIGHTLY)
27+
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
28+
L"BraveVpnNightlyWireguardTunnelService";
29+
// 8C2EE50E-9130-4B30-84C1-34753BF26E1B
30+
constexpr IID kBraveWireguardServiceIID = {
31+
0x8c2ee50e,
32+
0x9130,
33+
0x4b30,
34+
{0x84, 0xc1, 0x34, 0x75, 0x3b, 0xf2, 0x6e, 0x18}};
35+
// A8D57D90-7A29-4405-91D7-A712F347E426
36+
constexpr CLSID kBraveWireguardServiceCLSID = {
37+
0xa8d57d90,
38+
0x7a29,
39+
0x4405,
40+
{0x91, 0xd7, 0xa7, 0x12, 0xf3, 0x47, 0xe4, 0x26}};
41+
#elif BUILDFLAG(CHANNEL_BETA)
42+
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
43+
L"BraveVpnBetaWireguardTunnelService";
44+
// FB4C65B6-98B4-426B-8B11-5DB735526A84
45+
constexpr IID kBraveWireguardServiceIID = {
46+
0xfb4c65b6,
47+
0x98b4,
48+
0x426b,
49+
{0x8b, 0x11, 0x5d, 0xb7, 0x35, 0x52, 0x6a, 0x84}};
50+
// 93175676-5FAC-4D73-B1E1-5485003C9427
51+
constexpr CLSID kBraveWireguardServiceCLSID = {
52+
0x93175676,
53+
0x5fac,
54+
0x4d73,
55+
{0xb1, 0xe1, 0x54, 0x85, 0x00, 0x3c, 0x94, 0x27}};
56+
#elif BUILDFLAG(CHANNEL_DEV)
57+
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
58+
L"BraveVpnDevWireguardTunnelService";
59+
// E278A30A-CA8C-4885-A468-67741705A518
60+
constexpr IID kBraveWireguardServiceIID = {
61+
0xe278a30a,
62+
0xca8c,
63+
0x4885,
64+
{0xa4, 0x68, 0x67, 0x74, 0x17, 0x05, 0xa5, 0x18}};
65+
// 52C95DE1-D7D9-4C03-A275-8A4517AFAE08
66+
constexpr CLSID kBraveWireguardServiceCLSID = {
67+
0x52c95de1,
68+
0xd7d9,
69+
0x4c03,
70+
{0xa2, 0x75, 0x8a, 0x45, 0x17, 0xaf, 0xae, 0x08}};
71+
#elif BUILDFLAG(CHANNEL_DEVELOPMENT)
72+
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
73+
L"BraveVpnDevelopmentWireguardTunnelService";
74+
// 048EC63C-E2F2-4288-BEA0-DB58AD9CC20E
75+
constexpr IID kBraveWireguardServiceIID = {
76+
0x048ec63c,
77+
0xe2f2,
78+
0x4288,
79+
{0xbe, 0xa0, 0xd8, 0x58, 0xad, 0x9c, 0xc2, 0x0e}};
80+
// 57B73EDD-CBE4-46CA-8ACB-11D90840AF6E
81+
constexpr CLSID kBraveWireguardServiceCLSID = {
82+
0x57b73edd,
83+
0xcbe4,
84+
0x46ca,
85+
{0x8a, 0xcb, 0x11, 0xd9, 0x08, 0x40, 0xaf, 0x6e}};
86+
#else
87+
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
88+
L"BraveVpnWireguardTunnelService";
89+
1690
// 053057AB-CF06-4E6C-BBAD-F8DA6436D933
1791
constexpr IID kBraveWireguardServiceIID = {
1892
0x053057ab,
@@ -25,12 +99,15 @@ constexpr CLSID kBraveWireguardServiceCLSID = {
2599
0xb213,
26100
0x4a8e,
27101
{0x98, 0xad, 0x9d, 0x64, 0xd8, 0x91, 0x39, 0x68}};
28-
29-
constexpr wchar_t kBraveWireguardTunnelServiceName[] =
30-
L"BraveWireGuardTunnelService";
102+
#endif
31103

32104
} // namespace
33105

106+
std::wstring GetBraveVpnWireguardServiceRegistryStoragePath() {
107+
return kBraveVpnWireguardServiceRegistryStoragePath +
108+
GetBraveVpnWireguardServiceName();
109+
}
110+
34111
// Returns the Brave Vpn Service CLSID, IID, Name, and Display Name
35112
// respectively.
36113
const CLSID& GetBraveVpnWireguardServiceClsid() {
@@ -56,4 +133,12 @@ std::wstring GetBraveVpnWireguardServiceName() {
56133
std::wstring GetBraveVpnWireguardTunnelServiceName() {
57134
return kBraveWireguardTunnelServiceName;
58135
}
136+
137+
base::FilePath GetBraveVPNWireguardServiceInstallationPath(
138+
const base::FilePath& target_path,
139+
const base::Version& version) {
140+
return target_path.AppendASCII(version.GetString())
141+
.Append(brave_vpn::kBraveVpnWireguardServiceSubFolder)
142+
.Append(brave_vpn::kBraveVpnWireguardServiceExecutable);
143+
}
59144
} // namespace brave_vpn

components/brave_vpn/browser/connection/wireguard/win/brave_vpn_wireguard_service/service_constants.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#include <guiddef.h>
1010
#include <string>
1111

12+
#include "base/files/file_path.h"
13+
#include "base/version.h"
14+
1215
namespace brave_vpn {
16+
1317
constexpr wchar_t kBraveVpnWireguardServiceExecutable[] =
1418
L"brave_vpn_wireguard_service.exe";
15-
constexpr wchar_t kBraveVpnWireguardServiceRegistryStoragePath[] =
16-
L"Software\\BraveSoftware\\Brave\\Vpn\\BraveWireguardService";
1719
constexpr char kBraveVpnWireguardServiceInstallSwitchName[] = "install";
1820
constexpr char kBraveVpnWireguardServiceConnectSwitchName[] = "connect";
1921

@@ -22,7 +24,10 @@ const IID& GetBraveVpnWireguardServiceIid();
2224
std::wstring GetBraveVpnWireguardTunnelServiceName();
2325
std::wstring GetBraveVpnWireguardServiceName();
2426
std::wstring GetBraveVpnWireguardServiceDisplayName();
25-
27+
std::wstring GetBraveVpnWireguardServiceRegistryStoragePath();
28+
base::FilePath GetBraveVPNWireguardServiceInstallationPath(
29+
const base::FilePath& target_path,
30+
const base::Version& version);
2631
} // namespace brave_vpn
2732

2833
#endif // BRAVE_COMPONENTS_BRAVE_VPN_BROWSER_CONNECTION_WIREGUARD_WIN_BRAVE_VPN_WIREGUARD_SERVICE_SERVICE_CONSTANTS_H_

0 commit comments

Comments
 (0)