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

Update WireGuard COM interface to pass params instead of config #24261

Merged
merged 8 commits into from
Jun 28, 2024

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Jun 18, 2024

Fixes brave/brave-browser#37960

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used GitHub auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

See brave/brave-browser#37960

@bsclifton bsclifton self-assigned this Jun 18, 2024
@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch from 13997db to 7dc2e0a Compare June 18, 2024 21:43
@bsclifton bsclifton requested a review from thypon June 18, 2024 21:51
@bsclifton bsclifton changed the title WIP: Update WireGuard COM interface to pass params instead of config Update WireGuard COM interface to pass params instead of config Jun 18, 2024
Copy link
Member

@diracdeltas diracdeltas left a comment

Choose a reason for hiding this comment

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

@bsclifton bsclifton requested a review from a team as a code owner June 20, 2024 22:12
@diracdeltas diracdeltas self-requested a review June 20, 2024 22:29
@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch 2 times, most recently from 7c6191c to e8355eb Compare June 21, 2024 01:56
@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch from e8355eb to 5d347ea Compare June 21, 2024 16:09
address && wcslen(address) == 0 &&
endpoint && wcslen(endpoint) == 0;
if (reconnect_using_last_config) {
*last_error = !brave_vpn::wireguard::LaunchWireguardService(L"");
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we expect this to happen under some circumstances or are we trying to handle an unexpected condition here? If it's the latter I think we should just fail here because we might be unintentionally opening another attack vector

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the current behavior - I thought I made comments in this PR explaining... but basically the tray program is passing empty string for the arguments. This triggers the "reconnect using the last known config" logic.

We could rework the tray program - but that's a bigger change of course.

Copy link
Member

Choose a reason for hiding this comment

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

I think, best is to harden this part with the follow-up in brave/brave-browser#39229

@bsclifton bsclifton added the CI/skip-macos-arm64 Do not run CI builds for macOS arm64 label Jun 25, 2024
@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch 5 times, most recently from c19cd52 to 01d22c2 Compare June 25, 2024 20:12
@bsclifton
Copy link
Member Author

bsclifton commented Jun 25, 2024

Issue solved - build works locally 🎉

Investigating the COM interface defined here:

There is already a separate CLSID per-channel (Release, Beta, Nightly, etc):

// 053057AB-CF06-4E6C-BBAD-F8DA6436D933
constexpr IID kBraveWireguardServiceIID = {
0x053057ab,
0xcf06,
0x4e6c,
{0xbb, 0xad, 0xf8, 0xda, 0x64, 0x36, 0xd9, 0x33}};

The next step I'm looking at now is making a per-channel IID (interface ID). We could then update the code to return the correct IID per channel here:

const IID& GetBraveVpnWireguardServiceIid() {
return kBraveWireguardServiceIID;
}

And then the IDL can be rebuilt. Basically, if this gets installed, the IID registration (where # of arguments changes) will break other channels trying to use VPN on the machine. If this was merged and installed for Nightly, Release channel VPN would stop working properly for Windows folks because the COM interface changed.

@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch from 06867b9 to b58bef9 Compare June 26, 2024 21:15
bsclifton and others added 6 commits June 26, 2024 16:02
Includes per-field validation for all fields

NOTE: this updates the COM IID to avoid breakage for other channels

Fixes brave/brave-browser#37960
- Moved wchar_t => std::string to the Windows specific file
- Utils methods now all work with std::string
- Additional IP address checks
- Validation methods now return `std::optional<std::string>`
Code has been tested with PR builder on Windows.
@bsclifton bsclifton force-pushed the bsc-wireguard-com-interface branch from b58bef9 to 755f596 Compare June 26, 2024 23:02
@bsclifton bsclifton removed CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-ios Do not run CI builds for iOS CI/skip-macos-arm64 Do not run CI builds for macOS arm64 labels Jun 26, 2024
@bsclifton
Copy link
Member Author

OK made some changes and verified it works with latest PR builder.
Rebased and squashed those changes.
Also removed the SKIP labels so this can run on all platforms

@bsclifton
Copy link
Member Author

Tested and this works great 😄

Copy link
Member

@thypon thypon left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

[puLL-Merge] - brave/brave-core@24261

Description

This PR updates the Brave VPN WireGuard service implementation, particularly focusing on improving security and input validation. The changes include modifying the interface for enabling VPN connections, adding input validation for WireGuard configuration parameters, and updating the COM interface identifier.

Possible Issues

  1. The change in the COM interface identifier (from 053057AB-CF06-4E6C-BBAD-F8DA6436D933 to 6D319801-690B-441E-8C94-5C18D8E7E9D7) may cause compatibility issues with existing clients that use the old interface.

  2. The new input validation logic might potentially reject some previously valid inputs, which could lead to connection failures for some users until they update their configuration.

Security Hotspots

  1. The EnableVpn function now takes individual parameters instead of a single config string, which allows for better input validation. However, ensure that all callers of this function are updated to provide the correct parameters.

  2. The new validation functions (ValidateKey, ValidateAddress, ValidateEndpoint) improve security by checking inputs, but their implementation should be carefully reviewed to ensure they don't introduce new vulnerabilities.

  3. The WireguardGenerateKeypair function now uses SysAllocString to allocate memory for keys. Ensure that this memory is properly freed to prevent memory leaks.

Changes

Changes

  1. brave_wireguard_manager.cc:

    • Updated EnableVpn to take separate parameters instead of a single config string.
    • Added input validation for public key, private key, address, and endpoint.
    • Improved error handling and logging.
    • Updated GenerateKeypair to use SysAllocString for key allocation.
  2. brave_wireguard_manager.h:

    • Updated EnableVpn method signature to match the new implementation.
  3. wireguard_service_runner.cc:

    • Added denial of access for guest accounts in the COM security settings.
  4. status_tray_runner.cc:

    • Updated ConnectVPN to use empty strings for reconnection using last known good config.
  5. service_details.cc:

    • Updated the COM interface identifier.
  6. wireguard_connection_api_impl_win.cc:

    • Updated PlatformConnectImpl to use the new EnableVpn interface.
  7. wireguard_utils_win.cc and wireguard_utils_win.h:

    • Updated EnableBraveVpnWireguardService to take separate parameters.
    • Improved error handling and logging.
  8. wireguard_utils.cc and wireguard_utils.h:

    • Added new validation functions: ValidateKey, ValidateAddress, and ValidateEndpoint.
    • Updated GenerateNewX25519Keypair implementation.
  9. Added new unit tests in wireguard_utils_unittest.cc for the new validation functions.

  10. Updated various MIDL-generated files to reflect the changes in the COM interface.

These changes significantly improve the security and robustness of the Brave VPN WireGuard implementation by adding thorough input validation and improving error handling.

Important to have a default value as methods will only set
(using GetLastError) if an error occurs.
@bsclifton bsclifton enabled auto-merge June 27, 2024 23:08
@bsclifton bsclifton merged commit 13fa3a2 into master Jun 28, 2024
19 checks passed
@bsclifton bsclifton deleted the bsc-wireguard-com-interface branch June 28, 2024 01:11
@github-actions github-actions bot added this to the 1.69.x - Nightly milestone Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[hackerone] Harden the connect method for WireGuard tunnel service
5 participants