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