Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sync/engine/get_key_command.h" | |
| 6 | |
| 7 #include "sync/engine/syncer_proto_util.h" | |
| 8 #include "sync/protocol/sync.pb.h" | |
| 9 #include "sync/sessions/sync_session.h" | |
| 10 #include "sync/syncable/directory.h" | |
| 11 #include "sync/syncable/read_transaction.h" | |
| 12 #include "sync/util/cryptographer.h" | |
| 13 | |
| 14 using sync_pb::ClientToServerMessage; | |
| 15 using sync_pb::ClientToServerResponse; | |
| 16 | |
| 17 namespace syncer { | |
| 18 | |
| 19 using sessions::SyncSession; | |
| 20 | |
| 21 GetKeyCommand::GetKeyCommand() {} | |
| 22 | |
| 23 GetKeyCommand::~GetKeyCommand() {} | |
| 24 | |
| 25 SyncerError GetKeyCommand::ExecuteImpl(SyncSession* session) { | |
| 26 ClientToServerMessage client_to_server_message; | |
| 27 ClientToServerResponse server_to_client_response; | |
| 28 | |
| 29 if (!session->context()->keystore_encryption_enabled()) | |
| 30 return SYNCER_OK; | |
| 31 | |
| 32 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.
| |
| 33 client_to_server_message.set_share(session->context()->account_name()); | |
| 34 client_to_server_message.set_message_contents( | |
| 35 sync_pb::ClientToServerMessage::GET_ENCRYPTION_KEY); | |
| 36 client_to_server_message.mutable_get_encryption_key(); | |
| 37 | |
| 38 SyncerProtoUtil::AddRequestBirthday(session->context()->directory(), | |
| 39 &client_to_server_message); | |
| 40 | |
| 41 SyncerError result = SyncerProtoUtil::PostClientToServerMessage( | |
| 42 client_to_server_message, | |
| 43 &server_to_client_response, | |
| 44 session); | |
| 45 | |
| 46 DVLOG(2) << SyncerProtoUtil::ClientToServerResponseDebugString( | |
| 47 server_to_client_response); | |
| 48 | |
| 49 if (result != SYNCER_OK) { | |
| 50 LOG(ERROR) << "PostClientToServerMessage() failed during GetKey."; | |
| 51 return result; | |
| 52 } | |
| 53 | |
| 54 syncable::Directory* dir = session->context()->directory(); | |
| 55 syncable::ReadTransaction trans(FROM_HERE, dir); | |
| 56 Cryptographer* cryptographer = | |
| 57 session->context()->directory()->GetCryptographer(&trans); | |
| 58 bool success = cryptographer->SetKeystoreKey( | |
| 59 server_to_client_response.get_encryption_key().key()); | |
| 60 | |
| 61 DVLOG(1) << "GetKey returned key of length " | |
| 62 << server_to_client_response.get_encryption_key().key().length() | |
| 63 << ". Cryptographer keystore key " | |
| 64 << (success ? "" : "not ") << "updated."; | |
| 65 | |
| 66 return (success ? SYNCER_OK : SERVER_RESPONSE_VALIDATION_FAILED); | |
| 67 } | |
| 68 | |
| 69 } // namespace syncer | |
| OLD | NEW |