1 /* Copyright 2011 The ChromiumOS Authors
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
13 #include "host_common.h"
14 #include "common/tests.h"
15 #include "tlcl.h"
16 #include "tlcl_tests.h"
17
main(int argc,char ** argv)18 int main(int argc, char** argv) {
19 uint32_t zero = 0;
20 uint32_t x;
21
22 TlclLibInit();
23 TPM_CHECK(TlclStartupIfNeeded());
24 TPM_CHECK(TlclSelfTestFull());
25 TPM_CHECK(TlclAssertPhysicalPresence());
26 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
27 TPM_CHECK(TlclWrite(INDEX0, (uint8_t*) &zero, sizeof(uint32_t)));
28 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
29 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &zero, sizeof(uint32_t)));
30 TPM_CHECK(TlclSetGlobalLock());
31
32 // Verifies that write to index0 fails.
33 x = 1;
34 TPM_EXPECT(TlclWrite(INDEX0, (uint8_t*) &x, sizeof(x)),
35 TPM_E_AREA_LOCKED);
36 TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
37 TEST_EQ(x, 0, "Read from INDEX0 should give 0");
38
39 // Verifies that write to index1 is still possible.
40 x = 2;
41 TPM_CHECK(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)));
42 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
43 TEST_EQ(x, 0, "Read from INDEX1 should give 2");
44
45 // Turns off PP.
46 TlclLockPhysicalPresence();
47
48 // Verifies that write to index1 fails.
49 x = 3;
50 TPM_EXPECT(TlclWrite(INDEX1, (uint8_t*) &x, sizeof(x)),
51 TPM_E_BAD_PRESENCE);
52 TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
53 TEST_EQ(x, 2, "Read from INDEX1 should give 2");
54 printf("TEST SUCCEEDED\n");
55 exit(0);
56 }
57