| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Cryptographer instance into the ready state (is_ready will be true). | 91 // Cryptographer instance into the ready state (is_ready will be true). |
| 92 // It must be a string that was previously built by the | 92 // It must be a string that was previously built by the |
| 93 // GetSerializedBootstrapToken function. It is possible that the token is no | 93 // GetSerializedBootstrapToken function. It is possible that the token is no |
| 94 // longer valid (due to server key change), in which case the normal | 94 // longer valid (due to server key change), in which case the normal |
| 95 // decryption code paths will fail and the user will need to provide a new | 95 // decryption code paths will fail and the user will need to provide a new |
| 96 // passphrase. | 96 // passphrase. |
| 97 // It is an error to call this if is_ready() == true, though it is fair to | 97 // It is an error to call this if is_ready() == true, though it is fair to |
| 98 // never call Bootstrap at all. | 98 // never call Bootstrap at all. |
| 99 void Bootstrap(const std::string& restored_bootstrap_token); | 99 void Bootstrap(const std::string& restored_bootstrap_token); |
| 100 | 100 |
| 101 // Bootstrap the keystore key. |
| 102 void BootstrapKeystoreKey( |
| 103 const std::string& restored_keystore_bootstrap_token); |
| 104 |
| 101 // Returns whether we can decrypt |encrypted| using the keys we currently know | 105 // Returns whether we can decrypt |encrypted| using the keys we currently know |
| 102 // about. | 106 // about. |
| 103 bool CanDecrypt(const sync_pb::EncryptedData& encrypted) const; | 107 bool CanDecrypt(const sync_pb::EncryptedData& encrypted) const; |
| 104 | 108 |
| 105 // Returns whether |encrypted| can be decrypted using the default encryption | 109 // Returns whether |encrypted| can be decrypted using the default encryption |
| 106 // key. | 110 // key. |
| 107 bool CanDecryptUsingDefaultKey(const sync_pb::EncryptedData& encrypted) const; | 111 bool CanDecryptUsingDefaultKey(const sync_pb::EncryptedData& encrypted) const; |
| 108 | 112 |
| 109 // Encrypts |message| into |encrypted|. Does not overwrite |encrypted| if | 113 // Encrypts |message| into |encrypted|. Does not overwrite |encrypted| if |
| 110 // |message| already matches the decrypted data within |encrypted| and | 114 // |message| already matches the decrypted data within |encrypted| and |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 has_pending_keys() == false; } | 166 has_pending_keys() == false; } |
| 163 | 167 |
| 164 // Returns whether there is a pending set of keys that needs to be decrypted. | 168 // Returns whether there is a pending set of keys that needs to be decrypted. |
| 165 bool has_pending_keys() const { return NULL != pending_keys_.get(); } | 169 bool has_pending_keys() const { return NULL != pending_keys_.get(); } |
| 166 | 170 |
| 167 // Obtain a token that can be provided on construction to a future | 171 // Obtain a token that can be provided on construction to a future |
| 168 // Cryptographer instance to bootstrap itself. Returns false if such a token | 172 // Cryptographer instance to bootstrap itself. Returns false if such a token |
| 169 // can't be created (i.e. if this Cryptograhper doesn't have valid keys). | 173 // can't be created (i.e. if this Cryptograhper doesn't have valid keys). |
| 170 bool GetBootstrapToken(std::string* token) const; | 174 bool GetBootstrapToken(std::string* token) const; |
| 171 | 175 |
| 176 // Obtain the bootstrap token based on the keystore encryption key. |
| 177 bool GetKeystoreKeyBootstrapToken(std::string* token) const; |
| 178 |
| 172 // Update the cryptographer based on the contents of the nigori specifics. | 179 // Update the cryptographer based on the contents of the nigori specifics. |
| 173 // This updates both the encryption keys and the set of encrypted types. | 180 // This updates both the encryption keys and the set of encrypted types. |
| 174 // Returns NEEDS_PASSPHRASE if was unable to decrypt the pending keys, | 181 // Returns NEEDS_PASSPHRASE if was unable to decrypt the pending keys, |
| 175 // SUCCESS otherwise. | 182 // SUCCESS otherwise. |
| 176 // Note: will not change the default key. If the nigori's keybag | 183 // 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 | 184 // 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 | 185 // default is preserved. If the nigori's keybag is not decryptable, it is |
| 179 // stored in the |pending_keys_|. | 186 // stored in the |pending_keys_|. |
| 180 UpdateResult Update(const sync_pb::NigoriSpecifics& nigori); | 187 UpdateResult Update(const sync_pb::NigoriSpecifics& nigori); |
| 181 | 188 |
| 182 // Set the keystore-derived nigori from the provided key. | 189 // Set the keystore-derived nigori from the provided key. |
| 183 // Returns true if we succesfully create the keystore derived nigori from the | 190 // Returns true if we succesfully create the keystore derived nigori from the |
| 184 // provided key, false otherwise. | 191 // provided key, false otherwise. |
| 185 bool SetKeystoreKey(const std::string& keystore_key); | 192 bool SetKeystoreKey(const std::string& keystore_key); |
| 186 | 193 |
| 187 // Returns true if we currently have a keystore-derived nigori, false | 194 // Returns true if we currently have a keystore-derived nigori, false |
| 188 // otherwise. | 195 // otherwise. |
| 189 bool HasKeystoreKey(); | 196 bool HasKeystoreKey() const; |
| 190 | 197 |
| 191 // The set of types that are always encrypted. | 198 // The set of types that are always encrypted. |
| 192 static ModelTypeSet SensitiveTypes(); | 199 static ModelTypeSet SensitiveTypes(); |
| 193 | 200 |
| 194 // Reset our set of encrypted types based on the contents of the nigori | 201 // Reset our set of encrypted types based on the contents of the nigori |
| 195 // specifics. | 202 // specifics. |
| 196 void UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori); | 203 void UpdateEncryptedTypesFromNigori(const sync_pb::NigoriSpecifics& nigori); |
| 197 | 204 |
| 198 // Update the nigori to reflect the current set of encrypted types. | 205 // Update the nigori to reflect the current set of encrypted types. |
| 199 void UpdateNigoriFromEncryptedTypes(sync_pb::NigoriSpecifics* nigori) const; | 206 void UpdateNigoriFromEncryptedTypes(sync_pb::NigoriSpecifics* nigori) const; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 225 // Returns true unless decryption of |encrypted| fails. The caller is | 232 // Returns true unless decryption of |encrypted| fails. The caller is |
| 226 // responsible for checking that CanDecrypt(encrypted) == true. | 233 // responsible for checking that CanDecrypt(encrypted) == true. |
| 227 // Does not update the default nigori. | 234 // Does not update the default nigori. |
| 228 void InstallKeys(const sync_pb::EncryptedData& encrypted); | 235 void InstallKeys(const sync_pb::EncryptedData& encrypted); |
| 229 | 236 |
| 230 // Helper method to instantiate Nigori instances for each set of key | 237 // Helper method to instantiate Nigori instances for each set of key |
| 231 // parameters in |bag|. | 238 // parameters in |bag|. |
| 232 // Does not update the default nigori. | 239 // Does not update the default nigori. |
| 233 void InstallKeyBag(const sync_pb::NigoriKeyBag& bag); | 240 void InstallKeyBag(const sync_pb::NigoriKeyBag& bag); |
| 234 | 241 |
| 235 // Helper method to add a nigori as the new default nigori. | 242 // Helper method to add a nigori as either the new default nigori or the new |
| 236 bool AddKeyImpl(Nigori* nigori); | 243 // keystore nigori. |
| 244 bool AddKeyImpl(Nigori* nigori, bool is_keystore_key); |
| 237 | 245 |
| 238 // Functions to serialize + encrypt a Nigori object in an opaque format for | 246 // Functions to serialize + encrypt a Nigori object in an opaque format for |
| 239 // persistence by sync infrastructure. | 247 // persistence by sync infrastructure. |
| 240 bool PackBootstrapToken(const Nigori* nigori, std::string* pack_into) const; | 248 bool PackBootstrapToken(const Nigori* nigori, std::string* pack_into) const; |
| 241 Nigori* UnpackBootstrapToken(const std::string& token) const; | 249 Nigori* UnpackBootstrapToken(const std::string& token) const; |
| 242 | 250 |
| 243 Encryptor* const encryptor_; | 251 Encryptor* const encryptor_; |
| 244 | 252 |
| 245 ObserverList<Observer> observers_; | 253 ObserverList<Observer> observers_; |
| 246 | 254 |
| 247 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. | 255 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. |
| 248 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. | 256 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. |
| 249 NigoriMap::value_type* keystore_nigori_; // Nigori generated from keystore. | 257 NigoriMap::value_type* keystore_nigori_; // Nigori generated from keystore. |
| 250 | 258 |
| 251 scoped_ptr<sync_pb::EncryptedData> pending_keys_; | 259 scoped_ptr<sync_pb::EncryptedData> pending_keys_; |
| 252 | 260 |
| 253 ModelTypeSet encrypted_types_; | 261 ModelTypeSet encrypted_types_; |
| 254 bool encrypt_everything_; | 262 bool encrypt_everything_; |
| 255 | 263 |
| 256 DISALLOW_COPY_AND_ASSIGN(Cryptographer); | 264 DISALLOW_COPY_AND_ASSIGN(Cryptographer); |
| 257 }; | 265 }; |
| 258 | 266 |
| 259 } // namespace syncer | 267 } // namespace syncer |
| 260 | 268 |
| 261 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ | 269 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ |
| OLD | NEW |