OLD | NEW |
(Empty) | |
| 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 |
| 6 /* Test of protection from space redefinition. |
| 7 * |
| 8 * This test is actually not that interesting because, if I am right, space |
| 9 * redefinition is not allowed with PP only. It requires |
| 10 * TPM_TAG_RQU_AUTH1_COMMAND with owner authentication. |
| 11 */ |
| 12 |
| 13 #include <stdio.h> |
| 14 #include <stdint.h> |
| 15 #include <stdlib.h> |
| 16 #include <tss/tcs.h> |
| 17 |
| 18 #include "tlcl.h" |
| 19 #include "utility.h" |
| 20 |
| 21 #define INDEX0 0xcafe |
| 22 #define INDEX1 0xcaff |
| 23 |
| 24 int main(int argc, char** argv) { |
| 25 uint32_t perm; |
| 26 uint32_t result; |
| 27 uint32_t x; |
| 28 |
| 29 TlclLibInit(); |
| 30 TlclStartup(); |
| 31 TlclSelftestfull(); |
| 32 TlclAssertPhysicalPresence(); |
| 33 |
| 34 result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)); |
| 35 if (result == TPM_E_BADINDEX) { |
| 36 VBDEBUG(("creating INDEX0\n")); |
| 37 } else { |
| 38 VBDEBUG(("redefining INDEX0\n")); |
| 39 } |
| 40 perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK; |
| 41 TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); |
| 42 |
| 43 result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)); |
| 44 if (result == TPM_E_BADINDEX) { |
| 45 VBDEBUG(("redefining INDEX1\n")); |
| 46 } else { |
| 47 VBDEBUG(("creating INDEX1\n")); |
| 48 } |
| 49 perm = TPM_NV_PER_PPWRITE; |
| 50 TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)); |
| 51 |
| 52 // Sets the global lock. |
| 53 TlclSetGlobalLock(); |
| 54 |
| 55 // Verifies that index0 cannot be redefined. |
| 56 result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); |
| 57 if (result == TPM_SUCCESS) { |
| 58 error("unexpected success redefining INDEX0\n"); |
| 59 exit(1); |
| 60 } |
| 61 |
| 62 // Turns off PP. |
| 63 TlclLockPhysicalPresence(); |
| 64 |
| 65 // Verifies that neither index0 nor index1 cannot be redefined. |
| 66 result = TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); |
| 67 if (result == TPM_SUCCESS) { |
| 68 error("unexpected success redefining INDEX0\n"); |
| 69 exit(1); |
| 70 } |
| 71 result = TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)); |
| 72 if (result == TPM_SUCCESS) { |
| 73 error("unexpected success redefining INDEX1\n"); |
| 74 exit(1); |
| 75 } |
| 76 |
| 77 printf("Test completed successfully\n"); |
| 78 exit(0); |
| 79 } |
OLD | NEW |