nigori_state.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_NIGORI_NIGORI_STATE_H_
  5. #define COMPONENTS_SYNC_NIGORI_NIGORI_STATE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/time/time.h"
  9. #include "components/sync/base/model_type.h"
  10. #include "components/sync/engine/nigori/key_derivation_params.h"
  11. #include "components/sync/engine/nigori/nigori.h"
  12. #include "components/sync/protocol/encryption.pb.h"
  13. #include "components/sync/protocol/nigori_specifics.pb.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. namespace sync_pb {
  16. class NigoriModel;
  17. } // namespace sync_pb
  18. namespace syncer {
  19. class CryptographerImpl;
  20. class KeystoreKeysCryptographer;
  21. struct NigoriState {
  22. static constexpr sync_pb::NigoriSpecifics::PassphraseType
  23. kInitialPassphraseType = sync_pb::NigoriSpecifics::UNKNOWN;
  24. static constexpr bool kInitialEncryptEverything = false;
  25. // Deserialization from proto.
  26. static NigoriState CreateFromLocalProto(const sync_pb::NigoriModel& proto);
  27. NigoriState();
  28. NigoriState(NigoriState&& other);
  29. ~NigoriState();
  30. NigoriState& operator=(NigoriState&& other);
  31. // Serialization to proto as persisted on local disk.
  32. sync_pb::NigoriModel ToLocalProto() const;
  33. // Serialization to proto as sent to the sync server.
  34. sync_pb::NigoriSpecifics ToSpecificsProto() const;
  35. // Makes a deep copy of |this|.
  36. NigoriState Clone() const;
  37. bool NeedsKeystoreReencryption() const;
  38. ModelTypeSet GetEncryptedTypes() const;
  39. // TODO(crbug.com/1109221): Make this const unique_ptr to avoid the object
  40. // being destroyed after it's been injected to the ModelTypeWorker-s.
  41. std::unique_ptr<CryptographerImpl> cryptographer;
  42. // Pending keys represent a remote update that contained a keybag that cannot
  43. // be decrypted (e.g. user needs to enter a custom passphrase). If pending
  44. // keys are present, |*cryptographer| does not have a default encryption key
  45. // set and instead the should-be default encryption key is determined by the
  46. // key in |pending_keys_|.
  47. absl::optional<sync_pb::EncryptedData> pending_keys;
  48. // TODO(mmoskvitin): Consider adopting the C++ enum PassphraseType here and
  49. // if so remove function ProtoPassphraseInt32ToProtoEnum() from
  50. // passphrase_enums.h.
  51. sync_pb::NigoriSpecifics::PassphraseType passphrase_type;
  52. base::Time keystore_migration_time;
  53. base::Time custom_passphrase_time;
  54. // The key derivation params we are using for the custom passphrase. Set iff
  55. // |passphrase_type| is CUSTOM_PASSPHRASE, otherwise key derivation method
  56. // is always PBKDF2.
  57. absl::optional<KeyDerivationParams> custom_passphrase_key_derivation_params;
  58. bool encrypt_everything;
  59. // Contains keystore keys. Uses last keystore key as encryption key. Must be
  60. // not null. Serialized as keystore keys, which must be encrypted with
  61. // OSCrypt before persisting.
  62. std::unique_ptr<KeystoreKeysCryptographer> keystore_keys_cryptographer;
  63. // Represents |keystore_decryptor_token| from NigoriSpecifics in case it
  64. // can't be decrypted right after remote update arrival due to lack of
  65. // keystore keys. May be set only for keystore Nigori.
  66. absl::optional<sync_pb::EncryptedData> pending_keystore_decryptor_token;
  67. // The name of the latest available trusted vault key that was used as the
  68. // default encryption key.
  69. absl::optional<std::string> last_default_trusted_vault_key_name;
  70. // Some debug-only fields for passphrase type TRUSTED_VAULT_PASSPHRASE.
  71. sync_pb::NigoriSpecifics::TrustedVaultDebugInfo trusted_vault_debug_info;
  72. };
  73. } // namespace syncer
  74. #endif // COMPONENTS_SYNC_NIGORI_NIGORI_STATE_H_