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

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: Self review 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 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 RequestNudge(FROM_HERE); 1059 RequestNudge(FROM_HERE);
1060 } else { 1060 } else {
1061 DVLOG(1) << "No pending keys, adding provided passphrase."; 1061 DVLOG(1) << "No pending keys, adding provided passphrase.";
1062 1062
1063 // Prevent an implicit SetPassphrase request from changing an explicitly 1063 // Prevent an implicit SetPassphrase request from changing an explicitly
1064 // set passphrase. 1064 // set passphrase.
1065 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase()) 1065 if (!is_explicit && node.GetNigoriSpecifics().using_explicit_passphrase())
1066 return; 1066 return;
1067 1067
1068 cryptographer->AddKey(params); 1068 cryptographer->AddKey(params);
1069 }
1069 1070
1070 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require 1071 // TODO(tim): Bug 58231. It would be nice if SetPassphrase didn't require
akalin 2011/12/06 18:28:02 any reason why you moved this out of the if statem
Nicolas Zea 2011/12/06 20:45:36 To ensure we always have the full set of keys, now
1071 // messing with the Nigori node, because we can't call SetPassphrase until 1072 // messing with the Nigori node, because we can't call SetPassphrase until
1072 // download conditions are met vs Cryptographer init. It seems like it's 1073 // download conditions are met vs Cryptographer init. It seems like it's
1073 // safe to defer this work. 1074 // safe to defer this work.
1074 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics()); 1075 sync_pb::NigoriSpecifics specifics(node.GetNigoriSpecifics());
1075 specifics.clear_encrypted(); 1076 // Does not modify specifics.encrypted() if the original decrypted data was
1076 cryptographer->GetKeys(specifics.mutable_encrypted()); 1077 // the same.
1077 specifics.set_using_explicit_passphrase(is_explicit); 1078 cryptographer->GetKeys(specifics.mutable_encrypted());
akalin 2011/12/06 18:28:02 check return value?
Nicolas Zea 2011/12/06 20:45:36 Done.
1078 node.SetNigoriSpecifics(specifics); 1079 specifics.set_using_explicit_passphrase(is_explicit);
1079 } 1080 node.SetNigoriSpecifics(specifics);
1080 1081
1081 // Does nothing if everything is already encrypted or the cryptographer has 1082 // Does nothing if everything is already encrypted or the cryptographer has
1082 // pending keys. 1083 // pending keys.
1083 ReEncryptEverything(&trans); 1084 ReEncryptEverything(&trans);
1084 1085
1085 DVLOG(1) << "Passphrase accepted, bootstrapping encryption."; 1086 DVLOG(1) << "Passphrase accepted, bootstrapping encryption.";
1086 std::string bootstrap_token; 1087 std::string bootstrap_token;
1087 cryptographer->GetBootstrapToken(&bootstrap_token); 1088 cryptographer->GetBootstrapToken(&bootstrap_token);
1088 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 1089 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
1089 OnPassphraseAccepted(bootstrap_token)); 1090 OnPassphraseAccepted(bootstrap_token));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 nigori.CopyFrom(node.GetNigoriSpecifics()); 1132 nigori.CopyFrom(node.GetNigoriSpecifics());
1132 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 1133 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
1133 node.SetNigoriSpecifics(nigori); 1134 node.SetNigoriSpecifics(nigori);
1134 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes()); 1135 allstatus_.SetEncryptedTypes(cryptographer->GetEncryptedTypes());
1135 1136
1136 // We reencrypt everything regardless of whether the set of encrypted 1137 // We reencrypt everything regardless of whether the set of encrypted
1137 // types changed to ensure that any stray unencrypted entries are overwritten. 1138 // types changed to ensure that any stray unencrypted entries are overwritten.
1138 ReEncryptEverything(&trans); 1139 ReEncryptEverything(&trans);
1139 } 1140 }
1140 1141
1141 // TODO(zea): Add unit tests that ensure no sync changes are made when not
1142 // needed.
1143 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) { 1142 void SyncManager::SyncInternal::ReEncryptEverything(WriteTransaction* trans) {
1144 Cryptographer* cryptographer = trans->GetCryptographer(); 1143 Cryptographer* cryptographer = trans->GetCryptographer();
1145 if (!cryptographer || !cryptographer->is_ready()) 1144 if (!cryptographer || !cryptographer->is_ready())
1146 return; 1145 return;
1147 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans); 1146 syncable::ModelTypeSet encrypted_types = GetEncryptedTypes(trans);
1148 ModelSafeRoutingInfo routes; 1147 ModelSafeRoutingInfo routes;
1149 registrar_->GetModelSafeRoutingInfo(&routes); 1148 registrar_->GetModelSafeRoutingInfo(&routes);
1150 std::string tag; 1149 std::string tag;
1151 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin(); 1150 for (syncable::ModelTypeSet::iterator iter = encrypted_types.begin();
1152 iter != encrypted_types.end(); ++iter) { 1151 iter != encrypted_types.end(); ++iter) {
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 lookup->GetDownloadProgress(*i, &marker); 2086 lookup->GetDownloadProgress(*i, &marker);
2088 2087
2089 if (marker.token().empty()) 2088 if (marker.token().empty())
2090 result.insert(*i); 2089 result.insert(*i);
2091 2090
2092 } 2091 }
2093 return result; 2092 return result;
2094 } 2093 }
2095 2094
2096 } // namespace sync_api 2095 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698