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 when an owner is NOT present.
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
17int main(int argc, char** argv) {
18  uint32_t perm;
19  uint32_t x;
20
21  TlclLibInit();
22  TPM_CHECK(TlclStartupIfNeeded());
23  TPM_CHECK(TlclSelfTestFull());
24  TPM_CHECK(TlclAssertPhysicalPresence());
25
26  VbAssert(!TlclIsOwned());
27
28  /* Ensures spaces exist. */
29  TPM_CHECK(TlclRead(INDEX0, (uint8_t*) &x, sizeof(x)));
30  TPM_CHECK(TlclRead(INDEX1, (uint8_t*) &x, sizeof(x)));
31
32  /* Redefines spaces a couple of times. */
33  perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
34  TPM_CHECK(TlclDefineSpace(INDEX0, perm, 2 * sizeof(uint32_t)));
35  TPM_CHECK(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)));
36
37  perm = TPM_NV_PER_PPWRITE;
38  TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
39  TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
40
41  // Sets the global lock.
42  TlclSetGlobalLock();
43
44  // Verifies that index0 cannot be redefined.
45  TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
46             TPM_E_AREA_LOCKED);
47
48  // Checks that index1 can.
49  TPM_CHECK(TlclDefineSpace(INDEX1, perm, 2 * sizeof(uint32_t)));
50  TPM_CHECK(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)));
51
52  // Turns off PP.
53  TlclLockPhysicalPresence();
54
55  // Verifies that neither index0 nor index1 can be redefined.
56  TPM_EXPECT(TlclDefineSpace(INDEX0, perm, sizeof(uint32_t)),
57             TPM_E_BAD_PRESENCE);
58  TPM_EXPECT(TlclDefineSpace(INDEX1, perm, sizeof(uint32_t)),
59             TPM_E_BAD_PRESENCE);
60
61  printf("TEST SUCCEEDED\n");
62  exit(0);
63}
64