OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 // Cryptohome client that uses the dbus client interface | 5 // Cryptohome client that uses the dbus client interface |
6 | 6 |
7 #include <openssl/err.h> | 7 #include <openssl/err.h> |
8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
9 #include <openssl/rand.h> | 9 #include <openssl/rand.h> |
10 #include <openssl/sha.h> | 10 #include <openssl/sha.h> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 ACTION_REMOVE_TRACKED_SUBDIRS, | 65 ACTION_REMOVE_TRACKED_SUBDIRS, |
66 ACTION_TPM_TAKE_OWNERSHIP, | 66 ACTION_TPM_TAKE_OWNERSHIP, |
67 ACTION_TPM_CLEAR_STORED_PASSWORD, | 67 ACTION_TPM_CLEAR_STORED_PASSWORD, |
68 ACTION_TPM_WAIT_OWNERSHIP }; | 68 ACTION_TPM_WAIT_OWNERSHIP }; |
69 static const char kUserSwitch[] = "user"; | 69 static const char kUserSwitch[] = "user"; |
70 static const char kPasswordSwitch[] = "password"; | 70 static const char kPasswordSwitch[] = "password"; |
71 static const char kOldPasswordSwitch[] = "old_password"; | 71 static const char kOldPasswordSwitch[] = "old_password"; |
72 static const char kForceSwitch[] = "force"; | 72 static const char kForceSwitch[] = "force"; |
73 static const char kAsyncSwitch[] = "async"; | 73 static const char kAsyncSwitch[] = "async"; |
74 static const char kCreateSwitch[] = "create"; | 74 static const char kCreateSwitch[] = "create"; |
75 static const char kTrackedDirsSwitch[] = "tracked_dirs"; | |
76 } // namespace switches | 75 } // namespace switches |
77 | 76 |
78 chromeos::Blob GetSystemSalt(const chromeos::dbus::Proxy& proxy) { | 77 chromeos::Blob GetSystemSalt(const chromeos::dbus::Proxy& proxy) { |
79 chromeos::glib::ScopedError error; | 78 chromeos::glib::ScopedError error; |
80 GArray* salt; | 79 GArray* salt; |
81 if (!org_chromium_CryptohomeInterface_get_system_salt(proxy.gproxy(), | 80 if (!org_chromium_CryptohomeInterface_get_system_salt(proxy.gproxy(), |
82 &salt, | 81 &salt, |
83 &chromeos::Resetter(&error).lvalue())) { | 82 &chromeos::Resetter(&error).lvalue())) { |
84 LOG(ERROR) << "GetSystemSalt failed: " << error->message; | 83 LOG(ERROR) << "GetSystemSalt failed: " << error->message; |
85 return chromeos::Blob(); | 84 return chromeos::Blob(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 284 |
286 if (!GetUsername(cl, &user)) { | 285 if (!GetUsername(cl, &user)) { |
287 printf("No username specified.\n"); | 286 printf("No username specified.\n"); |
288 return 1; | 287 return 1; |
289 } | 288 } |
290 | 289 |
291 GetPassword(proxy, cl, switches::kPasswordSwitch, | 290 GetPassword(proxy, cl, switches::kPasswordSwitch, |
292 StringPrintf("Enter the password for <%s>", user.c_str()), | 291 StringPrintf("Enter the password for <%s>", user.c_str()), |
293 &password); | 292 &password); |
294 | 293 |
295 const char** tracked_subdirectories = NULL; | |
296 // Defined outside to keep the values in-scope for use in the functions | |
297 // below | |
298 std::vector<std::string> tracked_dirs; | |
299 if (cl->HasSwitch(switches::kTrackedDirsSwitch)) { | |
300 SplitString(cl->GetSwitchValueASCII(switches::kTrackedDirsSwitch), ',', | |
301 &tracked_dirs); | |
302 tracked_subdirectories = new const char*[tracked_dirs.size() + 1]; | |
303 int i = 0; | |
304 for (std::vector<std::string>::const_iterator itr = tracked_dirs.begin(); | |
305 itr != tracked_dirs.end(); itr++, i++) { | |
306 tracked_subdirectories[i] = itr->c_str(); | |
307 } | |
308 tracked_subdirectories[i] = NULL; | |
309 } | |
310 | |
311 gboolean done = false; | 294 gboolean done = false; |
312 gint mount_error = 0; | 295 gint mount_error = 0; |
313 chromeos::glib::ScopedError error; | 296 chromeos::glib::ScopedError error; |
314 | 297 |
315 if (!cl->HasSwitch(switches::kAsyncSwitch)) { | 298 if (!cl->HasSwitch(switches::kAsyncSwitch)) { |
316 if (!org_chromium_CryptohomeInterface_mount(proxy.gproxy(), | 299 if (!org_chromium_CryptohomeInterface_mount(proxy.gproxy(), |
317 user.c_str(), | 300 user.c_str(), |
318 password.c_str(), | 301 password.c_str(), |
319 cl->HasSwitch(switches::kCreateSwitch), | 302 cl->HasSwitch(switches::kCreateSwitch), |
320 (tracked_subdirectories != NULL), | 303 false, |
321 tracked_subdirectories, | 304 NULL, |
322 &mount_error, | 305 &mount_error, |
323 &done, | 306 &done, |
324 &chromeos::Resetter(&error).lvalue())) { | 307 &chromeos::Resetter(&error).lvalue())) { |
325 printf("Mount call failed: %s, with reason code: %d.\n", error->message, | 308 printf("Mount call failed: %s, with reason code: %d.\n", error->message, |
326 mount_error); | 309 mount_error); |
327 } | 310 } |
328 } else { | 311 } else { |
329 ClientLoop client_loop; | 312 ClientLoop client_loop; |
330 client_loop.Initialize(proxy); | 313 client_loop.Initialize(proxy); |
331 gint async_id = -1; | 314 gint async_id = -1; |
332 if (!org_chromium_CryptohomeInterface_async_mount(proxy.gproxy(), | 315 if (!org_chromium_CryptohomeInterface_async_mount(proxy.gproxy(), |
333 user.c_str(), | 316 user.c_str(), |
334 password.c_str(), | 317 password.c_str(), |
335 cl->HasSwitch(switches::kCreateSwitch), | 318 cl->HasSwitch(switches::kCreateSwitch), |
336 (tracked_subdirectories != NULL), | 319 false, |
337 tracked_subdirectories, | 320 NULL, |
338 &async_id, | 321 &async_id, |
339 &chromeos::Resetter(&error).lvalue())) { | 322 &chromeos::Resetter(&error).lvalue())) { |
340 printf("Mount call failed: %s.\n", error->message); | 323 printf("Mount call failed: %s.\n", error->message); |
341 } else { | 324 } else { |
342 client_loop.Run(async_id); | 325 client_loop.Run(async_id); |
343 done = client_loop.get_return_status(); | 326 done = client_loop.get_return_status(); |
344 } | 327 } |
345 } | 328 } |
346 if (tracked_subdirectories) { | |
347 delete(tracked_subdirectories); | |
348 } | |
349 if (!done) { | 329 if (!done) { |
350 printf("Mount failed.\n"); | 330 printf("Mount failed.\n"); |
351 } else { | 331 } else { |
352 printf("Mount succeeded.\n"); | 332 printf("Mount succeeded.\n"); |
353 } | 333 } |
354 } else if (!strcmp(switches::kActions[switches::ACTION_MOUNT_GUEST], | 334 } else if (!strcmp(switches::kActions[switches::ACTION_MOUNT_GUEST], |
355 action.c_str())) { | 335 action.c_str())) { |
356 gboolean done = false; | 336 gboolean done = false; |
357 gint mount_error = 0; | 337 gint mount_error = 0; |
358 chromeos::glib::ScopedError error; | 338 chromeos::glib::ScopedError error; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 blob.resize(serialized.tpm_public_key_hash().length()); | 573 blob.resize(serialized.tpm_public_key_hash().length()); |
594 serialized.tpm_public_key_hash().copy(static_cast<char*>(blob.data()), | 574 serialized.tpm_public_key_hash().copy(static_cast<char*>(blob.data()), |
595 serialized.tpm_key().length(), 0); | 575 serialized.tpm_key().length(), 0); |
596 printf(" TPM Public Key Hash:\n"); | 576 printf(" TPM Public Key Hash:\n"); |
597 printf(" %s\n", chromeos::AsciiEncode(blob).c_str()); | 577 printf(" %s\n", chromeos::AsciiEncode(blob).c_str()); |
598 } | 578 } |
599 if (serialized.has_password_rounds()) { | 579 if (serialized.has_password_rounds()) { |
600 printf(" Password rounds:\n"); | 580 printf(" Password rounds:\n"); |
601 printf(" %d\n", serialized.password_rounds()); | 581 printf(" %d\n", serialized.password_rounds()); |
602 } | 582 } |
603 if (serialized.tracked_subdirectories_size()) { | |
604 printf(" Tracked subdirectories:\n"); | |
605 for (int index = 0; index < serialized.tracked_subdirectories_size(); | |
606 index++) { | |
607 printf(" %s\n", serialized.tracked_subdirectories(index).c_str()); | |
608 } | |
609 } | |
610 } else if (!strcmp(switches::kActions[switches::ACTION_TPM_STATUS], | 583 } else if (!strcmp(switches::kActions[switches::ACTION_TPM_STATUS], |
611 action.c_str())) { | 584 action.c_str())) { |
612 chromeos::glib::ScopedError error; | 585 chromeos::glib::ScopedError error; |
613 gboolean result = false; | 586 gboolean result = false; |
614 if (!org_chromium_CryptohomeInterface_tpm_is_enabled(proxy.gproxy(), | 587 if (!org_chromium_CryptohomeInterface_tpm_is_enabled(proxy.gproxy(), |
615 &result, | 588 &result, |
616 &chromeos::Resetter(&error).lvalue())) { | 589 &chromeos::Resetter(&error).lvalue())) { |
617 printf("TpmIsEnabled call failed: %s.\n", error->message); | 590 printf("TpmIsEnabled call failed: %s.\n", error->message); |
618 } else { | 591 } else { |
619 printf("TPM Enabled: %s\n", (result ? "true" : "false")); | 592 printf("TPM Enabled: %s\n", (result ? "true" : "false")); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 printf("Unknown action or no action given. Available actions:\n"); | 691 printf("Unknown action or no action given. Available actions:\n"); |
719 for(int i = 0; /* loop forever */; i++) { | 692 for(int i = 0; /* loop forever */; i++) { |
720 if(!switches::kActions[i]) { | 693 if(!switches::kActions[i]) { |
721 break; | 694 break; |
722 } | 695 } |
723 printf(" --action=%s\n", switches::kActions[i]); | 696 printf(" --action=%s\n", switches::kActions[i]); |
724 } | 697 } |
725 } | 698 } |
726 return 0; | 699 return 0; |
727 } | 700 } |
OLD | NEW |