Beispiel #1
0
int main(int argc, char** argv) {
	uint32_t x;
	uint8_t in[20], out[20];
	int time_limit_exceeded = 0;
	int errors = 0;

	TlclLibInit();
	TTPM_CHECK(0, 50);
	TTPM_CHECK(TlclStartupIfNeeded(), 50);
	TTPM_CHECK(TlclContinueSelfTest(), 100);
	TTPM_CHECK(TlclSelfTestFull(), 1000);
	TTPM_CHECK(TlclAssertPhysicalPresence(), 100);
	TTPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
	TTPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)), 100);
	TTPM_CHECK(TlclExtend(0, in, out), 200);
	TTPM_CHECK(TlclSetGlobalLock(), 50);
	TTPM_CHECK(TlclLockPhysicalPresence(), 100);
	if (time_limit_exceeded || errors > 0) {
		printf("TEST FAILED\n");
		exit(1);
	} else {
		printf("TEST SUCCEEDED\n");
		return 0;
	}
}
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;
}
Beispiel #4
0
/**
 * Test assorted tlcl functions
 */
static void TlclTest(void)
{
	uint8_t buf[32], buf2[32];

	ResetMocks();
	TEST_EQ(TlclLibInit(), VBERROR_SUCCESS, "Init");

	ResetMocks();
	mock_retval = VBERROR_SIMULATED;
	TEST_EQ(TlclLibInit(), mock_retval, "Init bad");

	ResetMocks();
	TEST_EQ(TlclLibClose(), VBERROR_SUCCESS, "Close");

	ResetMocks();
	mock_retval = VBERROR_SIMULATED;
	TEST_EQ(TlclLibClose(), mock_retval, "Close bad");

	ResetMocks();
	ToTpmUint32(buf + 2, 123);
	TEST_EQ(TlclPacketSize(buf), 123, "TlclPacketSize");

	ResetMocks();
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 0, "SendReceive");
	TEST_PTR_EQ(calls[0].req, buf, "SendReceive req ptr");
	TEST_EQ(calls[0].req_size, 10, "SendReceive size");

	ResetMocks();
	calls[0].retval = VBERROR_SIMULATED;
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), VBERROR_SIMULATED,
		"SendReceive fail");

	ResetMocks();
	SetResponse(0, 123, 10);
	ToTpmUint32(buf + 2, 10);
	TEST_EQ(TlclSendReceive(buf, buf2, sizeof(buf2)), 123,
		"SendReceive error response");

	// TODO: continue self test (if needed or doing)
	// TODO: then retry doing self test

}
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;
}
/* One-time call to create the WRITE_BUCKET space.
 */
static uint32_t RollbackTest_InitializeTPM(void) {
  TlclLibInit();
  RETURN_ON_FAILURE(TlclStartup());
  RETURN_ON_FAILURE(TlclContinueSelfTest());
  RETURN_ON_FAILURE(TlclAssertPhysicalPresence());
  RETURN_ON_FAILURE(SafeDefineSpace(WRITE_BUCKET_NV_INDEX,
                                    TPM_NV_PER_PPWRITE, 1));
  RETURN_ON_FAILURE(RollbackTest_SetTPMState(0));
  return TPM_SUCCESS;
}
int main(int argc, char** argv) {
  uint32_t x;

  TlclLibInit();
  TPM_CHECK(TlclStartup());
  TPM_CHECK(TlclContinueSelfTest());
  TPM_CHECK(TlclAssertPhysicalPresence());
  TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)));
  printf("TEST SUCCEEDED\n");
  return 0;
}
/* Sets the TPM to the right state for the next test run.
 *
 * Functionally correct ordering is tricky.  Optimal ordering is even trickier
 * (no claim to this).  May succeed only partially and require a reboot to
 * continue (if the TPM was deactivated at boot).
 */
static uint32_t RollbackTest_SetTPMState(int initialize) {
  uint8_t disable, deactivated;
  int wrong_value = 0;

  /* Initializes if needed */
  if (initialize) {
    TlclLibInit();
    /* Don't worry if we're already started. */
    (void) TlclStartup();
    RETURN_ON_FAILURE(TlclContinueSelfTest());
    RETURN_ON_FAILURE(TlclAssertPhysicalPresence());
  }

  RETURN_ON_FAILURE(RollbackTest_PartiallyAdjustFlags(&disable, &deactivated));
  RETURN_ON_FAILURE(RollbackTest_AdjustIsInitialized());
  RETURN_ON_FAILURE(RollbackTest_AdjustMustUseBackup());
  RETURN_ON_FAILURE(RollbackTest_AdjustKernelVersions(&wrong_value));

  if (RBTS.KERNEL_VERSIONS_exists) {
    /* Adjusting these states only makes sense when the kernel versions space
     * exists. */
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelPermissions(&wrong_value));
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelValue(wrong_value));
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelBackup());
  }

  RETURN_ON_FAILURE(RollbackTest_AdjustDeveloperMode());
  RETURN_ON_FAILURE(RollbackTest_SetOwnership(RBTS.owned));
  /* Do not remove spaces between SetOwnership and AdjustWriteCount, as that
   * might change the ownership state.  Also do not issue any writes from now
   * on, because AdjustWriteCount tries to avoid unneccessary clears, and after
   * that, any writes will obviously change the write count.
   */
  RETURN_ON_FAILURE(RollbackTest_AdjustWriteCount());

  /* Finally, disables and/or deactivates.  Must deactivate before disabling
   */
  if (!deactivated && RBTS.deactivated) {
    RETURN_ON_FAILURE(TlclSetDeactivated(1));
  }
  /* It's better to do this last, even though most commands we use work with
   * the TPM disabled.
   */
  if (!disable && RBTS.disable) {
    RETURN_ON_FAILURE(TlclClearEnable());
  }
  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 #10
0
int main(int argc, char** argv) {
	uint32_t result;
	TlclLibInit();
	result = TlclStartup();
	if (result != 0) {
		printf("tpm startup failed with 0x%x\n", result);
	}
	result = TlclGetFlags(NULL, NULL, NULL);
	if (result != 0) {
		printf("tpm getflags failed with 0x%x\n", result);
	}
	printf("executing SelfTestFull\n");
	TlclSelfTestFull();
	result = TlclGetFlags(NULL, NULL, NULL);
	if (result != 0) {
		printf("tpm getflags failed with 0x%x\n", result);
	}
	printf("TEST SUCCEEDED\n");
	return 0;
}