| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 "migrate_key", | 42 "migrate_key", |
| 43 "remove", | 43 "remove", |
| 44 "obfuscate_user", | 44 "obfuscate_user", |
| 45 "dump_keyset", | 45 "dump_keyset", |
| 46 "tpm_status", | 46 "tpm_status", |
| 47 "status", | 47 "status", |
| 48 "remove_tracked_subdirs", | 48 "remove_tracked_subdirs", |
| 49 "tpm_take_ownership", | 49 "tpm_take_ownership", |
| 50 "tpm_clear_stored_password", | 50 "tpm_clear_stored_password", |
| 51 "tpm_wait_ownership", | 51 "tpm_wait_ownership", |
| 52 "lockbox_test", |
| 52 NULL }; | 53 NULL }; |
| 53 enum ActionEnum { | 54 enum ActionEnum { |
| 54 ACTION_MOUNT, | 55 ACTION_MOUNT, |
| 55 ACTION_MOUNT_GUEST, | 56 ACTION_MOUNT_GUEST, |
| 56 ACTION_UNMOUNT, | 57 ACTION_UNMOUNT, |
| 57 ACTION_MOUNTED, | 58 ACTION_MOUNTED, |
| 58 ACTION_TEST_AUTH, | 59 ACTION_TEST_AUTH, |
| 59 ACTION_MIGRATE_KEY, | 60 ACTION_MIGRATE_KEY, |
| 60 ACTION_REMOVE, | 61 ACTION_REMOVE, |
| 61 ACTION_OBFUSCATE_USER, | 62 ACTION_OBFUSCATE_USER, |
| 62 ACTION_DUMP_KEYSET, | 63 ACTION_DUMP_KEYSET, |
| 63 ACTION_TPM_STATUS, | 64 ACTION_TPM_STATUS, |
| 64 ACTION_STATUS, | 65 ACTION_STATUS, |
| 65 ACTION_REMOVE_TRACKED_SUBDIRS, | 66 ACTION_REMOVE_TRACKED_SUBDIRS, |
| 66 ACTION_TPM_TAKE_OWNERSHIP, | 67 ACTION_TPM_TAKE_OWNERSHIP, |
| 67 ACTION_TPM_CLEAR_STORED_PASSWORD, | 68 ACTION_TPM_CLEAR_STORED_PASSWORD, |
| 68 ACTION_TPM_WAIT_OWNERSHIP }; | 69 ACTION_TPM_WAIT_OWNERSHIP, |
| 70 ACTION_LOCKBOX_TEST }; |
| 69 static const char kUserSwitch[] = "user"; | 71 static const char kUserSwitch[] = "user"; |
| 70 static const char kPasswordSwitch[] = "password"; | 72 static const char kPasswordSwitch[] = "password"; |
| 71 static const char kOldPasswordSwitch[] = "old_password"; | 73 static const char kOldPasswordSwitch[] = "old_password"; |
| 72 static const char kForceSwitch[] = "force"; | 74 static const char kForceSwitch[] = "force"; |
| 73 static const char kAsyncSwitch[] = "async"; | 75 static const char kAsyncSwitch[] = "async"; |
| 74 static const char kCreateSwitch[] = "create"; | 76 static const char kCreateSwitch[] = "create"; |
| 75 } // namespace switches | 77 } // namespace switches |
| 76 | 78 |
| 77 chromeos::Blob GetSystemSalt(const chromeos::dbus::Proxy& proxy) { | 79 chromeos::Blob GetSystemSalt(const chromeos::dbus::Proxy& proxy) { |
| 78 chromeos::glib::ScopedError error; | 80 chromeos::glib::ScopedError error; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } else if (!strcmp( | 664 } else if (!strcmp( |
| 663 switches::kActions[switches::ACTION_TPM_CLEAR_STORED_PASSWORD], | 665 switches::kActions[switches::ACTION_TPM_CLEAR_STORED_PASSWORD], |
| 664 action.c_str())) { | 666 action.c_str())) { |
| 665 chromeos::glib::ScopedError error; | 667 chromeos::glib::ScopedError error; |
| 666 if (!org_chromium_CryptohomeInterface_tpm_clear_stored_password( | 668 if (!org_chromium_CryptohomeInterface_tpm_clear_stored_password( |
| 667 proxy.gproxy(), | 669 proxy.gproxy(), |
| 668 &chromeos::Resetter(&error).lvalue())) { | 670 &chromeos::Resetter(&error).lvalue())) { |
| 669 printf("TpmClearStoredPassword call failed: %s.\n", error->message); | 671 printf("TpmClearStoredPassword call failed: %s.\n", error->message); |
| 670 } | 672 } |
| 671 } else if (!strcmp( | 673 } else if (!strcmp( |
| 674 switches::kActions[switches::ACTION_LOCKBOX_TEST], |
| 675 action.c_str())) { |
| 676 chromeos::glib::ScopedError error; |
| 677 gboolean result; |
| 678 if (!org_chromium_CryptohomeInterface_lockbox_is_ready( |
| 679 proxy.gproxy(), |
| 680 &result, |
| 681 &chromeos::Resetter(&error).lvalue())) { |
| 682 printf("LockboxIsReady call failed: %s.\n", error->message); |
| 683 } |
| 684 if (result == FALSE) { |
| 685 printf("Lockbox not ready for use.\n"); |
| 686 return 1; |
| 687 } |
| 688 printf("Lockbox is ready\n"); |
| 689 if (!org_chromium_CryptohomeInterface_lockbox_is_locked( |
| 690 proxy.gproxy(), |
| 691 &result, |
| 692 &chromeos::Resetter(&error).lvalue())) { |
| 693 printf("LockboxIsLocked call failed: %s.\n", error->message); |
| 694 } |
| 695 bool locked = result; |
| 696 printf("Lockbox is locked: %d\n", result); |
| 697 const char* kTestNameA = "LockboxTest.IsManaged"; |
| 698 const char* kTestValueA = "TRUE"; |
| 699 const char* kTestNameB = "LockboxTest.Foo"; |
| 700 const char* kTestValueB = "Bar"; |
| 701 if (result == FALSE) { |
| 702 // Set a value! |
| 703 GArray *value = g_array_new(FALSE, FALSE, sizeof(char)); |
| 704 g_array_append_vals(value, kTestValueA, strlen(kTestValueA)); |
| 705 if (!org_chromium_CryptohomeInterface_lockbox_set( |
| 706 proxy.gproxy(), |
| 707 kTestNameA, |
| 708 value, |
| 709 &result, |
| 710 &chromeos::Resetter(&error).lvalue())) { |
| 711 printf("LockboxSet call failed: %s.\n", error->message); |
| 712 } |
| 713 g_array_free(value, false); |
| 714 printf("LockboxSet(%s,%s): %d\n", kTestNameA, kTestValueA, result); |
| 715 // Set a value! |
| 716 value = g_array_new(FALSE, FALSE, sizeof(char)); |
| 717 g_array_append_vals(value, kTestValueB, strlen(kTestValueB)); |
| 718 if (!org_chromium_CryptohomeInterface_lockbox_set( |
| 719 proxy.gproxy(), |
| 720 kTestNameB, |
| 721 value, |
| 722 &result, |
| 723 &chromeos::Resetter(&error).lvalue())) { |
| 724 printf("LockboxSet call failed: %s.\n", error->message); |
| 725 } |
| 726 g_array_free(value, false); |
| 727 printf("LockboxSet(%s,%s): %d\n", kTestNameB, kTestValueB, result); |
| 728 } |
| 729 // Grab the value and emit it. |
| 730 // Set a value! |
| 731 GArray *value = NULL; |
| 732 if (!org_chromium_CryptohomeInterface_lockbox_get( |
| 733 proxy.gproxy(), |
| 734 kTestNameA, |
| 735 &value, |
| 736 &result, |
| 737 &chromeos::Resetter(&error).lvalue())) { |
| 738 printf("LockboxGet call failed: %s.\n", error->message); |
| 739 } |
| 740 std::string value_str(value->data, value->len); |
| 741 printf("LockboxGet(%s,%s): %d\n", kTestNameA, value_str.c_str(), result); |
| 742 g_array_free(value, false); |
| 743 if (locked) |
| 744 return 0; |
| 745 // Lock it down. |
| 746 if (!org_chromium_CryptohomeInterface_lockbox_lock( |
| 747 proxy.gproxy(), |
| 748 &result, |
| 749 &chromeos::Resetter(&error).lvalue())) { |
| 750 printf("LockboxLock call failed: %s.\n", error->message); |
| 751 } |
| 752 printf("Lockbox has been locked (%d).\n", result); |
| 753 } else if (!strcmp( |
| 672 switches::kActions[switches::ACTION_TPM_WAIT_OWNERSHIP], | 754 switches::kActions[switches::ACTION_TPM_WAIT_OWNERSHIP], |
| 673 action.c_str())) { | 755 action.c_str())) { |
| 674 TpmWaitLoop client_loop; | 756 TpmWaitLoop client_loop; |
| 675 client_loop.Initialize(proxy); | 757 client_loop.Initialize(proxy); |
| 676 gboolean result; | 758 gboolean result; |
| 677 chromeos::glib::ScopedError error; | 759 chromeos::glib::ScopedError error; |
| 678 if (!org_chromium_CryptohomeInterface_tpm_is_being_owned(proxy.gproxy(), | 760 if (!org_chromium_CryptohomeInterface_tpm_is_being_owned(proxy.gproxy(), |
| 679 &result, | 761 &result, |
| 680 &chromeos::Resetter(&error).lvalue())) { | 762 &chromeos::Resetter(&error).lvalue())) { |
| 681 printf("TpmIsBeingOwned call failed: %s.\n", error->message); | 763 printf("TpmIsBeingOwned call failed: %s.\n", error->message); |
| 682 } else { | 764 } else { |
| 683 if (result) { | 765 if (result) { |
| 684 printf("Waiting for TPM to be owned...\n"); | 766 printf("Waiting for TPM to be owned...\n"); |
| 685 client_loop.Run(); | 767 client_loop.Run(); |
| 686 } else { | 768 } else { |
| 687 printf("TPM is not currently being owned.\n"); | 769 printf("TPM is not currently being owned.\n"); |
| 688 } | 770 } |
| 689 } | 771 } |
| 690 } else { | 772 } else { |
| 691 printf("Unknown action or no action given. Available actions:\n"); | 773 printf("Unknown action or no action given. Available actions:\n"); |
| 692 for(int i = 0; /* loop forever */; i++) { | 774 for(int i = 0; /* loop forever */; i++) { |
| 693 if(!switches::kActions[i]) { | 775 if(!switches::kActions[i]) { |
| 694 break; | 776 break; |
| 695 } | 777 } |
| 696 printf(" --action=%s\n", switches::kActions[i]); | 778 printf(" --action=%s\n", switches::kActions[i]); |
| 697 } | 779 } |
| 698 } | 780 } |
| 699 return 0; | 781 return 0; |
| 700 } | 782 } |
| OLD | NEW |