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