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

Side by Side Diff: chrome/browser/sync/internal_api/sync_manager.cc

Issue 8759019: [Sync] Add intelligent re-encryption support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/internal_api/sync_manager.h" 5 #include "chrome/browser/sync/internal_api/sync_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 Cryptographer::UpdateResult result = cryptographer->Update(nigori); 847 Cryptographer::UpdateResult result = cryptographer->Update(nigori);
848 if (result == Cryptographer::NEEDS_PASSPHRASE) { 848 if (result == Cryptographer::NEEDS_PASSPHRASE) {
849 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 849 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
850 OnPassphraseRequired(sync_api::REASON_DECRYPTION)); 850 OnPassphraseRequired(sync_api::REASON_DECRYPTION));
851 } 851 }
852 852
853 // Due to http://crbug.com/102526, we must check if the encryption keys 853 // Due to http://crbug.com/102526, we must check if the encryption keys
854 // are present in the nigori node. If they're not, we write the current set of 854 // are present in the nigori node. If they're not, we write the current set of
855 // keys. 855 // keys.
856 if (!nigori.has_encrypted() && cryptographer->is_ready()) { 856 if (!nigori.has_encrypted() && cryptographer->is_ready()) {
857 cryptographer->GetKeys(nigori.mutable_encrypted()); 857 DCHECK(cryptographer->GetKeys(nigori.mutable_encrypted()));
akalin 2011/12/09 23:52:42 Change to a CHECK, or rewrite as: if (!...) { N
Nicolas Zea 2011/12/12 20:12:26 Done.
858 } 858 }
859 859
860 // Ensure the nigori node reflects the most recent set of sensitive types 860 // Ensure the nigori node reflects the most recent set of sensitive types
861 // and properly sets encrypt_everything. This is a no-op if nothing changes. 861 // and properly sets encrypt_everything. This is a no-op if nothing changes.
862 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 862 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
863 node.SetNigoriSpecifics(nigori); 863 node.SetNigoriSpecifics(nigori);
864 864
865 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 865 allstatus_.SetCryptographerReady(cryptographer->is_ready());
866 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 866 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
867 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 867 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 RequestNudge(FROM_HERE); 1054 RequestNudge(FROM_HERE);
1055 } else { 1055 } else {
1056 DVLOG(1) << "No pending keys, adding provided passphrase."; 1056 DVLOG(1) << "No pending keys, adding provided passphrase.";
1057 1057
1058 // Prevent an implicit SetPassphrase request from changing an explicitly 1058 // Prevent an implicit SetPassphrase request from changing an explicitly
1059 // set passphrase. 1059 // set passphrase.
1060 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase()) 1060 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase())
1061 return; 1061 return;
1062 1062
1063 cryptographer->AddKey(params); 1063 cryptographer->AddKey(params);
1064 }
1064 1065
1065 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require 1066 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require
1066 // messing with the Nigori node, because we can't call SetPassphrase until 1067 // messing with the Nigori node, because we can't call SetPassphrase until
1067 // download conditions are met vs Cryptographer init. It seems like it's 1068 // download conditions are met vs Cryptographer init. It seems like it's
1068 // safe to defer this work. 1069 // safe to defer this work.
1069 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics()); 1070 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
1070 specifics.clear_encrypted(); 1071 // Does not modify specifics.encrypted() if the original decrypted data was
1071 cryptographer->GetKeys(specifics.mutable_encrypted()); 1072 // the same.
1072 specifics.set_using_explicit_passphrase(is_explicit); 1073 DCHECK(cryptographer->GetKeys(specifics.mutable_encrypted()));
akalin 2011/12/09 23:52:42 here, too
Nicolas Zea 2011/12/12 20:12:26 Done.
1073 node.SetNigoriSpecifics(specifics); 1074 specifics.set_using_explicit_passphrase(is_explicit);
1074 } 1075 node.SetNigoriSpecifics(specifics);
1075 1076
1076 // Does nothing if everything is already encrypted or the cryptographer has 1077 // Does nothing if everything is already encrypted or the cryptographer has
1077 // pending keys. 1078 // pending keys.
1078 ReEncryptEverything(&trans); 1079 ReEncryptEverything(&trans);
1079 1080
1080 DVLOG(1) << "Passphrase accepted, bootstrapping encryption."; 1081 DVLOG(1) << "Passphrase accepted, bootstrapping encryption.";
1081 std::string bootstrap_token; 1082 std::string bootstrap_token;
1082 cryptographer->GetBootstrapToken(&bootstrap_token); 1083 cryptographer->GetBootstrapToken(&bootstrap_token);
1083 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1084 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1084 OnPassphraseAccepted(bootstrap_token)); 1085 OnPassphraseAccepted(bootstrap_token));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 nigori.CopyFrom(node.GetNigoriSpecifics()); 1127 nigori.CopyFrom(node.GetNigoriSpecifics());
1127 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 1128 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
1128 node.SetNigoriSpecifics(nigori); 1129 node.SetNigoriSpecifics(nigori);
1129 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 1130 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
1130 1131
1131 // We reencrypt everything regardless of whether the set of encrypted 1132 // We reencrypt everything regardless of whether the set of encrypted
1132 // types changed to ensure that any stray unencrypted entries are overwritten. 1133 // types changed to ensure that any stray unencrypted entries are overwritten.
1133 ReEncryptEverything(&trans); 1134 ReEncryptEverything(&trans);
1134 } 1135 }
1135 1136
1136 // TODO(zea): Add unit tests that ensure no sync changes are made when not
1137 // needed.
1138 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1137 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1139 Cryptographer* cryptographer = trans->GetCryptographer(); 1138 Cryptographer* cryptographer = trans->GetCryptographer();
1140 if (!cryptographer || !cryptographer->is_ready()) 1139 if (!cryptographer || !cryptographer->is_ready())
1141 return; 1140 return;
1142 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); 1141 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
1143 ModelSafeRoutingInfo routes; 1142 ModelSafeRoutingInfo routes;
1144 registrar_->GetModelSafeRoutingInfo(&routes); 1143 registrar_->GetModelSafeRoutingInfo(&routes);
1145 std::string tag; 1144 std::string tag;
1146 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin(); 1145 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin();
1147 iter != encrypted_types.end(); ++iter) { 1146 iter != encrypted_types.end(); ++iter) {
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 lookup->GetDownloadProgress(*i, &marker); 2081 lookup->GetDownloadProgress(*i, &marker);
2083 2082
2084 if (marker.token().empty()) 2083 if (marker.token().empty())
2085 result.insert(*i); 2084 result.insert(*i);
2086 2085
2087 } 2086 }
2088 return result; 2087 return result;
2089 } 2088 }
2090 2089
2091 } // namespace sync_api 2090 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698