tpm_manager_client.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2020 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 CHROMEOS_DBUS_TPM_MANAGER_TPM_MANAGER_CLIENT_H_
  5. #define CHROMEOS_DBUS_TPM_MANAGER_TPM_MANAGER_CLIENT_H_
  6. #include "base/callback.h"
  7. #include "base/component_export.h"
  8. #include "base/observer_list_types.h"
  9. #include "chromeos/dbus/tpm_manager/tpm_manager.pb.h"
  10. namespace dbus {
  11. class Bus;
  12. }
  13. namespace chromeos {
  14. // TpmManagerClient is used to communicate with the org.chromium.TpmManager
  15. // service. All method should be called from the origin thread (UI thread) which
  16. // initializes the DBusThreadManager instance.
  17. // For more information, please see
  18. // "chromium/src/third_party/cros_system_api/dbus/tpm_manager" for detailed
  19. // definitions of the D-Bus methods and their arguments.
  20. class COMPONENT_EXPORT(CHROMEOS_DBUS_TPM_MANAGER) TpmManagerClient {
  21. public:
  22. class Observer : public base::CheckedObserver {
  23. public:
  24. virtual void OnOwnershipTaken() = 0;
  25. };
  26. public:
  27. // Callbacks of the D-Bus methods.
  28. using GetTpmNonsensitiveStatusCallback = base::OnceCallback<void(
  29. const ::tpm_manager::GetTpmNonsensitiveStatusReply&)>;
  30. using GetVersionInfoCallback =
  31. base::OnceCallback<void(const ::tpm_manager::GetVersionInfoReply&)>;
  32. using GetSupportedFeaturesCallback =
  33. base::OnceCallback<void(const ::tpm_manager::GetSupportedFeaturesReply&)>;
  34. using GetDictionaryAttackInfoCallback = base::OnceCallback<void(
  35. const ::tpm_manager::GetDictionaryAttackInfoReply&)>;
  36. using TakeOwnershipCallback =
  37. base::OnceCallback<void(const ::tpm_manager::TakeOwnershipReply&)>;
  38. using ClearStoredOwnerPasswordCallback = base::OnceCallback<void(
  39. const ::tpm_manager::ClearStoredOwnerPasswordReply&)>;
  40. // Interface with testing functionality. Accessed through GetTestInterface(),
  41. // only implemented in the fake implementation.
  42. class TestInterface {
  43. public:
  44. // Gets a mutable reply that is returned when `GetTpmNonsensitiveStatus()`
  45. // is called.
  46. virtual ::tpm_manager::GetTpmNonsensitiveStatusReply*
  47. mutable_nonsensitive_status_reply() = 0;
  48. // Sets how many times the `GetTpmNonsensitiveStatus()` returns D-Bus error
  49. // before it works normally.
  50. virtual void set_non_nonsensitive_status_dbus_error_count(int count) = 0;
  51. // Gets a mutable reply that is returned when `GetVersionInfo()` is called.
  52. virtual ::tpm_manager::GetVersionInfoReply*
  53. mutable_version_info_reply() = 0;
  54. // Gets a mutable reply that is returned when `GetSupportedFeatures()` is
  55. // called.
  56. virtual ::tpm_manager::GetSupportedFeaturesReply*
  57. mutable_supported_features_reply() = 0;
  58. // Gets a mutable reply that is returned when `GetDictionaryAttackInfo()` is
  59. // called.
  60. virtual ::tpm_manager::GetDictionaryAttackInfoReply*
  61. mutable_dictionary_attack_info_reply() = 0;
  62. // Gets the count of `TakeOwnership()` being called.
  63. virtual int take_ownership_count() const = 0;
  64. // Gets the count of `ClearStoredOwnerPassword()` being called.
  65. virtual int clear_stored_owner_password_count() const = 0;
  66. // Emits ownership taken signal.
  67. virtual void EmitOwnershipTakenSignal() = 0;
  68. };
  69. // Not copyable or movable.
  70. TpmManagerClient(const TpmManagerClient&) = delete;
  71. TpmManagerClient& operator=(const TpmManagerClient&) = delete;
  72. TpmManagerClient(TpmManagerClient&&) = delete;
  73. TpmManagerClient& operator=(TpmManagerClient&&) = delete;
  74. // Creates and initializes the global instance. |bus| must not be null.
  75. static void Initialize(dbus::Bus* bus);
  76. // Creates and initializes a fake global instance if not already created.
  77. static void InitializeFake();
  78. // Destroys the global instance.
  79. static void Shutdown();
  80. // Returns the global instance which may be null if not initialized.
  81. static TpmManagerClient* Get();
  82. // Queries the assorted TPM statuses that tpm manager can tell, e.g., TPM
  83. // ownership status, the presence of the owner password, the capability of
  84. // resetting dictionary attack lockout; for the complete list of the returned
  85. // statuses, see `GetTpmNonsensitiveStatusReply`.
  86. virtual void GetTpmNonsensitiveStatus(
  87. const ::tpm_manager::GetTpmNonsensitiveStatusRequest& request,
  88. GetTpmNonsensitiveStatusCallback callback) = 0;
  89. // Queries the detailed TPM version information; for the complete list of the
  90. // entries, see `GetVersionInfoReply`.
  91. virtual void GetVersionInfo(
  92. const ::tpm_manager::GetVersionInfoRequest& request,
  93. GetVersionInfoCallback callback) = 0;
  94. // Queries the features that TPM supports; for the complete list of the
  95. // entries, see `GetSupportedFeaturesReply`.
  96. virtual void GetSupportedFeatures(
  97. const ::tpm_manager::GetSupportedFeaturesRequest& request,
  98. GetSupportedFeaturesCallback callback) = 0;
  99. // Queries the dictionary lockout information of TPM's dictionary attack
  100. // protection, The reply contains the related information, including the
  101. // current dictionary attack counter, and the flag if the TPM is in the
  102. // lockout state.
  103. virtual void GetDictionaryAttackInfo(
  104. const ::tpm_manager::GetDictionaryAttackInfoRequest& request,
  105. GetDictionaryAttackInfoCallback callback) = 0;
  106. // Triggers TPM initialization process by tpm manager.
  107. virtual void TakeOwnership(const ::tpm_manager::TakeOwnershipRequest& request,
  108. TakeOwnershipCallback callback) = 0;
  109. // Requests tpm manager to attempt to wipe the TPM owner password from its
  110. // on-disk database.
  111. virtual void ClearStoredOwnerPassword(
  112. const ::tpm_manager::ClearStoredOwnerPasswordRequest& request,
  113. ClearStoredOwnerPasswordCallback callback) = 0;
  114. // Adds an observer.
  115. virtual void AddObserver(Observer* observer) = 0;
  116. // Removes an observer.
  117. virtual void RemoveObserver(Observer* observer) = 0;
  118. // Returns an interface for testing (fake only), or returns nullptr.
  119. virtual TestInterface* GetTestInterface() = 0;
  120. protected:
  121. // Initialize/Shutdown should be used instead.
  122. TpmManagerClient();
  123. virtual ~TpmManagerClient();
  124. };
  125. } // namespace chromeos
  126. // TODO(https://crbug.com/1164001): remove after the //chrome/browser/chromeos
  127. // source migration is finished.
  128. namespace ash {
  129. using ::chromeos::TpmManagerClient;
  130. }
  131. #endif // CHROMEOS_DBUS_TPM_MANAGER_TPM_MANAGER_CLIENT_H_