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 two-stage locking using bGlobalLock and PP. |
| 7 */ |
| 8 |
| 9 #include <stdio.h> |
| 10 #include <stdint.h> |
| 11 #include <stdlib.h> |
| 12 #include <tss/tcs.h> |
| 13 |
| 14 #include "tlcl.h" |
| 15 #include "utility.h" |
| 16 |
| 17 #define INDEX0 0xcafe |
| 18 #define INDEX1 0xcaff |
| 19 |
| 20 int main(int argc, char** argv) { |
| 21 uint32_t zero = 0; |
| 22 uint32_t perm; |
| 23 uint32_t result; |
| 24 uint32_t x; |
| 25 |
| 26 TlclLibInit(); |
| 27 |
| 28 TlclStartup(); |
| 29 TlclSelftestfull(); |
| 30 |
| 31 TlclAssertPhysicalPresence(); |
| 32 |
| 33 result = TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)); |
| 34 if (result == TPM_E_BADINDEX) { |
| 35 perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK; |
| 36 TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)); |
| 37 } |
| 38 result = TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t)); |
| 39 assert(result == TPM_SUCCESS); |
| 40 |
| 41 result = TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)); |
| 42 if (result == TPM_E_BADINDEX) { |
| 43 perm = TPM_NV_PER_PPWRITE; |
| 44 TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)); |
| 45 } |
| 46 result = TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t)); |
| 47 assert(result == TPM_SUCCESS); |
| 48 |
| 49 // Sets the global lock. |
| 50 TlclSetGlobalLock(); |
| 51 |
| 52 // Verifies that write to index0 fails. |
| 53 x = 1; |
| 54 result = TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)); |
| 55 if (result != TPM_E_AREA_LOCKED) { |
| 56 error("INDEX0 is not locked\n"); |
| 57 exit(1); |
| 58 } |
| 59 |
| 60 // Verifies that write to index1 is still possible. |
| 61 x = 2; |
| 62 result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); |
| 63 if (result != TPM_SUCCESS) { |
| 64 error("failure to write at INDEX1\n"); |
| 65 exit(2); |
| 66 } |
| 67 |
| 68 // Turns off PP. |
| 69 TlclLockPhysicalPresence(); |
| 70 |
| 71 // Verifies that write to index1 fails. |
| 72 x = 3; |
| 73 result = TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)); |
| 74 if (result != TPM_E_BAD_PRESENCE) { |
| 75 error("INDEX1 is not locked\n"); |
| 76 exit(3); |
| 77 } |
| 78 |
| 79 printf("Test completed successfully\n"); |
| 80 exit(0); |
| 81 } |
OLD | NEW |