Chromium Code Reviews| Index: sync/internal_api/sync_encryption_handler_impl.cc |
| diff --git a/sync/internal_api/sync_encryption_handler_impl.cc b/sync/internal_api/sync_encryption_handler_impl.cc |
| index 2d4497118d31ec4d682c587f1dd37df45685cddf..58f855c714a78a939798eabbcf90919227e3c6fc 100644 |
| --- a/sync/internal_api/sync_encryption_handler_impl.cc |
| +++ b/sync/internal_api/sync_encryption_handler_impl.cc |
| @@ -52,7 +52,9 @@ T* TransactionalHolder<T>::GetMutable( |
| SyncEncryptionHandlerImpl::SyncEncryptionHandlerImpl( |
| UserShare* user_share, |
| - Encryptor* encryptor) |
| + Encryptor* encryptor, |
| + const std::string& restored_key_for_bootstrapping, |
| + const std::string& restored_keystore_key_for_bootstrapping) |
| : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| user_share_(user_share), |
| cryptographer_unsafe_(encryptor), |
| @@ -61,7 +63,11 @@ SyncEncryptionHandlerImpl::SyncEncryptionHandlerImpl( |
| encrypted_types_holder_(user_share_, &encrypted_types_unsafe_), |
| encrypt_everything_(false), |
| passphrase_state_(IMPLICIT_PASSPHRASE), |
| + keystore_key_(restored_keystore_key_for_bootstrapping), |
| nigori_overwrite_count_(0) { |
| + // We only bootstrap the user provided passphrase. The keystore key is handled |
| + // at Init time once we're sure the nigori is downloaded. |
| + cryptographer_unsafe_.Bootstrap(restored_key_for_bootstrapping); |
| } |
| SyncEncryptionHandlerImpl::~SyncEncryptionHandlerImpl() {} |
| @@ -423,6 +429,27 @@ void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes( |
| nigori); |
| } |
| +bool SyncEncryptionHandlerImpl::NeedKeystoreKey( |
| + syncable::BaseTransaction* const trans) const { |
| + return keystore_key_.empty(); |
| +} |
| + |
| +bool SyncEncryptionHandlerImpl::SetKeystoreKey( |
| + const std::string& key, |
| + syncable::BaseTransaction* const trans) { |
| + if (!keystore_key_.empty() || key.empty()) |
| + return false; |
| + keystore_key_ = key; |
| + |
| + // TODO(zea): trigger migration if necessary. |
| + |
| + DVLOG(1) << "Keystore bootstrap token updated."; |
|
akalin
2012/08/22 22:09:33
usually no periods on log statements
Nicolas Zea
2012/08/22 22:48:59
Done.
|
| + FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| + OnBootstrapTokenUpdated(key, |
| + KEYSTORE_BOOTSTRAP_TOKEN)); |
| + return true; |
| +} |
| + |
| ModelTypeSet SyncEncryptionHandlerImpl::GetEncryptedTypes( |
| syncable::BaseTransaction* const trans) const { |
| return encrypted_types_holder_.Get(trans); |
| @@ -677,7 +704,8 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase( |
| if (!bootstrap_token.empty()) { |
| DVLOG(1) << "Bootstrap token updated."; |
| FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
| - OnBootstrapTokenUpdated(bootstrap_token)); |
| + OnBootstrapTokenUpdated(bootstrap_token, |
| + PASSPHRASE_BOOTSTRAP_TOKEN)); |
| } |
| const Cryptographer& cryptographer = |
| @@ -700,6 +728,8 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase( |
| DCHECK(cryptographer.is_ready()); |
| + // TODO(zea): trigger migration if necessary. |
| + |
| sync_pb::NigoriSpecifics specifics(nigori_node->GetNigoriSpecifics()); |
| // Does not modify specifics.encrypted() if the original decrypted data was |
| // the same. |