| 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 "PolicyTicket_fp.h" |
| 37 |
|
| 38 |
#if CC_PolicyTicket // Conditional expansion of this file |
| 39 |
|
| 40 |
#include "Policy_spt_fp.h" |
| 41 |
|
| 42 |
/*(See part 3 specification) |
| 43 |
// Include ticket to the policy evaluation |
| 44 |
*/ |
| 45 |
// Return Type: TPM_RC |
| 46 |
// TPM_RC_CPHASH policy's cpHash was previously set to a different |
| 47 |
// value |
| 48 |
// TPM_RC_EXPIRED 'timeout' value in the ticket is in the past and the |
| 49 |
// ticket has expired |
| 50 |
// TPM_RC_SIZE 'timeout' or 'cpHash' has invalid size for the |
| 51 |
// TPM_RC_TICKET 'ticket' is not valid |
| 52 |
TPM_RC |
| 53 |
TPM2_PolicyTicket( |
| 54 |
PolicyTicket_In *in // IN: input parameter list |
| 55 |
) |
| 56 |
{ |
| 57 |
TPM_RC result; |
| 58 |
SESSION *session; |
| 59 |
UINT64 authTimeout; |
| 60 |
TPMT_TK_AUTH ticketToCompare; |
| 61 |
TPM_CC commandCode = TPM_CC_PolicySecret; |
| 62 |
BOOL expiresOnReset; |
| 63 |
|
| 64 |
// Input Validation |
| 65 |
|
| 66 |
// Get pointer to the session structure |
| 67 |
session = SessionGet(in->policySession); |
| 68 |
|
| 69 |
// NOTE: A trial policy session is not allowed to use this command. |
| 70 |
// A ticket is used in place of a previously given authorization. Since |
| 71 |
// a trial policy doesn't actually authenticate, the validated |
| 72 |
// ticket is not necessary and, in place of using a ticket, one |
| 73 |
// should use the intended authorization for which the ticket |
| 74 |
// would be a substitute. |
| 75 |
if(session->attributes.isTrialPolicy) |
| 76 |
return TPM_RCS_ATTRIBUTES + RC_PolicyTicket_policySession; |
| 77 |
// Restore timeout data. The format of timeout buffer is TPM-specific. |
| 78 |
// In this implementation, the most significant bit of the timeout value is |
| 79 |
// used as the flag to indicate that the ticket expires on TPM Reset or |
| 80 |
// TPM Restart. The flag has to be removed before the parameters and ticket |
| 81 |
// are checked. |
| 82 |
if(in->timeout.t.size != sizeof(UINT64)) |
| 83 |
return TPM_RCS_SIZE + RC_PolicyTicket_timeout; |
| 84 |
authTimeout = BYTE_ARRAY_TO_UINT64(in->timeout.t.buffer); |
| 85 |
|
| 86 |
// extract the flag |
| 87 |
expiresOnReset = (authTimeout & EXPIRATION_BIT) != 0; |
| 88 |
authTimeout &= ~EXPIRATION_BIT; |
| 89 |
|
| 90 |
// Do the normal checks on the cpHashA and timeout values |
| 91 |
result = PolicyParameterChecks(session, authTimeout, |
| 92 |
&in->cpHashA, |
| 93 |
NULL, // no nonce |
| 94 |
0, // no bad nonce return |
| 95 |
RC_PolicyTicket_cpHashA, |
| 96 |
RC_PolicyTicket_timeout); |
| 97 |
if(result != TPM_RC_SUCCESS) |
| 98 |
return result; |
| 99 |
// Validate Ticket |
| 100 |
// Re-generate policy ticket by input parameters |
| 101 |
TicketComputeAuth(in->ticket.tag, in->ticket.hierarchy, |
| 102 |
authTimeout, expiresOnReset, &in->cpHashA, &in->policyRef, |
| 103 |
&in->authName, &ticketToCompare); |
| 104 |
// Compare generated digest with input ticket digest |
| 105 |
if(!MemoryEqual2B(&in->ticket.digest.b, &ticketToCompare.digest.b)) |
| 106 |
return TPM_RCS_TICKET + RC_PolicyTicket_ticket; |
| 107 |
|
| 108 |
// Internal Data Update |
| 109 |
|
| 110 |
// Is this ticket to take the place of a TPM2_PolicySigned() or |
| 111 |
// a TPM2_PolicySecret()? |
| 112 |
if(in->ticket.tag == TPM_ST_AUTH_SIGNED) |
| 113 |
commandCode = TPM_CC_PolicySigned; |
| 114 |
else if(in->ticket.tag == TPM_ST_AUTH_SECRET) |
| 115 |
commandCode = TPM_CC_PolicySecret; |
| 116 |
else |
| 117 |
// There could only be two possible tag values. Any other value should |
| 118 |
// be caught by the ticket validation process. |
| 119 |
FAIL(FATAL_ERROR_INTERNAL); |
| 120 |
|
| 121 |
// Update policy context |
| 122 |
PolicyContextUpdate(commandCode, &in->authName, &in->policyRef, |
| 123 |
&in->cpHashA, authTimeout, session); |
| 124 |
|
| 125 |
return TPM_RC_SUCCESS; |
| 126 |
} |
| 127 |
|
| 128 |
#endif // CC_PolicyTicket |