aboutsummaryrefslogtreecommitdiff
path: root/HierarchyControl.c
blob: cf41f7e1d909eb78533d9398e4e8106e8e2aba21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// This file was extracted from the TCG Published
// Trusted Platform Module Library
// Part 3: Commands
// Family "2.0"
// Level 00 Revision 01.16
// October 30, 2014

#include "InternalRoutines.h"
#include "HierarchyControl_fp.h"
//
//
//     Error Returns               Meaning
//
//     TPM_RC_AUTH_TYPE            authHandle is not applicable to hierarchy in its current state
//
TPM_RC
TPM2_HierarchyControl(
   HierarchyControl_In    *in                 // IN: input parameter list
   )
{
   TPM_RC      result;
   BOOL        select = (in->state == YES);
   BOOL        *selected = NULL;

// Input Validation
   switch(in->enable)
   {
       // Platform hierarchy has to be disabled by platform auth
       // If the platform hierarchy has already been disabled, only a reboot
       // can enable it again
       case TPM_RH_PLATFORM:
       case TPM_RH_PLATFORM_NV:
           if(in->authHandle != TPM_RH_PLATFORM)
               return TPM_RC_AUTH_TYPE;
           break;

       // ShEnable may be disabled if PlatformAuth/PlatformPolicy or
       // OwnerAuth/OwnerPolicy is provided. If ShEnable is disabled, then it
       // may only be enabled if PlatformAuth/PlatformPolicy is provided.
       case TPM_RH_OWNER:
           if(   in->authHandle != TPM_RH_PLATFORM
              && in->authHandle != TPM_RH_OWNER)
               return TPM_RC_AUTH_TYPE;
           if(   gc.shEnable == FALSE && in->state == YES
              && in->authHandle != TPM_RH_PLATFORM)
               return TPM_RC_AUTH_TYPE;
           break;

       // EhEnable may be disabled if either PlatformAuth/PlatformPolicy or
       // EndosementAuth/EndorsementPolicy is provided. If EhEnable is disabled,
       // then it may only be enabled if PlatformAuth/PlatformPolicy is
       // provided.
       case TPM_RH_ENDORSEMENT:
           if(   in->authHandle != TPM_RH_PLATFORM
              && in->authHandle != TPM_RH_ENDORSEMENT)
               return TPM_RC_AUTH_TYPE;
           if(   gc.ehEnable == FALSE && in->state == YES
              && in->authHandle != TPM_RH_PLATFORM)
               return TPM_RC_AUTH_TYPE;
           break;
       default:
           pAssert(FALSE);
           break;
   }

// Internal Data Update

   // Enable or disable the selected hierarchy
   // Note: the authorization processing for this command may keep these
   // command actions from being executed. For example, if phEnable is
   // CLEAR, then platformAuth cannot be used for authorization. This
   // means that would not be possible to use platformAuth to change the
   // state of phEnable from CLEAR to SET.
   // If it is decided that platformPolicy can still be used when phEnable
   // is CLEAR, then this code could SET phEnable when proper platform
   // policy is provided.
   switch(in->enable)
   {
       case TPM_RH_OWNER:
           selected = &gc.shEnable;
           break;
       case TPM_RH_ENDORSEMENT:
           selected = &gc.ehEnable;
           break;
       case TPM_RH_PLATFORM:
           selected = &g_phEnable;
           break;
       case TPM_RH_PLATFORM_NV:
           selected = &gc.phEnableNV;
           break;
       default:
           pAssert(FALSE);
           break;
   }
   if(selected != NULL && *selected != select)
   {
       // Before changing the internal state, make sure that NV is available.
       // Only need to update NV if changing the orderly state
       if(gp.orderlyState != SHUTDOWN_NONE)
       {
           // The command needs NV update. Check if NV is available.
           // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at
           // this point
           result = NvIsAvailable();
           if(result != TPM_RC_SUCCESS)
               return result;
       }
       // state is changing and NV is available so modify
       *selected = select;
       // If a hierarchy was just disabled, flush it
       if(select == CLEAR && in->enable != TPM_RH_PLATFORM_NV)
       // Flush hierarchy
           ObjectFlushHierarchy(in->enable);

       // orderly state should be cleared because of the update to state clear data
       // This gets processed in ExecuteCommand() on the way out.
       g_clearOrderly = TRUE;
   }
   return TPM_RC_SUCCESS;
}