int main(int argc, char** argv) {
  uint32_t perm;
  uint32_t result;
  uint32_t x;

  TlclLibInit();

  TPM_CHECK(TlclStartupIfNeeded());
  TPM_CHECK(TlclSelfTestFull());
  TPM_CHECK(TlclAssertPhysicalPresence());
  TPM_CHECK(TlclForceClear());
  TPM_CHECK(TlclSetEnable());
  TPM_CHECK(TlclSetDeactivated(0));

  result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x));
  if (result == TPM_E_BADINDEX) {
    perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
    TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
  }

  result = TlclRead(INDEX1, (uint8_t*) &x, sizeof(x));
  if (result == TPM_E_BADINDEX) {
    perm = TPM_NV_PER_PPWRITE;
    TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
  }

  printf("TEST SUCCEEDED\n");
  exit(0);
}
int main(int argc, char** argv) {
    uint8_t disable, deactivated;
    int i;

    TlclLibInit();
    TPM_CHECK(TlclStartupIfNeeded());
    TPM_CHECK(TlclSelfTestFull());
    TPM_CHECK(TlclAssertPhysicalPresence());
    TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
    printf("disable is %d, deactivated is %d\n", disable, deactivated);

    for (i = 0; i < 2; i++) {
        TPM_CHECK(TlclForceClear());
        TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
        printf("disable is %d, deactivated is %d\n", disable, deactivated);
        VbAssert(disable == 1 && deactivated == 1);
        TPM_CHECK(TlclSetEnable());
        TPM_CHECK(TlclSetDeactivated(0));
        TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
        printf("disable is %d, deactivated is %d\n", disable, deactivated);
        VbAssert(disable == 0 && deactivated == 0);
    }

    printf("TEST SUCCEEDED\n");
    return 0;
}
int main(int argc, char* argv[]) {
  uint32_t result;
  uint8_t disable, deactivated;
  int pri = LOG_USER | LOG_ERR;

  TlclLibInit();
  TlclStartup();        /* ignore result */

  /* On the dogfood device, GetFlags causes an assertion failure because the
   * device uses an older TPM which is not compatible with the current spec.
   * We take advantage of this to cause the program to exit and not run the
   * self test again (which takes 1 second).
   */
  result = TlclGetFlags(NULL, NULL, NULL);

  result = TlclSelfTestFull();
  if (result != 0) {
    syslog(pri, "TPM selftest failed with code 0x%x\n", result);
    printf("fail\n");
    return 0;
  }

  /* Optional one-time enabling of TPM. */
  result = TlclAssertPhysicalPresence();
  if (result != 0) {
    syslog(pri, "TPM assertpp failed with code 0x%x\n", result);
    printf("fail\n");
    return 0;
  }
  result = TlclGetFlags(&disable, &deactivated, NULL);
  if (result != 0) {
    syslog(pri, "TPM getflags failed with code 0x%x\n", result);
    printf("fail\n");
    return 0;
  }
  if (disable) {
    result = TlclSetEnable();
    if (result != 0) {
      syslog(pri, "TPM physical enable failed with code 0x%x\n", result);
      printf("fail\n");
      return 0;
    }
  }
  if (deactivated) {
    result = TlclSetDeactivated(0);
    if (result != 0) {
      syslog(pri, "TPM physical activate failed with code 0x%x\n", result);
      printf("fail\n");
    } else {
      printf("reboot\n");
    }
    return 0; /* needs reboot */
  }
  printf("success\n");
  return 0;
}
/* Checks if the TPM is disabled/deactivated, and optionally enables/activates.
 * Does not disable/deactivate here because it might interfere with other
 * operations.
 */
static uint32_t RollbackTest_PartiallyAdjustFlags(uint8_t* disable,
                                                  uint8_t* deactivated) {
  RETURN_ON_FAILURE(TlclGetFlags(disable, deactivated));

  if (*deactivated && !RBTS.deactivated) {
    /* Needs to enable before we can activate. */
    RETURN_ON_FAILURE(TlclSetEnable());
    *disable = 0;
    /* Needs to reboot after activating. */
    RETURN_ON_FAILURE(TlclSetDeactivated(0));
    reboot();
  }
  /* We disable and deactivate at the end, if needed. */

  if (*disable && !RBTS.disable) {
    RETURN_ON_FAILURE(TlclSetEnable());
  }
  return TPM_SUCCESS;
}
int main(int argc, char** argv) {
  uint8_t disable, deactivated;

  TlclLibInit();
  TPM_CHECK(TlclStartupIfNeeded());
  TPM_CHECK(TlclSelfTestFull());
  TPM_CHECK(TlclAssertPhysicalPresence());
  TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
  printf("disable is %d, deactivated is %d\n", disable, deactivated);
  TPM_CHECK(TlclSetEnable());
  TPM_CHECK(TlclSetDeactivated(0));
  TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
  printf("disable is %d, deactivated is %d\n", disable, deactivated);
  if (disable == 1 || deactivated == 1) {
    VbExError("failed to enable or activate");
  }
  printf("TEST SUCCEEDED\n");
  return 0;
}
Beispiel #6
0
/**
 * Test send-command functions
 */
static void SendCommandTest(void)
{
	ResetMocks();
	TEST_EQ(TlclStartup(), 0, "SaveState");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_Startup, "  cmd");

	ResetMocks();
	TEST_EQ(TlclSaveState(), 0, "SaveState");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_SaveState, "  cmd");

	ResetMocks();
	TEST_EQ(TlclResume(), 0, "Resume");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_Startup, "  cmd");

	ResetMocks();
	TEST_EQ(TlclSelfTestFull(), 0, "SelfTestFull");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_SelfTestFull, "  cmd");

	ResetMocks();
	TEST_EQ(TlclContinueSelfTest(), 0, "ContinueSelfTest");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_ContinueSelfTest, "  cmd");

	ResetMocks();
	TEST_EQ(TlclAssertPhysicalPresence(), 0,
		"AssertPhysicalPresence");
	TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, "  cmd");

	ResetMocks();
	TEST_EQ(TlclPhysicalPresenceCMDEnable(), 0,
		"PhysicalPresenceCMDEnable");
	TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, "  cmd");

	ResetMocks();
	TEST_EQ(TlclFinalizePhysicalPresence(), 0,
		"FinalizePhysicalPresence");
	TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, "  cmd");

	ResetMocks();
	TEST_EQ(TlclAssertPhysicalPresenceResult(), 0,
		"AssertPhysicalPresenceResult");
	TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, "  cmd");

	ResetMocks();
	TEST_EQ(TlclLockPhysicalPresence(), 0,
		"LockPhysicalPresence");
	TEST_EQ(calls[0].req_cmd, TSC_ORD_PhysicalPresence, "  cmd");

	ResetMocks();
	TEST_EQ(TlclIsOwned(), 0, "IsOwned");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_ReadPubek, "  cmd");
	ResetMocks();
	calls[0].retval = VBERROR_SIMULATED;
	TEST_NEQ(TlclIsOwned(), 0, "IsOwned");

	ResetMocks();
	TEST_EQ(TlclForceClear(), 0, "ForceClear");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_ForceClear, "  cmd");

	ResetMocks();
	TEST_EQ(TlclSetEnable(), 0, "SetEnable");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalEnable, "  cmd");

	ResetMocks();
	TEST_EQ(TlclClearEnable(), 0, "ClearEnable");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalDisable, "  cmd");

	ResetMocks();
	TEST_EQ(TlclSetDeactivated(0), 0, "SetDeactivated");
	TEST_EQ(calls[0].req_cmd, TPM_ORD_PhysicalSetDeactivated, "  cmd");
}