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

Unified Diff: sync/engine/get_key_command.cc

Issue 10455012: [Sync] Add support for performing a GetKey on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/get_key_command.cc
diff --git a/sync/engine/get_key_command.cc b/sync/engine/get_key_command.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3e9401d5432b8a8098cc0a11fd0fd63fe954a0d6
--- /dev/null
+++ b/sync/engine/get_key_command.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/engine/get_key_command.h"
+
+#include "sync/engine/syncer_proto_util.h"
+#include "sync/protocol/sync.pb.h"
+#include "sync/sessions/sync_session.h"
+#include "sync/syncable/directory.h"
+#include "sync/syncable/read_transaction.h"
+#include "sync/util/cryptographer.h"
+
+using sync_pb::ClientToServerMessage;
+using sync_pb::ClientToServerResponse;
+
+namespace syncer {
+
+using sessions::SyncSession;
+
+GetKeyCommand::GetKeyCommand() {}
+
+GetKeyCommand::~GetKeyCommand() {}
+
+SyncerError GetKeyCommand::ExecuteImpl(SyncSession* session) {
+ ClientToServerMessage client_to_server_message;
+ ClientToServerResponse server_to_client_response;
+
+ if (!session->context()->keystore_encryption_enabled())
+ return SYNCER_OK;
+
+ SyncerProtoUtil::SetProtocolVersion(&client_to_server_message);
tim (not reviewing) 2012/07/19 21:42:03 Can we move this to PostClientToServerMessage?
Nicolas Zea 2012/07/24 22:51:24 Added TODO to do that in a follow-up patch.
+ client_to_server_message.set_share(session->context()->account_name());
+ client_to_server_message.set_message_contents(
+ sync_pb::ClientToServerMessage::GET_ENCRYPTION_KEY);
+ client_to_server_message.mutable_get_encryption_key();
+
+ SyncerProtoUtil::AddRequestBirthday(session->context()->directory(),
+ &client_to_server_message);
+
+ SyncerError result = SyncerProtoUtil::PostClientToServerMessage(
+ client_to_server_message,
+ &server_to_client_response,
+ session);
+
+ DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString(
+ server_to_client_response);
+
+ if (result != SYNCER_OK) {
+ LOG(ERROR) << "PostClientToServerMessage() failed during GetKey.";
+ return result;
+ }
+
+ syncable::Directory* dir = session->context()->directory();
+ syncable::ReadTransaction trans(FROM_HERE, dir);
+ Cryptographer* cryptographer =
+ session->context()->directory()->GetCryptographer(&trans);
+ bool success = cryptographer->SetKeystoreKey(
+ server_to_client_response.get_encryption_key().key());
+
+ DVLOG(1) << "GetKey returned key of length "
+ << server_to_client_response.get_encryption_key().key().length()
+ << ". Cryptographer keystore key "
+ << (success ? "" : "not ") << "updated.";
+
+ return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED);
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698