tpmtest_redefine_unowned.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. /* Test of protection from space redefinition when an owner is NOT present.
  6. */
  7. #include <stdio.h>
  8. #include <stdint.h>
  9. #include <stdlib.h>
  10. #include "host_common.h"
  11. #include "tlcl.h"
  12. #include "tlcl_tests.h"
  13. int main(int argc, char** argv) {
  14. uint32_t perm;
  15. uint32_t x;
  16. TlclLibInit();
  17. TPM_CHECK(TlclStartupIfNeeded());
  18. TPM_CHECK(TlclSelfTestFull());
  19. TPM_CHECK(TlclAssertPhysicalPresence());
  20. VbAssert(!TlclIsOwned());
  21. /* Ensures spaces exist. */
  22. TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
  23. TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
  24. /* Redefines spaces a couple of times. */
  25. perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
  26. TPM_CHECK(TlclDefineSpace(INDEX0, perm, 2 * sizeof(uint32_t)));
  27. TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
  28. perm = TPM_NV_PER_PPWRITE;
  29. TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
  30. TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
  31. // Sets the global lock.
  32. TlclSetGlobalLock();
  33. // Verifies that index0 cannot be redefined.
  34. TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
  35. TPM_E_AREA_LOCKED);
  36. // Checks that index1 can.
  37. TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
  38. TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
  39. // Turns off PP.
  40. TlclLockPhysicalPresence();
  41. // Verifies that neither index0 nor index1 can be redefined.
  42. TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
  43. TPM_E_BAD_PRESENCE);
  44. TPM_EXPECT(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)),
  45. TPM_E_BAD_PRESENCE);
  46. printf("TEST SUCCEEDED\n");
  47. exit(0);
  48. }