Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ HRESULT BraveWireguardManager::EnableVpn(const BSTR public_key,
const BSTR private_key,
const BSTR address,
const BSTR endpoint,
BOOL block_untunneled_traffic,
DWORD* last_error) {
// if all params are empty, reconnect using last known good config.
// browser/brave_vpn/win/brave_vpn_wireguard_service/service/wireguard_tunnel_service.cc
Expand Down Expand Up @@ -81,7 +82,8 @@ HRESULT BraveWireguardManager::EnableVpn(const BSTR public_key,

auto config = brave_vpn::wireguard::CreateWireguardConfig(
validated_private_key.value(), validated_public_key.value(),
validated_endpoint.value(), validated_address.value());
validated_endpoint.value(), validated_address.value(),
block_untunneled_traffic);
if (!config.has_value()) {
VLOG(1) << __func__ << " : failed to get correct credentials";
return E_INVALIDARG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BraveWireguardManager
BSTR private_key,
BSTR address,
BSTR endpoint,
BOOL block_untunneled_traffic,
DWORD* last_error) override;
IFACEMETHODIMP DisableVpn(DWORD* last_error) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void StatusTrayRunner::ConnectVPN() {
// passing empty params will reconnect using last known good config.
// TODO(https://github.com/brave/brave-browser/issues/47115): fetch
// actual server details. See issue for more info.
"", "", "", "", std::nullopt,
"", "", "", "", false, std::nullopt,
base::BindOnce(&StatusTrayRunner::OnConnected,
weak_factory_.GetWeakPtr()));
} else {
Expand Down
3 changes: 2 additions & 1 deletion browser/brave_vpn/win/wireguard_connection_api_impl_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/memory/scoped_refptr.h"
#include "brave/browser/brave_vpn/win/service_details.h"
#include "brave/browser/brave_vpn/win/wireguard_utils_win.h"
#include "brave/components/brave_vpn/browser/connection/brave_vpn_connection_manager.h"
#include "brave/components/brave_vpn/common/brave_vpn_constants.h"
#include "brave/components/brave_vpn/common/win/utils.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ void WireguardConnectionAPIImplWin::PlatformConnectImpl(
brave_vpn::wireguard::EnableBraveVpnWireguardService(
credentials.server_public_key, credentials.client_private_key,
credentials.mapped_ip4_address, vpn_server_hostname,
std::move(smart_proxy_url),
manager_->ShouldBlockUntunneledTraffic(), std::move(smart_proxy_url),
base::BindOnce(&WireguardConnectionAPIImplWin::OnWireguardServiceLaunched,
weak_factory_.GetWeakPtr()));
}
Expand Down
21 changes: 11 additions & 10 deletions browser/brave_vpn/win/wireguard_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ bool IsBraveVPNWireguardTunnelServiceRunning() {
status.value() == SERVICE_START_PENDING;
}

