tpmtest_globallock.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (c) 2011 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 two-stage locking using bGlobalLock and PP.
  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 zero = 0;
  15. uint32_t x;
  16. TlclLibInit();
  17. TPM_CHECK(TlclStartupIfNeeded());
  18. TPM_CHECK(TlclSelfTestFull());
  19. TPM_CHECK(TlclAssertPhysicalPresence());
  20. TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
  21. TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t)));
  22. TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
  23. TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t)));
  24. TPM_CHECK(TlclSetGlobalLock());
  25. // Verifies that write to index0 fails.
  26. x = 1;
  27. TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)), TPM_E_AREA_LOCKED);
  28. TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
  29. VbAssert(x == 0);
  30. // Verifies that write to index1 is still possible.
  31. x = 2;
  32. TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)));
  33. TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
  34. VbAssert(x == 2);
  35. // Turns off PP.
  36. TlclLockPhysicalPresence();
  37. // Verifies that write to index1 fails.
  38. x = 3;
  39. TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)), TPM_E_BAD_PRESENCE);
  40. TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
  41. VbAssert(x == 2);
  42. printf("TEST SUCCEEDED\n");
  43. exit(0);
  44. }