| 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 bd6608ac6619cd4ed1dd42680504a85441bff0ad..eda619fffae00aa48ba0163b56d5fa49efd33614 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() {}
|
| @@ -430,6 +436,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.";
|
| + 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);
|
| @@ -684,7 +711,8 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase(
|
| if (!bootstrap_token.empty()) {
|
| DVLOG(1) << "Passphrase bootstrap token updated.";
|
| FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
|
| - OnBootstrapTokenUpdated(bootstrap_token));
|
| + OnBootstrapTokenUpdated(bootstrap_token,
|
| + PASSPHRASE_BOOTSTRAP_TOKEN));
|
| }
|
|
|
| const Cryptographer& cryptographer =
|
| @@ -707,6 +735,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.
|
|
|