| Index: cryptohome.cc
|
| diff --git a/cryptohome.cc b/cryptohome.cc
|
| index d8aea4ac5f1f5e3a47a3f841ec69d6ca06c8f14a..27e9bfcf03efda119bd3aa0f35c645d01ceb725d 100644
|
| --- a/cryptohome.cc
|
| +++ b/cryptohome.cc
|
| @@ -49,6 +49,7 @@ namespace switches {
|
| "tpm_take_ownership",
|
| "tpm_clear_stored_password",
|
| "tpm_wait_ownership",
|
| + "lockbox_test",
|
| NULL };
|
| enum ActionEnum {
|
| ACTION_MOUNT,
|
| @@ -65,7 +66,8 @@ namespace switches {
|
| ACTION_REMOVE_TRACKED_SUBDIRS,
|
| ACTION_TPM_TAKE_OWNERSHIP,
|
| ACTION_TPM_CLEAR_STORED_PASSWORD,
|
| - ACTION_TPM_WAIT_OWNERSHIP };
|
| + ACTION_TPM_WAIT_OWNERSHIP,
|
| + ACTION_LOCKBOX_TEST };
|
| static const char kUserSwitch[] = "user";
|
| static const char kPasswordSwitch[] = "password";
|
| static const char kOldPasswordSwitch[] = "old_password";
|
| @@ -669,6 +671,86 @@ int main(int argc, char **argv) {
|
| printf("TpmClearStoredPassword call failed: %s.\n", error->message);
|
| }
|
| } else if (!strcmp(
|
| + switches::kActions[switches::ACTION_LOCKBOX_TEST],
|
| + action.c_str())) {
|
| + chromeos::glib::ScopedError error;
|
| + gboolean result;
|
| + if (!org_chromium_CryptohomeInterface_lockbox_is_ready(
|
| + proxy.gproxy(),
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxIsReady call failed: %s.\n", error->message);
|
| + }
|
| + if (result == FALSE) {
|
| + printf("Lockbox not ready for use.\n");
|
| + return 1;
|
| + }
|
| + printf("Lockbox is ready\n");
|
| + if (!org_chromium_CryptohomeInterface_lockbox_is_locked(
|
| + proxy.gproxy(),
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxIsLocked call failed: %s.\n", error->message);
|
| + }
|
| + bool locked = result;
|
| + printf("Lockbox is locked: %d\n", result);
|
| + const char* kTestNameA = "LockboxTest.IsManaged";
|
| + const char* kTestValueA = "TRUE";
|
| + const char* kTestNameB = "LockboxTest.Foo";
|
| + const char* kTestValueB = "Bar";
|
| + if (result == FALSE) {
|
| + // Set a value!
|
| + GArray *value = g_array_new(FALSE, FALSE, sizeof(char));
|
| + g_array_append_vals(value, kTestValueA, strlen(kTestValueA));
|
| + if (!org_chromium_CryptohomeInterface_lockbox_set(
|
| + proxy.gproxy(),
|
| + kTestNameA,
|
| + value,
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxSet call failed: %s.\n", error->message);
|
| + }
|
| + g_array_free(value, false);
|
| + printf("LockboxSet(%s,%s): %d\n", kTestNameA, kTestValueA, result);
|
| + // Set a value!
|
| + value = g_array_new(FALSE, FALSE, sizeof(char));
|
| + g_array_append_vals(value, kTestValueB, strlen(kTestValueB));
|
| + if (!org_chromium_CryptohomeInterface_lockbox_set(
|
| + proxy.gproxy(),
|
| + kTestNameB,
|
| + value,
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxSet call failed: %s.\n", error->message);
|
| + }
|
| + g_array_free(value, false);
|
| + printf("LockboxSet(%s,%s): %d\n", kTestNameB, kTestValueB, result);
|
| + }
|
| + // Grab the value and emit it.
|
| + // Set a value!
|
| + GArray *value = NULL;
|
| + if (!org_chromium_CryptohomeInterface_lockbox_get(
|
| + proxy.gproxy(),
|
| + kTestNameA,
|
| + &value,
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxGet call failed: %s.\n", error->message);
|
| + }
|
| + std::string value_str(value->data, value->len);
|
| + printf("LockboxGet(%s,%s): %d\n", kTestNameA, value_str.c_str(), result);
|
| + g_array_free(value, false);
|
| + if (locked)
|
| + return 0;
|
| + // Lock it down.
|
| + if (!org_chromium_CryptohomeInterface_lockbox_lock(
|
| + proxy.gproxy(),
|
| + &result,
|
| + &chromeos::Resetter(&error).lvalue())) {
|
| + printf("LockboxLock call failed: %s.\n", error->message);
|
| + }
|
| + printf("Lockbox has been locked (%d).\n", result);
|
| + } else if (!strcmp(
|
| switches::kActions[switches::ACTION_TPM_WAIT_OWNERSHIP],
|
| action.c_str())) {
|
| TpmWaitLoop client_loop;
|
|
|