bool EnableBraveVpnWireguardServiceImpl(
const std::string& server_public_key,
const std::string& client_private_key,
const std::string& mapped_ip4_address,
const std::string& vpn_server_hostname) {
bool EnableBraveVpnWireguardServiceImpl(const std::string& server_public_key,
const std::string& client_private_key,
const std::string& mapped_ip4_address,
const std::string& vpn_server_hostname,
const bool block_untunneled_traffic) {
base::win::AssertComInitialized();
MaybeEnableSystemProxy();

Expand Down Expand Up @@ -184,10 +184,10 @@ bool EnableBraveVpnWireguardServiceImpl(
base::UTF8ToWide(vpn_server_hostname));

DWORD last_error = ERROR_SUCCESS;
HRESULT res = service->EnableVpn(server_public_key_data.Get(),
client_private_key_data.Get(),
mapped_ip4_address_data.Get(),
vpn_server_hostname_data.Get(), &last_error);
HRESULT res = service->EnableVpn(
server_public_key_data.Get(), client_private_key_data.Get(),
mapped_ip4_address_data.Get(), vpn_server_hostname_data.Get(),
block_untunneled_traffic, &last_error);

if (!SUCCEEDED(res)) {
VLOG(1) << "Failure calling EnableVpn. Result: "
Expand All @@ -203,6 +203,7 @@ void EnableBraveVpnWireguardService(const std::string& server_public_key,
const std::string& client_private_key,
const std::string& mapped_ip4_address,
const std::string& vpn_server_hostname,
const bool block_untunneled_traffic,
std::optional<std::string> smart_proxy_url,
wireguard::BooleanCallback callback) {
// If all params are empty this is a reconnect (using last known good config).
Expand All @@ -226,7 +227,7 @@ void EnableBraveVpnWireguardService(const std::string& server_public_key,
FROM_HERE,
base::BindOnce(&EnableBraveVpnWireguardServiceImpl, server_public_key,
client_private_key, mapped_ip4_address,
vpn_server_hostname),
vpn_server_hostname, block_untunneled_traffic),
std::move(callback));
}

Expand Down
1 change: 1 addition & 0 deletions browser/brave_vpn/win/wireguard_utils_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void EnableBraveVpnWireguardService(const std::string& server_public_key,
const std::string& client_private_key,
const std::string& mapped_ip4_address,
const std::string& vpn_server_hostname,
const bool block_untunneled_traffic,
std::optional<std::string> smart_proxy_url,
BooleanCallback callback);
void DisableBraveVpnWireguardService(BooleanCallback callback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ void BraveVPNConnectionManager::SetSelectedRegion(const std::string& name) {
}
}

bool BraveVPNConnectionManager::ShouldBlockUntunneledTraffic() {
#if BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD)
return local_prefs_->GetBoolean(
prefs::kBraveVPNWireguardBlockUntunneledTraffic) &&
local_prefs_->GetBoolean(prefs::kBraveVPNWireguardEnabled);
#else
NOTREACHED();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: NOTREACHED() is defined in base/notreached.h, which this file doesn't include (only base/check.h / base/logging.h are). Please add the include rather than relying on a transitive one. (✅ Always Include What You Use (IWYU))

#endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: this new guard spans more than 3 lines and has an #else branch, so per BS-045 the #endif should say what it closes: #endif // BUILDFLAG(ENABLE_BRAVE_VPN_WIREGUARD). (The rest of this file uses bare #endifs, so feel free to skip if you'd rather keep the file uniform.) (Refined Rule: #endif Comments Based on Block Length)

}

std::string BraveVPNConnectionManager::GetHostname() const {
if (connection_api_impl_) {
return connection_api_impl_->GetHostname();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class BraveVPNConnectionManager {
void CheckConnection();

void SetSelectedRegion(const std::string& name);
bool ShouldBlockUntunneledTraffic();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: worth a one-line comment on this new public method — the implementation NOTREACHED()s when ENABLE_BRAVE_VPN_WIREGUARD is off and it also requires kBraveVPNWireguardEnabled, neither of which is obvious from the name. (✅ Method Documentation Should Describe the Contract)


// Returns user friendly error string if existed.
// Otherwise returns empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IBraveVpnWireguardManager : IUnknown
[in] BSTR private_key,
[in] BSTR address,
[in] BSTR endpoint,
[in] BOOL block_untunneled_traffic,
[out] DWORD* last_error);

HRESULT DisableVpn([out] DWORD* last_error);
Expand Down
3 changes: 2 additions & 1 deletion components/brave_vpn/common/wireguard/wireguard_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ std::optional<std::string> CreateWireguardConfig(
const std::string& client_private_key,
const std::string& server_public_key,
const std::string& vpn_server_hostname,
const std::string& mapped_ipv4_address) {
const std::string& mapped_ipv4_address,
const bool block_untunneled_traffic) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

block_untunneled_traffic is added to the signature but never used in the body — the config template still hardcodes AllowedIPs = 0.0.0.0/0, ::/0, so everything plumbed through EnableVpn is dropped here and the flag has no effect. Either consume it (e.g. adjust AllowedIPs) in this PR or drop the parameter until the config change lands.

if (client_private_key.empty() || server_public_key.empty() ||
vpn_server_hostname.empty() || mapped_ipv4_address.empty()) {
return std::nullopt;
Expand Down
3 changes: 2 additions & 1 deletion components/brave_vpn/common/wireguard/wireguard_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ std::optional<std::string> CreateWireguardConfig(
const std::string& client_private_key,
const std::string& server_public_key,
const std::string& vpn_server_hostname,
const std::string& mapped_ipv4_address);
const std::string& mapped_ipv4_address,
const bool block_untunneled_traffic);

WireguardKeyPair GenerateNewX25519Keypair();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
/* [in] */ BSTR private_key,
/* [in] */ BSTR address,
/* [in] */ BSTR endpoint,
/* [in] */ BOOL block_untunneled_traffic,
/* [out] */ DWORD *last_error) = 0;

virtual HRESULT STDMETHODCALLTYPE DisableVpn(
Expand Down Expand Up @@ -132,6 +133,7 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
/* [in] */ BSTR private_key,
/* [in] */ BSTR address,
/* [in] */ BSTR endpoint,
/* [in] */ BOOL block_untunneled_traffic,
/* [out] */ DWORD *last_error);

DECLSPEC_XFGVIRT(IBraveVpnWireguardManager, DisableVpn)
Expand Down Expand Up @@ -162,8 +164,8 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
( (This)->lpVtbl -> Release(This) )


#define IBraveVpnWireguardManager_EnableVpn(This,public_key,private_key,address,endpoint,last_error) \
( (This)->lpVtbl -> EnableVpn(This,public_key,private_key,address,endpoint,last_error) )
#define IBraveVpnWireguardManager_EnableVpn(This,public_key,private_key,address,endpoint,block_untunneled_traffic,last_error) \
( (This)->lpVtbl -> EnableVpn(This,public_key,private_key,address,endpoint,block_untunneled_traffic,last_error) )

#define IBraveVpnWireguardManager_DisableVpn(This,last_error) \
( (This)->lpVtbl -> DisableVpn(This,last_error) )
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "brave_wireguard_manager_idl.h"

#define TYPE_FORMAT_STRING_SIZE 43
#define PROC_FORMAT_STRING_SIZE 113
#define PROC_FORMAT_STRING_SIZE 119
#define EXPR_FORMAT_STRING_SIZE 1
#define TRANSMIT_AS_TABLE_SIZE 0
#define WIRE_MARSHAL_TABLE_SIZE 1
Expand Down Expand Up @@ -164,25 +164,25 @@ static const brave_wireguard_manager_idl_MIDL_PROC_FORMAT_STRING brave_wireguard
0x6c, /* Old Flags: object, Oi2 */
/* 2 */ NdrFcLong( 0x0 ), /* 0 */
/* 6 */ NdrFcShort( 0x3 ), /* 3 */
/* 8 */ NdrFcShort( 0x38 ), /* ARM64 Stack size/offset = 56 */
/* 10 */ NdrFcShort( 0x0 ), /* 0 */
/* 8 */ NdrFcShort( 0x40 ), /* ARM64 Stack size/offset = 64 */
/* 10 */ NdrFcShort( 0x8 ), /* 8 */
/* 12 */ NdrFcShort( 0x24 ), /* 36 */
/* 14 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */
0x6, /* 6 */
0x7, /* 7 */
/* 16 */ 0x12, /* 18 */
0x5, /* Ext Flags: new corr desc, srv corr check, */
/* 18 */ NdrFcShort( 0x0 ), /* 0 */
/* 20 */ NdrFcShort( 0x1 ), /* 1 */
/* 22 */ NdrFcShort( 0x0 ), /* 0 */
/* 24 */ NdrFcShort( 0x6 ), /* 6 */
/* 26 */ 0x6, /* 6 */
/* 24 */ NdrFcShort( 0x7 ), /* 7 */
/* 26 */ 0x7, /* 7 */
0x80, /* 128 */
/* 28 */ 0x81, /* 129 */
0x82, /* 130 */
/* 30 */ 0x83, /* 131 */
0x84, /* 132 */
/* 32 */ 0x85, /* 133 */
0x0, /* 0 */
0x86, /* 134 */

/* Parameter public_key */

Expand All @@ -208,54 +208,61 @@ static const brave_wireguard_manager_idl_MIDL_PROC_FORMAT_STRING brave_wireguard
/* 54 */ NdrFcShort( 0x20 ), /* ARM64 Stack size/offset = 32 */
/* 56 */ NdrFcShort( 0x1c ), /* Type Offset=28 */

/* Parameter last_error */
/* Parameter block_untunneled_traffic */

/* 58 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 58 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 60 */ NdrFcShort( 0x28 ), /* ARM64 Stack size/offset = 40 */
/* 62 */ 0x8, /* FC_LONG */
0x0, /* 0 */

/* Return value */
/* Parameter last_error */

/* 64 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 64 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 66 */ NdrFcShort( 0x30 ), /* ARM64 Stack size/offset = 48 */
/* 68 */ 0x8, /* FC_LONG */
0x0, /* 0 */

/* Return value */

/* 70 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 72 */ NdrFcShort( 0x38 ), /* ARM64 Stack size/offset = 56 */
/* 74 */ 0x8, /* FC_LONG */
0x0, /* 0 */

/* Procedure DisableVpn */

/* 70 */ 0x33, /* FC_AUTO_HANDLE */
/* 76 */ 0x33, /* FC_AUTO_HANDLE */
0x6c, /* Old Flags: object, Oi2 */
/* 72 */ NdrFcLong( 0x0 ), /* 0 */
/* 76 */ NdrFcShort( 0x4 ), /* 4 */
/* 78 */ NdrFcShort( 0x18 ), /* ARM64 Stack size/offset = 24 */
/* 80 */ NdrFcShort( 0x0 ), /* 0 */
/* 82 */ NdrFcShort( 0x24 ), /* 36 */
/* 84 */ 0x44, /* Oi2 Flags: has return, has ext, */
/* 78 */ NdrFcLong( 0x0 ), /* 0 */
/* 82 */ NdrFcShort( 0x4 ), /* 4 */
/* 84 */ NdrFcShort( 0x18 ), /* ARM64 Stack size/offset = 24 */
/* 86 */ NdrFcShort( 0x0 ), /* 0 */
/* 88 */ NdrFcShort( 0x24 ), /* 36 */
/* 90 */ 0x44, /* Oi2 Flags: has return, has ext, */
0x2, /* 2 */
/* 86 */ 0xe, /* 14 */
/* 92 */ 0xe, /* 14 */
0x1, /* Ext Flags: new corr desc, */
/* 88 */ NdrFcShort( 0x0 ), /* 0 */
/* 90 */ NdrFcShort( 0x0 ), /* 0 */
/* 92 */ NdrFcShort( 0x0 ), /* 0 */
/* 94 */ NdrFcShort( 0x2 ), /* 2 */
/* 96 */ 0x2, /* 2 */
/* 94 */ NdrFcShort( 0x0 ), /* 0 */
/* 96 */ NdrFcShort( 0x0 ), /* 0 */
/* 98 */ NdrFcShort( 0x0 ), /* 0 */
/* 100 */ NdrFcShort( 0x2 ), /* 2 */
/* 102 */ 0x2, /* 2 */
0x80, /* 128 */
/* 98 */ 0x81, /* 129 */
/* 104 */ 0x81, /* 129 */
0x0, /* 0 */

/* Parameter last_error */

/* 100 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 102 */ NdrFcShort( 0x8 ), /* ARM64 Stack size/offset = 8 */
/* 104 */ 0x8, /* FC_LONG */
/* 106 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 108 */ NdrFcShort( 0x8 ), /* ARM64 Stack size/offset = 8 */
/* 110 */ 0x8, /* FC_LONG */
0x0, /* 0 */

/* Return value */

/* 106 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 108 */ NdrFcShort( 0x10 ), /* ARM64 Stack size/offset = 16 */
/* 110 */ 0x8, /* FC_LONG */
/* 112 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 114 */ NdrFcShort( 0x10 ), /* ARM64 Stack size/offset = 16 */
/* 116 */ 0x8, /* FC_LONG */
0x0, /* 0 */

0x0
Expand Down Expand Up @@ -333,7 +340,7 @@ static const USER_MARSHAL_ROUTINE_QUADRUPLE UserMarshalRoutines[ WIRE_MARSHAL_TA
static const unsigned short IBraveVpnWireguardManager_FormatStringOffsetTable[] =
{
0,
70
76
};

static const MIDL_STUBLESS_PROXY_INFO IBraveVpnWireguardManager_ProxyInfo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
/* [in] */ BSTR private_key,
/* [in] */ BSTR address,
/* [in] */ BSTR endpoint,
/* [in] */ BOOL block_untunneled_traffic,
/* [out] */ DWORD *last_error) = 0;

virtual HRESULT STDMETHODCALLTYPE DisableVpn(
Expand Down Expand Up @@ -132,6 +133,7 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
/* [in] */ BSTR private_key,
/* [in] */ BSTR address,
/* [in] */ BSTR endpoint,
/* [in] */ BOOL block_untunneled_traffic,
/* [out] */ DWORD *last_error);

DECLSPEC_XFGVIRT(IBraveVpnWireguardManager, DisableVpn)
Expand Down Expand Up @@ -162,8 +164,8 @@ EXTERN_C const IID IID_IBraveVpnWireguardManager;
( (This)->lpVtbl -> Release(This) )


#define IBraveVpnWireguardManager_EnableVpn(This,public_key,private_key,address,endpoint,last_error) \
( (This)->lpVtbl -> EnableVpn(This,public_key,private_key,address,endpoint,last_error) )
#define IBraveVpnWireguardManager_EnableVpn(This,public_key,private_key,address,endpoint,block_untunneled_traffic,last_error) \
( (This)->lpVtbl -> EnableVpn(This,public_key,private_key,address,endpoint,block_untunneled_traffic,last_error) )

#define IBraveVpnWireguardManager_DisableVpn(This,last_error) \
( (This)->lpVtbl -> DisableVpn(This,last_error) )
Expand Down
Binary file not shown.
Loading
Loading