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

Side by Side Diff: chromeos/cryptohome/homedir_methods.cc

Issue 506943002: Wire up GetKeyDataEx() in Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@d_1_367847_move_to_mount_ex
Patch Set: Added missing OVERRIDE. Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « chromeos/cryptohome/homedir_methods.h ('k') | chromeos/cryptohome/homedir_methods_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromeos/cryptohome/homedir_methods.h" 5 #include "chromeos/cryptohome/homedir_methods.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h"
8 #include "chromeos/dbus/cryptohome/key.pb.h" 9 #include "chromeos/dbus/cryptohome/key.pb.h"
9 #include "chromeos/dbus/cryptohome/rpc.pb.h" 10 #include "chromeos/dbus/cryptohome/rpc.pb.h"
10 #include "chromeos/dbus/cryptohome_client.h" 11 #include "chromeos/dbus/cryptohome_client.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
12 13
14 #if defined(USE_SYSTEM_PROTOBUF)
15 #include <google/protobuf/repeated_field.h>
16 #else
17 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
18 #endif
19
13 using chromeos::DBusThreadManager; 20 using chromeos::DBusThreadManager;
21 using google::protobuf::RepeatedPtrField;
14 22
15 namespace cryptohome { 23 namespace cryptohome {
16 24
17 namespace { 25 namespace {
18 26
19 HomedirMethods* g_homedir_methods = NULL; 27 HomedirMethods* g_homedir_methods = NULL;
20 28
21 void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) { 29 void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) {
22 key->set_secret(key_def.key); 30 key->set_secret(key_def.key);
23 KeyData* data = key->mutable_data(); 31 KeyData* data = key->mutable_data();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 110 }
103 } 111 }
104 112
105 // The implementation of HomedirMethods 113 // The implementation of HomedirMethods
106 class HomedirMethodsImpl : public HomedirMethods { 114 class HomedirMethodsImpl : public HomedirMethods {
107 public: 115 public:
108 HomedirMethodsImpl() : weak_ptr_factory_(this) {} 116 HomedirMethodsImpl() : weak_ptr_factory_(this) {}
109 117
110 virtual ~HomedirMethodsImpl() {} 118 virtual ~HomedirMethodsImpl() {}
111 119
120 virtual void GetKeyDataEx(const Identification& id,
121 const std::string& label,
122 const GetKeyDataCallback& callback) OVERRIDE {
123 cryptohome::AccountIdentifier id_proto;
124 cryptohome::AuthorizationRequest kEmptyAuthProto;
125 cryptohome::GetKeyDataRequest request;
126
127 FillIdentificationProtobuf(id, &id_proto);
128 request.mutable_key()->mutable_data()->set_label(label);
129
130 DBusThreadManager::Get()->GetCryptohomeClient()->GetKeyDataEx(
131 id_proto,
132 kEmptyAuthProto,
133 request,
134 base::Bind(&HomedirMethodsImpl::OnGetKeyDataExCallback,
135 weak_ptr_factory_.GetWeakPtr(),
136 callback));
137 }
138
112 virtual void CheckKeyEx(const Identification& id, 139 virtual void CheckKeyEx(const Identification& id,
113 const Authorization& auth, 140 const Authorization& auth,
114 const Callback& callback) OVERRIDE { 141 const Callback& callback) OVERRIDE {
115 cryptohome::AccountIdentifier id_proto; 142 cryptohome::AccountIdentifier id_proto;
116 cryptohome::AuthorizationRequest auth_proto; 143 cryptohome::AuthorizationRequest auth_proto;
117 cryptohome::CheckKeyRequest request; 144 cryptohome::CheckKeyRequest request;
118 145
119 FillIdentificationProtobuf(id, &id_proto); 146 FillIdentificationProtobuf(id, &id_proto);
120 FillAuthorizationProtobuf(auth, &auth_proto); 147 FillAuthorizationProtobuf(auth, &auth_proto);
121 148
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DBusThreadManager::Get()->GetCryptohomeClient()->UpdateKeyEx( 245 DBusThreadManager::Get()->GetCryptohomeClient()->UpdateKeyEx(
219 id_proto, 246 id_proto,
220 auth_proto, 247 auth_proto,
221 pb_update_key, 248 pb_update_key,
222 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback, 249 base::Bind(&HomedirMethodsImpl::OnBaseReplyCallback,
223 weak_ptr_factory_.GetWeakPtr(), 250 weak_ptr_factory_.GetWeakPtr(),
224 callback)); 251 callback));
225 } 252 }
226 253
227 private: 254 private:
255 void OnGetKeyDataExCallback(const GetKeyDataCallback& callback,
256 chromeos::DBusMethodCallStatus call_status,
257 bool result,
258 const BaseReply& reply) {
259 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
260 callback.Run(false, MOUNT_ERROR_FATAL, ScopedVector<RetrievedKeyData>());
261 return;
262 }
263 if (reply.has_error()) {
264 if (reply.error() != CRYPTOHOME_ERROR_NOT_SET) {
265 callback.Run(false,
266 MapError(reply.error()),
267 ScopedVector<RetrievedKeyData>());
268 return;
269 }
270 }
271
272 if (!reply.HasExtension(GetKeyDataReply::reply)) {
273 callback.Run(false, MOUNT_ERROR_FATAL, ScopedVector<RetrievedKeyData>());
274 return;
275 }
276
277 // Extract the contents of the |KeyData| protos returned.
278 const RepeatedPtrField<KeyData>& key_data_proto =
279 reply.GetExtension(GetKeyDataReply::reply).key_data();
280 ScopedVector<RetrievedKeyData> key_data_list;
281 for (RepeatedPtrField<KeyData>::const_iterator it = key_data_proto.begin();
282 it != key_data_proto.end(); ++it) {
283
284 // Extract |type|, |label| and |revision|.
285 DCHECK_EQ(KeyData::KEY_TYPE_PASSWORD, it->type());
286 key_data_list.push_back(new RetrievedKeyData(
287 RetrievedKeyData::TYPE_PASSWORD,
288 it->label(),
289 it->revision()));
290 RetrievedKeyData* key_data = key_data_list.back();
291
292 // Extract |privileges|.
293 const KeyPrivileges& privileges = it->privileges();
294 if (privileges.mount())
295 key_data->privileges |= PRIV_MOUNT;
296 if (privileges.add())
297 key_data->privileges |= PRIV_ADD;
298 if (privileges.remove())
299 key_data->privileges |= PRIV_REMOVE;
300 if (privileges.update())
301 key_data->privileges |= PRIV_MIGRATE;
302 if (privileges.authorized_update())
303 key_data->privileges |= PRIV_AUTHORIZED_UPDATE;
304
305 // Extract |authorization_data|.
306 for (RepeatedPtrField<KeyAuthorizationData>::const_iterator auth_it =
307 it->authorization_data().begin();
308 auth_it != it->authorization_data().end(); ++auth_it) {
309 switch (auth_it->type()) {
310 case KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_HMACSHA256:
311 key_data->authorization_types.push_back(
312 RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256);
313 break;
314 case KeyAuthorizationData::
315 KEY_AUTHORIZATION_TYPE_AES256CBC_HMACSHA256:
316 key_data->authorization_types.push_back(
317 RetrievedKeyData::AUTHORIZATION_TYPE_AES256CBC_HMACSHA256);
318 break;
319 default:
320 NOTREACHED();
321 break;
322 }
323 }
324
325 // Extract |provider_data|.
326 for (RepeatedPtrField<KeyProviderData::Entry>::const_iterator
327 provider_data_it = it->provider_data().entry().begin();
328 provider_data_it != it->provider_data().entry().end();
329 ++provider_data_it) {
330 // Extract |name|.
331 key_data->provider_data.push_back(
332 new RetrievedKeyData::ProviderData(provider_data_it->name()));
333 RetrievedKeyData::ProviderData* provider_data =
334 key_data->provider_data.back();
335
336 int data_items = 0;
337
338 // Extract |number|.
339 if (provider_data_it->has_number()) {
340 provider_data->number.reset(new int64(provider_data_it->number()));
341 ++data_items;
342 }
343
344 // Extract |bytes|.
345 if (provider_data_it->has_bytes()) {
346 provider_data->bytes.reset(
347 new std::string(provider_data_it->bytes()));
348 ++data_items;
349 }
350
351 DCHECK_EQ(1, data_items);
352 }
353 }
354
355 callback.Run(true, MOUNT_ERROR_NONE, key_data_list.Pass());
356 }
357
228 void OnMountExCallback(const MountCallback& callback, 358 void OnMountExCallback(const MountCallback& callback,
229 chromeos::DBusMethodCallStatus call_status, 359 chromeos::DBusMethodCallStatus call_status,
230 bool result, 360 bool result,
231 const BaseReply& reply) { 361 const BaseReply& reply) {
232 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 362 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
233 callback.Run(false, MOUNT_ERROR_FATAL, std::string()); 363 callback.Run(false, MOUNT_ERROR_FATAL, std::string());
234 return; 364 return;
235 } 365 }
236 if (reply.has_error()) { 366 if (reply.has_error()) {
237 if (reply.error() != CRYPTOHOME_ERROR_NOT_SET) { 367 if (reply.error() != CRYPTOHOME_ERROR_NOT_SET) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 431 }
302 delete g_homedir_methods; 432 delete g_homedir_methods;
303 g_homedir_methods = NULL; 433 g_homedir_methods = NULL;
304 VLOG(1) << "HomedirMethods Shutdown completed"; 434 VLOG(1) << "HomedirMethods Shutdown completed";
305 } 435 }
306 436
307 // static 437 // static
308 HomedirMethods* HomedirMethods::GetInstance() { return g_homedir_methods; } 438 HomedirMethods* HomedirMethods::GetInstance() { return g_homedir_methods; }
309 439
310 } // namespace cryptohome 440 } // namespace cryptohome
OLDNEW
« no previous file with comments | « chromeos/cryptohome/homedir_methods.h ('k') | chromeos/cryptohome/homedir_methods_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698