| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H_ | 5 #ifndef SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H_ |
| 6 #define SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H_ | 6 #define SYNC_INTERNAL_API_SYNC_ENCRYPTION_HANDLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // | 64 // |
| 65 // Note: See sync_encryption_handler.h for a description of the chrome visible | 65 // Note: See sync_encryption_handler.h for a description of the chrome visible |
| 66 // methods and what they do, and nigori_handler.h for a description of the | 66 // methods and what they do, and nigori_handler.h for a description of the |
| 67 // sync methods. | 67 // sync methods. |
| 68 // All methods are non-thread-safe and should only be called from the sync | 68 // All methods are non-thread-safe and should only be called from the sync |
| 69 // thread unless explicitly noted otherwise. | 69 // thread unless explicitly noted otherwise. |
| 70 class SyncEncryptionHandlerImpl | 70 class SyncEncryptionHandlerImpl |
| 71 : public SyncEncryptionHandler, | 71 : public SyncEncryptionHandler, |
| 72 public syncable::NigoriHandler { | 72 public syncable::NigoriHandler { |
| 73 public: | 73 public: |
| 74 SyncEncryptionHandlerImpl(UserShare* user_share, | 74 SyncEncryptionHandlerImpl( |
| 75 Encryptor* encryptor); | 75 UserShare* user_share, |
| 76 Encryptor* encryptor, |
| 77 const std::string& restored_key_for_bootstrapping, |
| 78 const std::string& restored_keystore_key_for_bootstrapping); |
| 76 virtual ~SyncEncryptionHandlerImpl(); | 79 virtual ~SyncEncryptionHandlerImpl(); |
| 77 | 80 |
| 78 // SyncEncryptionHandler implementation. | 81 // SyncEncryptionHandler implementation. |
| 79 virtual void AddObserver(Observer* observer) OVERRIDE; | 82 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 80 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 83 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 81 virtual void Init() OVERRIDE; | 84 virtual void Init() OVERRIDE; |
| 82 virtual void SetEncryptionPassphrase(const std::string& passphrase, | 85 virtual void SetEncryptionPassphrase(const std::string& passphrase, |
| 83 bool is_explicit) OVERRIDE; | 86 bool is_explicit) OVERRIDE; |
| 84 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; | 87 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; |
| 85 virtual void EnableEncryptEverything() OVERRIDE; | 88 virtual void EnableEncryptEverything() OVERRIDE; |
| 86 virtual bool EncryptEverythingEnabled() const OVERRIDE; | 89 virtual bool EncryptEverythingEnabled() const OVERRIDE; |
| 87 virtual PassphraseState GetPassphraseState() const OVERRIDE; | 90 virtual PassphraseState GetPassphraseState() const OVERRIDE; |
| 88 | 91 |
| 89 // NigoriHandler implementation. | 92 // NigoriHandler implementation. |
| 90 // Note: all methods are invoked while the caller holds a transaction. | 93 // Note: all methods are invoked while the caller holds a transaction. |
| 91 virtual void ApplyNigoriUpdate( | 94 virtual void ApplyNigoriUpdate( |
| 92 const sync_pb::NigoriSpecifics& nigori, | 95 const sync_pb::NigoriSpecifics& nigori, |
| 93 syncable::BaseTransaction* const trans) OVERRIDE; | 96 syncable::BaseTransaction* const trans) OVERRIDE; |
| 94 virtual void UpdateNigoriFromEncryptedTypes( | 97 virtual void UpdateNigoriFromEncryptedTypes( |
| 95 sync_pb::NigoriSpecifics* nigori, | 98 sync_pb::NigoriSpecifics* nigori, |
| 96 syncable::BaseTransaction* const trans) const OVERRIDE; | 99 syncable::BaseTransaction* const trans) const OVERRIDE; |
| 100 virtual bool NeedKeystoreKey( |
| 101 syncable::BaseTransaction* const trans) const OVERRIDE; |
| 102 virtual bool SetKeystoreKey( |
| 103 const std::string& key, |
| 104 syncable::BaseTransaction* const trans) OVERRIDE; |
| 97 // Can be called from any thread. | 105 // Can be called from any thread. |
| 98 virtual ModelTypeSet GetEncryptedTypes( | 106 virtual ModelTypeSet GetEncryptedTypes( |
| 99 syncable::BaseTransaction* const trans) const OVERRIDE; | 107 syncable::BaseTransaction* const trans) const OVERRIDE; |
| 100 | 108 |
| 101 // Getters. | 109 // Getters. |
| 102 Cryptographer* cryptographer_unsafe() { return &cryptographer_unsafe_; } | 110 Cryptographer* cryptographer_unsafe() { return &cryptographer_unsafe_; } |
| 103 ModelTypeSet encrypted_types_unsafe() { return encrypted_types_unsafe_; } | 111 ModelTypeSet encrypted_types_unsafe() { return encrypted_types_unsafe_; } |
| 104 | 112 |
| 105 private: | 113 private: |
| 106 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest, | 114 FRIEND_TEST_ALL_PREFIXES(SyncEncryptionHandlerImplTest, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 TransactionalHolder<ModelTypeSet> encrypted_types_holder_; | 195 TransactionalHolder<ModelTypeSet> encrypted_types_holder_; |
| 188 | 196 |
| 189 // Sync encryption state that is only modified and accessed from the sync | 197 // Sync encryption state that is only modified and accessed from the sync |
| 190 // thread. | 198 // thread. |
| 191 // Whether all current and future types should be encrypted. | 199 // Whether all current and future types should be encrypted. |
| 192 bool encrypt_everything_; | 200 bool encrypt_everything_; |
| 193 // The current state of the passphrase required to decrypt the encryption | 201 // The current state of the passphrase required to decrypt the encryption |
| 194 // keys stored in the nigori node. | 202 // keys stored in the nigori node. |
| 195 PassphraseState passphrase_state_; | 203 PassphraseState passphrase_state_; |
| 196 | 204 |
| 205 // The keystore key provided by the server. |
| 206 std::string keystore_key_; |
| 207 |
| 197 // The number of times we've automatically (i.e. not via SetPassphrase or | 208 // The number of times we've automatically (i.e. not via SetPassphrase or |
| 198 // conflict resolver) updated the nigori's encryption keys in this chrome | 209 // conflict resolver) updated the nigori's encryption keys in this chrome |
| 199 // instantiation. | 210 // instantiation. |
| 200 int nigori_overwrite_count_; | 211 int nigori_overwrite_count_; |
| 201 | 212 |
| 202 DISALLOW_COPY_AND_ASSIGN(SyncEncryptionHandlerImpl); | 213 DISALLOW_COPY_AND_ASSIGN(SyncEncryptionHandlerImpl); |
| 203 }; | 214 }; |
| 204 | 215 |
| 205 } // namespace syncer | 216 } // namespace syncer |
| 206 | 217 |
| 207 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_ENCRYPTION_HANDLER_IMPL_H_ | 218 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_ENCRYPTION_HANDLER_IMPL_H_ |
| OLD | NEW |