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

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 again 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 if (!cryptographer->GetKeys(nigori.mutable_encrypted())) {
858 NOTREACHED();
859 return false;
860 }
858 } 861 }
859 862
860 // Ensure the nigori node reflects the most recent set of sensitive types 863 // 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. 864 // and properly sets encrypt_everything. This is a no-op if nothing changes.
862 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 865 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
863 node.SetNigoriSpecifics(nigori); 866 node.SetNigoriSpecifics(nigori);
864 867
865 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 868 allstatus_.SetCryptographerReady(cryptographer->is_ready());
866 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 869 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
867 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 870 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 RequestNudge(FROM_HERE); 1053 RequestNudge(FROM_HERE);
1051 } else { 1054 } else {
1052 DVLOG(1) << "No pending keys, adding provided passphrase."; 1055 DVLOG(1) << "No pending keys, adding provided passphrase.";
1053 1056
1054 // Prevent an implicit SetPassphrase request from changing an explicitly 1057 // Prevent an implicit SetPassphrase request from changing an explicitly
1055 // set passphrase. 1058 // set passphrase.
1056 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase()) 1059 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase())
1057 return; 1060 return;
1058 1061
1059 cryptographer->AddKey(params); 1062 cryptographer->AddKey(params);
1063 }
1060 1064
1061 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require 1065 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require
1062 // messing with the Nigori node, because we can't call SetPassphrase until 1066 // messing with the Nigori node, because we can't call SetPassphrase until
1063 // download conditions are met vs Cryptographer init. It seems like it's 1067 // download conditions are met vs Cryptographer init. It seems like it's
1064 // safe to defer this work. 1068 // safe to defer this work.
1065 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics()); 1069 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
1066 specifics.clear_encrypted(); 1070 // Does not modify specifics.encrypted() if the original decrypted data was
1067 cryptographer->GetKeys(specifics.mutable_encrypted()); 1071 // the same.
1068 specifics.set_using_explicit_passphrase(is_explicit); 1072 if (!cryptographer->GetKeys(specifics.mutable_encrypted())) {
1069 node.SetNigoriSpecifics(specifics); 1073 NOTREACHED();
1074 return;
1070 } 1075 }
1076 specifics.set_using_explicit_passphrase(is_explicit);
1077 node.SetNigoriSpecifics(specifics);
1071 1078
1072 // Does nothing if everything is already encrypted or the cryptographer has 1079 // Does nothing if everything is already encrypted or the cryptographer has
1073 // pending keys. 1080 // pending keys.
1074 ReEncryptEverything(&trans); 1081 ReEncryptEverything(&trans);
1075 1082
1076 DVLOG(1) << "Passphrase accepted, bootstrapping encryption."; 1083 DVLOG(1) << "Passphrase accepted, bootstrapping encryption.";
1077 std::string bootstrap_token; 1084 std::string bootstrap_token;
1078 cryptographer->GetBootstrapToken(&bootstrap_token); 1085 cryptographer->GetBootstrapToken(&bootstrap_token);
1079 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1086 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1080 OnPassphraseAccepted(bootstrap_token)); 1087 OnPassphraseAccepted(bootstrap_token));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 nigori.CopyFrom(node.GetNigoriSpecifics()); 1129 nigori.CopyFrom(node.GetNigoriSpecifics());
1123 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 1130 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
1124 node.SetNigoriSpecifics(nigori); 1131 node.SetNigoriSpecifics(nigori);
1125 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 1132 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
1126 1133
1127 // We reencrypt everything regardless of whether the set of encrypted 1134 // We reencrypt everything regardless of whether the set of encrypted
1128 // types changed to ensure that any stray unencrypted entries are overwritten. 1135 // types changed to ensure that any stray unencrypted entries are overwritten.
1129 ReEncryptEverything(&trans); 1136 ReEncryptEverything(&trans);
1130 } 1137 }
1131 1138
1132 // TODO(zea): Add unit tests that ensure no sync changes are made when not
1133 // needed.
1134 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1139 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1135 Cryptographer* cryptographer = trans->GetCryptographer(); 1140 Cryptographer* cryptographer = trans->GetCryptographer();
1136 if (!cryptographer || !cryptographer->is_ready()) 1141 if (!cryptographer || !cryptographer->is_ready())
1137 return; 1142 return;
1138 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); 1143 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
1139 ModelSafeRoutingInfo routes; 1144 ModelSafeRoutingInfo routes;
1140 registrar_->GetModelSafeRoutingInfo(&routes); 1145 registrar_->GetModelSafeRoutingInfo(&routes);
1141 std::string tag; 1146 std::string tag;
1142 for (syncable::ModelTypeSet::Iterator iter = encrypted_types.First(); 1147 for (syncable::ModelTypeSet::Iterator iter = encrypted_types.First();
1143 iter.Good(); iter.Inc()) { 1148 iter.Good(); iter.Inc()) {
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 lookup->GetDownloadProgress(i.Get(), &marker); 2081 lookup->GetDownloadProgress(i.Get(), &marker);
2077 2082
2078 if (marker.token().empty()) 2083 if (marker.token().empty())
2079 result.Put(i.Get()); 2084 result.Put(i.Get());
2080 2085
2081 } 2086 }
2082 return result; 2087 return result;
2083 } 2088 }
2084 2089
2085 } // namespace sync_api 2090 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/base_node.h ('k') | chrome/browser/sync/internal_api/syncapi_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698