| 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_UTIL_CRYPTOGRAPHER_H_ | 5 #ifndef SYNC_UTIL_CRYPTOGRAPHER_H_ |
| 6 #define SYNC_UTIL_CRYPTOGRAPHER_H_ | 6 #define SYNC_UTIL_CRYPTOGRAPHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // types. | 57 // types. |
| 58 // | 58 // |
| 59 // |encrypted_types| will always be a superset of | 59 // |encrypted_types| will always be a superset of |
| 60 // SensitiveTypes(). If |encrypt_everything| is true, | 60 // SensitiveTypes(). If |encrypt_everything| is true, |
| 61 // |encrypted_types| will be the set of all known types. | 61 // |encrypted_types| will be the set of all known types. |
| 62 // | 62 // |
| 63 // Until this function is called, observers can assume that the | 63 // Until this function is called, observers can assume that the |
| 64 // set of encrypted types is SensitiveTypes() and that the encrypt | 64 // set of encrypted types is SensitiveTypes() and that the encrypt |
| 65 // everything flag is false. | 65 // everything flag is false. |
| 66 virtual void OnEncryptedTypesChanged( | 66 virtual void OnEncryptedTypesChanged( |
| 67 syncer::ModelTypeSet encrypted_types, | 67 ModelTypeSet encrypted_types, |
| 68 bool encrypt_everything) = 0; | 68 bool encrypt_everything) = 0; |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 virtual ~Observer(); | 71 virtual ~Observer(); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Does not take ownership of |encryptor|. | 74 // Does not take ownership of |encryptor|. |
| 75 explicit Cryptographer(Encryptor* encryptor); | 75 explicit Cryptographer(Encryptor* encryptor); |
| 76 ~Cryptographer(); | 76 ~Cryptographer(); |
| 77 | 77 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // This updates both the encryption keys and the set of encrypted types. | 173 // This updates both the encryption keys and the set of encrypted types. |
| 174 // Returns NEEDS_PASSPHRASE if was unable to decrypt the pending keys, | 174 // Returns NEEDS_PASSPHRASE if was unable to decrypt the pending keys, |
| 175 // SUCCESS otherwise. | 175 // SUCCESS otherwise. |
| 176 // Note: will not change the default key. If the nigori's keybag | 176 // Note: will not change the default key. If the nigori's keybag |
| 177 // is decryptable, all keys are added to the local keybag and the current | 177 // is decryptable, all keys are added to the local keybag and the current |
| 178 // default is preserved. If the nigori's keybag is not decryptable, it is | 178 // default is preserved. If the nigori's keybag is not decryptable, it is |
| 179 // stored in the |pending_keys_|. | 179 // stored in the |pending_keys_|. |
| 180 UpdateResult Update(const sync_pb::NigoriSpecifics& nigori); | 180 UpdateResult Update(const sync_pb::NigoriSpecifics& nigori); |
| 181 | 181 |
| 182 // The set of types that are always encrypted. | 182 // The set of types that are always encrypted. |
| 183 static syncer::ModelTypeSet SensitiveTypes(); | 183 static ModelTypeSet SensitiveTypes(); |
| 184 | 184 |
| 185 // Reset our set of encrypted types based on the contents of the nigori | 185 // Reset our set of encrypted types based on the contents of the nigori |
| 186 // specifics. | 186 // specifics. |
| 187 void UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori); | 187 void UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori); |
| 188 | 188 |
| 189 // Update the nigori to reflect the current set of encrypted types. | 189 // Update the nigori to reflect the current set of encrypted types. |
| 190 void UpdateNigoriFromEncryptedTypes(sync_pb::NigoriSpecifics* nigori) const; | 190 void UpdateNigoriFromEncryptedTypes(sync_pb::NigoriSpecifics* nigori) const; |
| 191 | 191 |
| 192 // Setter/getter for whether all current and future datatypes should | 192 // Setter/getter for whether all current and future datatypes should |
| 193 // be encrypted. Once set you cannot unset without reading from a | 193 // be encrypted. Once set you cannot unset without reading from a |
| 194 // new nigori node. set_encrypt_everything() emits a notification | 194 // new nigori node. set_encrypt_everything() emits a notification |
| 195 // the first time it's called. | 195 // the first time it's called. |
| 196 void set_encrypt_everything(); | 196 void set_encrypt_everything(); |
| 197 bool encrypt_everything() const; | 197 bool encrypt_everything() const; |
| 198 | 198 |
| 199 // Return the set of encrypted types. | 199 // Return the set of encrypted types. |
| 200 syncer::ModelTypeSet GetEncryptedTypes() const; | 200 ModelTypeSet GetEncryptedTypes() const; |
| 201 | 201 |
| 202 // Forwards to MergeEncryptedTypes. | 202 // Forwards to MergeEncryptedTypes. |
| 203 void MergeEncryptedTypesForTest(syncer::ModelTypeSet encrypted_types); | 203 void MergeEncryptedTypesForTest(ModelTypeSet encrypted_types); |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 FRIEND_TEST_ALL_PREFIXES(SyncCryptographerTest, PackUnpack); | 206 FRIEND_TEST_ALL_PREFIXES(SyncCryptographerTest, PackUnpack); |
| 207 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; | 207 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; |
| 208 | 208 |
| 209 // Merges the given set of encrypted types with the existing set and emits a | 209 // Merges the given set of encrypted types with the existing set and emits a |
| 210 // notification if necessary. | 210 // notification if necessary. |
| 211 void MergeEncryptedTypes(syncer::ModelTypeSet encrypted_types); | 211 void MergeEncryptedTypes(ModelTypeSet encrypted_types); |
| 212 | 212 |
| 213 void EmitEncryptedTypesChangedNotification(); | 213 void EmitEncryptedTypesChangedNotification(); |
| 214 | 214 |
| 215 // Decrypts |encrypted| and uses its contents to initialize Nigori instances. | 215 // Decrypts |encrypted| and uses its contents to initialize Nigori instances. |
| 216 // Returns true unless decryption of |encrypted| fails. The caller is | 216 // Returns true unless decryption of |encrypted| fails. The caller is |
| 217 // responsible for checking that CanDecrypt(encrypted) == true. | 217 // responsible for checking that CanDecrypt(encrypted) == true. |
| 218 // Does not update the default nigori. | 218 // Does not update the default nigori. |
| 219 void InstallKeys(const sync_pb::EncryptedData& encrypted); | 219 void InstallKeys(const sync_pb::EncryptedData& encrypted); |
| 220 | 220 |
| 221 // Helper method to instantiate Nigori instances for each set of key | 221 // Helper method to instantiate Nigori instances for each set of key |
| (...skipping 11 matching lines...) Expand all Loading... |
| 233 | 233 |
| 234 Encryptor* const encryptor_; | 234 Encryptor* const encryptor_; |
| 235 | 235 |
| 236 ObserverList<Observer> observers_; | 236 ObserverList<Observer> observers_; |
| 237 | 237 |
| 238 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. | 238 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. |
| 239 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. | 239 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. |
| 240 | 240 |
| 241 scoped_ptr<sync_pb::EncryptedData> pending_keys_; | 241 scoped_ptr<sync_pb::EncryptedData> pending_keys_; |
| 242 | 242 |
| 243 syncer::ModelTypeSet encrypted_types_; | 243 ModelTypeSet encrypted_types_; |
| 244 bool encrypt_everything_; | 244 bool encrypt_everything_; |
| 245 | 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(Cryptographer); | 246 DISALLOW_COPY_AND_ASSIGN(Cryptographer); |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 } // namespace syncer | 249 } // namespace syncer |
| 250 | 250 |
| 251 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ | 251 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ |
| OLD | NEW |