trusted_vault_client.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2019 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 COMPONENTS_SYNC_DRIVER_TRUSTED_VAULT_CLIENT_H_
  5. #define COMPONENTS_SYNC_DRIVER_TRUSTED_VAULT_CLIENT_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback_forward.h"
  10. #include "base/observer_list_types.h"
  11. struct CoreAccountInfo;
  12. namespace syncer {
  13. // Interface that allows platform-specific logic related to accessing locally
  14. // available trusted vault encryption keys.
  15. class TrustedVaultClient {
  16. public:
  17. class Observer : public base::CheckedObserver {
  18. public:
  19. Observer() = default;
  20. Observer(const Observer&) = delete;
  21. Observer& operator=(const Observer&) = delete;
  22. ~Observer() override = default;
  23. // Invoked when the keys inside the vault have changed.
  24. virtual void OnTrustedVaultKeysChanged() = 0;
  25. // Invoked when the recoverability of the keys has changed.
  26. virtual void OnTrustedVaultRecoverabilityChanged() = 0;
  27. };
  28. TrustedVaultClient() = default;
  29. TrustedVaultClient(const TrustedVaultClient&) = delete;
  30. TrustedVaultClient& operator=(const TrustedVaultClient&) = delete;
  31. virtual ~TrustedVaultClient() = default;
  32. // Adds/removes an observer.
  33. virtual void AddObserver(Observer* observer) = 0;
  34. virtual void RemoveObserver(Observer* observer) = 0;
  35. // Attempts to fetch decryption keys, required by sync to resume.
  36. // Implementations are expected to NOT prompt the user for actions. |cb| is
  37. // called on completion with known keys or an empty list if none known.
  38. virtual void FetchKeys(
  39. const CoreAccountInfo& account_info,
  40. base::OnceCallback<void(const std::vector<std::vector<uint8_t>>&)>
  41. cb) = 0;
  42. // Invoked when the result of FetchKeys() contains keys that cannot decrypt
  43. // the pending cryptographer (Nigori) keys, which should only be possible if
  44. // the provided keys are not up-to-date. |cb| is run upon completion and
  45. // returns false if the call did not make any difference (e.g. the operation
  46. // is unsupported) or true if some change may have occurred (which indicates a
  47. // second FetchKeys() attempt is worth). During the execution, before |cb| is
  48. // invoked, the behavior is unspecified if FetchKeys() is invoked, that is,
  49. // FetchKeys() may or may not treat existing keys as stale (only guaranteed
  50. // upon completion of MarkLocalKeysAsStale()).
  51. virtual void MarkLocalKeysAsStale(const CoreAccountInfo& account_info,
  52. base::OnceCallback<void(bool)> cb) = 0;
  53. // Allows implementations to store encryption keys fetched by other means such
  54. // as Web interactions. Implementations are free to completely ignore these
  55. // keys, so callers may not assume that later calls to FetchKeys() would
  56. // necessarily return the keys passed here.
  57. virtual void StoreKeys(const std::string& gaia_id,
  58. const std::vector<std::vector<uint8_t>>& keys,
  59. int last_key_version) = 0;
  60. // Returns whether recoverability of the keys is degraded and user action is
  61. // required to add a new method. This may be called frequently and
  62. // implementations are responsible for implementing caching and possibly
  63. // throttling.
  64. virtual void GetIsRecoverabilityDegraded(
  65. const CoreAccountInfo& account_info,
  66. base::OnceCallback<void(bool)> cb) = 0;
  67. // Registers a new trusted recovery method that can be used to retrieve keys,
  68. // usually for the purpose of resolving a recoverability-degraded case
  69. // surfaced by GetIsRecoverabilityDegraded(). |method_type_hint| is an opaque
  70. // value provided server-side that may be used for related future
  71. // interactions with the server.
  72. virtual void AddTrustedRecoveryMethod(const std::string& gaia_id,
  73. const std::vector<uint8_t>& public_key,
  74. int method_type_hint,
  75. base::OnceClosure cb) = 0;
  76. // Clears all data associated with |account_info|. Doesn't remove account from
  77. // storage.
  78. virtual void ClearDataForAccount(const CoreAccountInfo& account_info) = 0;
  79. };
  80. } // namespace syncer
  81. #endif // COMPONENTS_SYNC_DRIVER_TRUSTED_VAULT_CLIENT_H_