elevator.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROME_ELEVATION_SERVICE_ELEVATOR_H_
  5. #define CHROME_ELEVATION_SERVICE_ELEVATOR_H_
  6. #include <string>
  7. #include <windows.h>
  8. #include <wrl/implements.h>
  9. #include <wrl/module.h>
  10. #include "base/gtest_prod_util.h"
  11. #include "base/win/windows_types.h"
  12. #include "chrome/elevation_service/elevation_service_idl.h"
  13. namespace elevation_service {
  14. constexpr IID kTestElevatorClsid = {
  15. 0x416C51AC,
  16. 0x4DEF,
  17. 0x43CA,
  18. {0xE7, 0x35, 0xE7, 0x35, 0x21, 0x0A, 0xB2,
  19. 0x57}}; // Elevator Test CLSID. {416C51AC-4DEF-43CA-96E8-E735210AB257}
  20. namespace switches {
  21. constexpr char kElevatorClsIdForTestingSwitch[] = "elevator-clsid-for-testing";
  22. } // namespace switches
  23. class Elevator
  24. : public Microsoft::WRL::RuntimeClass<
  25. Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
  26. IElevator,
  27. IElevatorChromium,
  28. IElevatorChrome,
  29. IElevatorChromeBeta,
  30. IElevatorChromeDev,
  31. IElevatorChromeCanary> {
  32. public:
  33. const HRESULT kErrorCouldNotObtainCallingProcess =
  34. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA001);
  35. const HRESULT kErrorCouldNotGenerateValidationData =
  36. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA002);
  37. const HRESULT kErrorCouldNotDecryptWithUserContext =
  38. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA003);
  39. const HRESULT kErrorCouldNotDecryptWithSystemContext =
  40. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA004);
  41. const HRESULT kErrorCouldNotEncryptWithUserContext =
  42. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA005);
  43. const HRESULT kErrorCouldNotEncryptWithSystemContext =
  44. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA006);
  45. const HRESULT kValidationDidNotPass =
  46. MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0xA007);
  47. Elevator() = default;
  48. Elevator(const Elevator&) = delete;
  49. Elevator& operator=(const Elevator&) = delete;
  50. // Securely validates and runs the provided Chrome Recovery CRX elevated, by
  51. // first copying the CRX to a secure directory under %ProgramFiles% to
  52. // validate and unpack the CRX.
  53. IFACEMETHODIMP RunRecoveryCRXElevated(const wchar_t* crx_path,
  54. const wchar_t* browser_appid,
  55. const wchar_t* browser_version,
  56. const wchar_t* session_id,
  57. DWORD caller_proc_id,
  58. ULONG_PTR* proc_handle) override;
  59. IFACEMETHODIMP EncryptData(ProtectionLevel protection_level,
  60. const BSTR plaintext,
  61. BSTR* ciphertext,
  62. DWORD* last_error) override;
  63. IFACEMETHODIMP DecryptData(const BSTR ciphertext,
  64. BSTR* plaintext,
  65. DWORD* last_error) override;
  66. private:
  67. FRIEND_TEST_ALL_PREFIXES(ElevatorTest, StringHandlingTest);
  68. ~Elevator() override = default;
  69. // Appends a string `to_append` to an existing string `base`, first the four
  70. // byte length then the string.
  71. static void AppendStringWithLength(const std::string& to_append,
  72. std::string& base);
  73. // Pulls a string from the start of the string, `str` is shortened to the
  74. // remainder of the string. `str` should have been a string previously passed
  75. // to AppendStringWithLength, so that it contains the four byte prefix of
  76. // length.
  77. static std::string PopFromStringFront(std::string& str);
  78. };
  79. } // namespace elevation_service
  80. #endif // CHROME_ELEVATION_SERVICE_ELEVATOR_H_