|
28 | 28 | namespace elevation_service {
|
29 | 29 |
|
30 | 30 | HRESULT Elevator::InstallVPNServices() {
|
| 31 | + // Perform a trusted source check. |
| 32 | + // This ensures the caller is an executable in `%PROGRAMFILES%`. |
| 33 | + // For more info, see https://github.com/brave/brave-core/pull/24900 |
| 34 | + HRESULT hr = ::CoImpersonateClient(); |
| 35 | + if (FAILED(hr)) { |
| 36 | + return hr; |
| 37 | + } |
| 38 | + |
| 39 | + { |
| 40 | + absl::Cleanup revert_to_self = [] { ::CoRevertToSelf(); }; |
| 41 | + |
| 42 | + const auto process = GetCallingProcess(); |
| 43 | + if (!process.IsValid()) { |
| 44 | + return kErrorCouldNotObtainCallingProcess; |
| 45 | + } |
| 46 | + const auto validation_data = GenerateValidationData( |
| 47 | + ProtectionLevel::PROTECTION_PATH_VALIDATION, process); |
| 48 | + if (!validation_data.has_value()) { |
| 49 | + return validation_data.error(); |
| 50 | + } |
| 51 | + const auto data = std::vector<uint8_t>(validation_data->cbegin(), |
| 52 | + validation_data->cend()); |
| 53 | + |
| 54 | + // Note: Validation should always be done using caller impersonation token. |
| 55 | + std::string log_message; |
| 56 | + HRESULT validation_result = ValidateData(process, data, &log_message); |
| 57 | + if (FAILED(validation_result)) { |
| 58 | + return validation_result; |
| 59 | + } |
| 60 | + } |
| 61 | + // End of trusted source check |
| 62 | + |
31 | 63 | #if BUILDFLAG(ENABLE_BRAVE_VPN)
|
32 | 64 | if (!brave_vpn::IsBraveVPNHelperServiceInstalled()) {
|
33 | 65 | auto success = brave_vpn::InstallBraveVPNHelperService(
|
|
0 commit comments