Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: sync/internal_api/sync_encryption_handler_impl.cc

Issue 10917246: [Sync] Add keystore encryption info to about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "sync/internal_api/sync_encryption_handler_impl.h" 5 #include "sync/internal_api/sync_encryption_handler_impl.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 UserShare* user_share, 121 UserShare* user_share,
122 Encryptor* encryptor, 122 Encryptor* encryptor,
123 const std::string& restored_key_for_bootstrapping, 123 const std::string& restored_key_for_bootstrapping,
124 const std::string& restored_keystore_key_for_bootstrapping) 124 const std::string& restored_keystore_key_for_bootstrapping)
125 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 125 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
126 user_share_(user_share), 126 user_share_(user_share),
127 vault_unsafe_(encryptor, SensitiveTypes()), 127 vault_unsafe_(encryptor, SensitiveTypes()),
128 encrypt_everything_(false), 128 encrypt_everything_(false),
129 passphrase_type_(IMPLICIT_PASSPHRASE), 129 passphrase_type_(IMPLICIT_PASSPHRASE),
130 keystore_key_(restored_keystore_key_for_bootstrapping), 130 keystore_key_(restored_keystore_key_for_bootstrapping),
131 nigori_overwrite_count_(0), 131 nigori_overwrite_count_(0) {
132 migration_time_ms_(0) {
133 // We only bootstrap the user provided passphrase. The keystore key is handled 132 // We only bootstrap the user provided passphrase. The keystore key is handled
134 // at Init time once we're sure the nigori is downloaded. 133 // at Init time once we're sure the nigori is downloaded.
135 vault_unsafe_.cryptographer.Bootstrap(restored_key_for_bootstrapping); 134 vault_unsafe_.cryptographer.Bootstrap(restored_key_for_bootstrapping);
136 } 135 }
137 136
138 SyncEncryptionHandlerImpl::~SyncEncryptionHandlerImpl() {} 137 SyncEncryptionHandlerImpl::~SyncEncryptionHandlerImpl() {}
139 138
140 void SyncEncryptionHandlerImpl::AddObserver(Observer* observer) { 139 void SyncEncryptionHandlerImpl::AddObserver(Observer* observer) {
141 DCHECK(thread_checker_.CalledOnValidThread()); 140 DCHECK(thread_checker_.CalledOnValidThread());
142 DCHECK(!observers_.HasObserver(observer)); 141 DCHECK(!observers_.HasObserver(observer));
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 586
588 bool SyncEncryptionHandlerImpl::MigratedToKeystore() { 587 bool SyncEncryptionHandlerImpl::MigratedToKeystore() {
589 DCHECK(thread_checker_.CalledOnValidThread()); 588 DCHECK(thread_checker_.CalledOnValidThread());
590 ReadTransaction trans(FROM_HERE, user_share_); 589 ReadTransaction trans(FROM_HERE, user_share_);
591 ReadNode nigori_node(&trans); 590 ReadNode nigori_node(&trans);
592 if (nigori_node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK) 591 if (nigori_node.InitByTagLookup(kNigoriTag) != BaseNode::INIT_OK)
593 return false; 592 return false;
594 return IsNigoriMigratedToKeystore(nigori_node.GetNigoriSpecifics()); 593 return IsNigoriMigratedToKeystore(nigori_node.GetNigoriSpecifics());
595 } 594 }
596 595
596 base::Time SyncEncryptionHandlerImpl::migration_time() const {
597 return migration_time_;
598 }
599
597 // This function iterates over all encrypted types. There are many scenarios in 600 // This function iterates over all encrypted types. There are many scenarios in
598 // which data for some or all types is not currently available. In that case, 601 // which data for some or all types is not currently available. In that case,
599 // the lookup of the root node will fail and we will skip encryption for that 602 // the lookup of the root node will fail and we will skip encryption for that
600 // type. 603 // type.
601 void SyncEncryptionHandlerImpl::ReEncryptEverything( 604 void SyncEncryptionHandlerImpl::ReEncryptEverything(
602 WriteTransaction* trans) { 605 WriteTransaction* trans) {
603 DCHECK(thread_checker_.CalledOnValidThread()); 606 DCHECK(thread_checker_.CalledOnValidThread());
604 DCHECK(UnlockVault(trans->GetWrappedTrans()).cryptographer.is_ready()); 607 DCHECK(UnlockVault(trans->GetWrappedTrans()).cryptographer.is_ready());
605 for (ModelTypeSet::Iterator iter = 608 for (ModelTypeSet::Iterator iter =
606 UnlockVault(trans->GetWrappedTrans()).encrypted_types.First(); 609 UnlockVault(trans->GetWrappedTrans()).encrypted_types.First();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 670
668 bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl( 671 bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
669 const sync_pb::NigoriSpecifics& nigori, 672 const sync_pb::NigoriSpecifics& nigori,
670 syncable::BaseTransaction* const trans) { 673 syncable::BaseTransaction* const trans) {
671 DCHECK(thread_checker_.CalledOnValidThread()); 674 DCHECK(thread_checker_.CalledOnValidThread());
672 DVLOG(1) << "Applying nigori node update."; 675 DVLOG(1) << "Applying nigori node update.";
673 bool nigori_types_need_update = !UpdateEncryptedTypesFromNigori(nigori, 676 bool nigori_types_need_update = !UpdateEncryptedTypesFromNigori(nigori,
674 trans); 677 trans);
675 bool is_nigori_migrated = IsNigoriMigratedToKeystore(nigori); 678 bool is_nigori_migrated = IsNigoriMigratedToKeystore(nigori);
676 if (is_nigori_migrated) { 679 if (is_nigori_migrated) {
677 migration_time_ms_ = nigori.keystore_migration_time(); 680 DCHECK(nigori.has_keystore_migration_time());
681 migration_time_ = ProtoTimeToTime(nigori.keystore_migration_time());
678 PassphraseType nigori_passphrase_type = 682 PassphraseType nigori_passphrase_type =
679 ProtoPassphraseTypeToEnum(nigori.passphrase_type()); 683 ProtoPassphraseTypeToEnum(nigori.passphrase_type());
680 684
681 // Only update the local passphrase state if it's a valid transition: 685 // Only update the local passphrase state if it's a valid transition:
682 // - implicit -> keystore 686 // - implicit -> keystore
683 // - implicit -> frozen implicit 687 // - implicit -> frozen implicit
684 // - implicit -> custom 688 // - implicit -> custom
685 // - keystore -> custom 689 // - keystore -> custom
686 // Note: frozen implicit -> custom is not technically a valid transition, 690 // Note: frozen implicit -> custom is not technically a valid transition,
687 // but we let it through here as well in case future versions do add support 691 // but we let it through here as well in case future versions do add support
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 DCHECK(thread_checker_.CalledOnValidThread()); 1139 DCHECK(thread_checker_.CalledOnValidThread());
1136 const sync_pb::NigoriSpecifics& old_nigori = 1140 const sync_pb::NigoriSpecifics& old_nigori =
1137 nigori_node->GetNigoriSpecifics(); 1141 nigori_node->GetNigoriSpecifics();
1138 Cryptographer* cryptographer = 1142 Cryptographer* cryptographer =
1139 &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer; 1143 &UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer;
1140 1144
1141 if (!ShouldTriggerMigration(old_nigori, *cryptographer)) 1145 if (!ShouldTriggerMigration(old_nigori, *cryptographer))
1142 return false; 1146 return false;
1143 1147
1144 DVLOG(1) << "Starting nigori migration to keystore support."; 1148 DVLOG(1) << "Starting nigori migration to keystore support.";
1145 if (migration_time_ms_ == 0)
1146 migration_time_ms_ = TimeToProtoTime(base::Time::Now());
1147 sync_pb::NigoriSpecifics migrated_nigori(old_nigori); 1149 sync_pb::NigoriSpecifics migrated_nigori(old_nigori);
1148 migrated_nigori.set_keystore_migration_time(migration_time_ms_);
1149 1150
1150 PassphraseType new_passphrase_type = passphrase_type_; 1151 PassphraseType new_passphrase_type = passphrase_type_;
1151 bool new_encrypt_everything = encrypt_everything_; 1152 bool new_encrypt_everything = encrypt_everything_;
1152 if (encrypt_everything_ && !IsExplicitPassphrase(passphrase_type_)) { 1153 if (encrypt_everything_ && !IsExplicitPassphrase(passphrase_type_)) {
1153 DVLOG(1) << "Switching to frozen implicit passphrase due to already having " 1154 DVLOG(1) << "Switching to frozen implicit passphrase due to already having "
1154 << "full encryption."; 1155 << "full encryption.";
1155 new_passphrase_type = FROZEN_IMPLICIT_PASSPHRASE; 1156 new_passphrase_type = FROZEN_IMPLICIT_PASSPHRASE;
1156 migrated_nigori.clear_keystore_decryptor_token(); 1157 migrated_nigori.clear_keystore_decryptor_token();
1157 } else if (IsExplicitPassphrase(passphrase_type_)) { 1158 } else if (IsExplicitPassphrase(passphrase_type_)) {
1158 DVLOG_IF(1, !encrypt_everything_) << "Enabling encrypt everything due to " 1159 DVLOG_IF(1, !encrypt_everything_) << "Enabling encrypt everything due to "
(...skipping 23 matching lines...) Expand all
1182 keystore_key_, 1183 keystore_key_,
1183 migrated_nigori.mutable_keystore_decryptor_token())) { 1184 migrated_nigori.mutable_keystore_decryptor_token())) {
1184 LOG(ERROR) << "Failed to extract keystore decryptor token."; 1185 LOG(ERROR) << "Failed to extract keystore decryptor token.";
1185 return false; 1186 return false;
1186 } 1187 }
1187 if (!cryptographer->GetKeys(migrated_nigori.mutable_encryption_keybag())) { 1188 if (!cryptographer->GetKeys(migrated_nigori.mutable_encryption_keybag())) {
1188 LOG(ERROR) << "Failed to extract encryption keybag."; 1189 LOG(ERROR) << "Failed to extract encryption keybag.";
1189 return false; 1190 return false;
1190 } 1191 }
1191 1192
1193 if (migration_time_.is_null())
1194 migration_time_ = base::Time::Now();
1195 migrated_nigori.set_keystore_migration_time(TimeToProtoTime(migration_time_));
1196
1192 DVLOG(1) << "Completing nigori migration to keystore support."; 1197 DVLOG(1) << "Completing nigori migration to keystore support.";
1193 nigori_node->SetNigoriSpecifics(migrated_nigori); 1198 nigori_node->SetNigoriSpecifics(migrated_nigori);
1199
1200 FOR_EACH_OBSERVER(
1201 SyncEncryptionHandler::Observer,
1202 observers_,
1203 OnCryptographerStateChanged(cryptographer));
1194 if (passphrase_type_ != new_passphrase_type) { 1204 if (passphrase_type_ != new_passphrase_type) {
1195 passphrase_type_ = new_passphrase_type; 1205 passphrase_type_ = new_passphrase_type;
1196 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 1206 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
1197 OnPassphraseTypeChanged(passphrase_type_)); 1207 OnPassphraseTypeChanged(passphrase_type_));
1198 } 1208 }
1209
1199 if (new_encrypt_everything && !encrypt_everything_) { 1210 if (new_encrypt_everything && !encrypt_everything_) {
1200 EnableEncryptEverythingImpl(trans->GetWrappedTrans()); 1211 EnableEncryptEverythingImpl(trans->GetWrappedTrans());
1201 ReEncryptEverything(trans); 1212 ReEncryptEverything(trans);
1202 } 1213 }
1203 return true; 1214 return true;
1204 } 1215 }
1205 1216
1206 bool SyncEncryptionHandlerImpl::GetKeystoreDecryptor( 1217 bool SyncEncryptionHandlerImpl::GetKeystoreDecryptor(
1207 const Cryptographer& cryptographer, 1218 const Cryptographer& cryptographer,
1208 const std::string& keystore_key, 1219 const std::string& keystore_key,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 SyncEncryptionHandler::Observer, 1303 SyncEncryptionHandler::Observer,
1293 observers_, 1304 observers_,
1294 OnCryptographerStateChanged(cryptographer)); 1305 OnCryptographerStateChanged(cryptographer));
1295 return true; 1306 return true;
1296 } 1307 }
1297 } 1308 }
1298 return false; 1309 return false;
1299 } 1310 }
1300 1311
1301 } // namespace browser_sync 1312 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/internal_api/sync_encryption_handler_impl.h ('k') | sync/internal_api/sync_encryption_handler_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698