• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Microsoft Reference Implementation for TPM 2.0
2  *
3  *  The copyright in this software is being made available under the BSD License,
4  *  included below. This software may be subject to other third party and
5  *  contributor rights, including patent rights, and no such rights are granted
6  *  under this license.
7  *
8  *  Copyright (c) Microsoft Corporation
9  *
10  *  All rights reserved.
11  *
12  *  BSD License
13  *
14  *  Redistribution and use in source and binary forms, with or without modification,
15  *  are permitted provided that the following conditions are met:
16  *
17  *  Redistributions of source code must retain the above copyright notice, this list
18  *  of conditions and the following disclaimer.
19  *
20  *  Redistributions in binary form must reproduce the above copyright notice, this
21  *  list of conditions and the following disclaimer in the documentation and/or
22  *  other materials provided with the distribution.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 #include "Tpm.h"
36 #include "PolicySecret_fp.h"
37 
38 #if CC_PolicySecret  // Conditional expansion of this file
39 
40 #include "Policy_spt_fp.h"
41 #include "NV_spt_fp.h"
42 
43 /*(See part 3 specification)
44 // Add a secret-based authorization to the policy evaluation
45 */
46 //  Return Type: TPM_RC
47 //      TPM_RC_CPHASH           cpHash for policy was previously set to a
48 //                              value that is not the same as 'cpHashA'
49 //      TPM_RC_EXPIRED          'expiration' indicates a time in the past
50 //      TPM_RC_NONCE            'nonceTPM' does not match the nonce associated
51 //                              with 'policySession'
52 //      TPM_RC_SIZE             'cpHashA' is not the size of a digest for the
53 //                              hash associated with 'policySession'
54 TPM_RC
TPM2_PolicySecret(PolicySecret_In * in,PolicySecret_Out * out)55 TPM2_PolicySecret(
56     PolicySecret_In     *in,            // IN: input parameter list
57     PolicySecret_Out    *out            // OUT: output parameter list
58     )
59 {
60     TPM_RC                   result;
61     SESSION                 *session;
62     TPM2B_NAME               entityName;
63     UINT64                   authTimeout = 0;
64 // Input Validation
65     // Get pointer to the session structure
66     session = SessionGet(in->policySession);
67 
68     //Only do input validation if this is not a trial policy session
69     if(session->attributes.isTrialPolicy == CLEAR)
70     {
71         authTimeout = ComputeAuthTimeout(session, in->expiration, &in->nonceTPM);
72 
73         result = PolicyParameterChecks(session, authTimeout,
74                                        &in->cpHashA, &in->nonceTPM,
75                                        RC_PolicySecret_nonceTPM,
76                                        RC_PolicySecret_cpHashA,
77                                        RC_PolicySecret_expiration);
78         if(result != TPM_RC_SUCCESS)
79             return result;
80     }
81 // Internal Data Update
82     // Update policy context with input policyRef and name of authorizing key
83     // This value is computed even for trial sessions. Possibly update the cpHash
84     PolicyContextUpdate(TPM_CC_PolicySecret,
85                         EntityGetName(in->authHandle, &entityName), &in->policyRef,
86                         &in->cpHashA, authTimeout, session);
87 // Command Output
88     // Create ticket and timeout buffer if in->expiration < 0 and this is not
89     // a trial session.
90     // NOTE: PolicyParameterChecks() makes sure that nonceTPM is present
91     // when expiration is non-zero.
92     if(in->expiration < 0
93        && session->attributes.isTrialPolicy == CLEAR
94        && !NvIsPinPassIndex(in->authHandle))
95     {
96         BOOL        expiresOnReset = (in->nonceTPM.t.size == 0);
97         // Compute policy ticket
98         authTimeout &= ~EXPIRATION_BIT;
99         TicketComputeAuth(TPM_ST_AUTH_SECRET, EntityGetHierarchy(in->authHandle),
100                           authTimeout, expiresOnReset, &in->cpHashA, &in->policyRef,
101                           &entityName, &out->policyTicket);
102         // Generate timeout buffer.  The format of output timeout buffer is
103         // TPM-specific.
104         // Note: In this implementation, the timeout buffer value is computed after
105         // the ticket is produced so, when the ticket is checked, the expiration
106         // flag needs to be extracted before the ticket is checked.
107         out->timeout.t.size = sizeof(authTimeout);
108         // In the Windows compatible version, the least-significant bit of the
109         // timeout value is used as a flag to indicate if the authorization expires
110         // on reset. The flag is the MSb.
111         if(expiresOnReset)
112             authTimeout |= EXPIRATION_BIT;
113         UINT64_TO_BYTE_ARRAY(authTimeout, out->timeout.t.buffer);
114     }
115     else
116     {
117         // timeout buffer is null
118         out->timeout.t.size = 0;
119 
120         // authorization ticket is null
121         out->policyTicket.tag = TPM_ST_AUTH_SECRET;
122         out->policyTicket.hierarchy = TPM_RH_NULL;
123         out->policyTicket.digest.t.size = 0;
124     }
125     return TPM_RC_SUCCESS;
126 }
127 
128 #endif // CC_PolicySecret