Peter Huewe | d5a36f6 | 2018-06-12 00:59:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-2 */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG |
| 4 | * All rights reserved. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 5 | ******************************************************************************/ |
| 6 | |
Philip Tricca | 910f17c | 2018-03-15 12:38:37 -0700 | [diff] [blame] | 7 | #include "tss2_mu.h" |
| 8 | #include "tss2_sys.h" |
Philip Tricca | 8ffd3c4 | 2018-03-09 16:27:24 -0800 | [diff] [blame] | 9 | #include "tss2_esys.h" |
Juergen Repp | ed6e6e2 | 2018-03-19 17:34:32 +0100 | [diff] [blame] | 10 | |
| 11 | #include "esys_types.h" |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 12 | #include "esys_iutil.h" |
| 13 | #include "esys_mu.h" |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 14 | #define LOGMODULE esys |
Philip Tricca | a7c51ce | 2018-03-10 18:28:25 -0800 | [diff] [blame] | 15 | #include "util/log.h" |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 16 | |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 17 | /** Store command parameters inside the ESYS_CONTEXT for use during _Finish */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 18 | static void store_input_parameters ( |
| 19 | ESYS_CONTEXT *esysContext, |
| 20 | ESYS_TR policySession, |
| 21 | const TPM2B_OPERAND *operandB, |
| 22 | UINT16 offset, |
| 23 | TPM2_EO operation) |
| 24 | { |
| 25 | esysContext->in.PolicyCounterTimer.policySession = policySession; |
| 26 | esysContext->in.PolicyCounterTimer.offset = offset; |
| 27 | esysContext->in.PolicyCounterTimer.operation = operation; |
| 28 | if (operandB == NULL) { |
| 29 | esysContext->in.PolicyCounterTimer.operandB = NULL; |
| 30 | } else { |
| 31 | esysContext->in.PolicyCounterTimer.operandBData = *operandB; |
| 32 | esysContext->in.PolicyCounterTimer.operandB = |
| 33 | &esysContext->in.PolicyCounterTimer.operandBData; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** One-Call function for TPM2_PolicyCounterTimer |
| 38 | * |
| 39 | * This function invokes the TPM2_PolicyCounterTimer command in a one-call |
| 40 | * variant. This means the function will block until the TPM response is |
| 41 | * available. All input parameters are const. The memory for non-simple output |
| 42 | * parameters is allocated by the function implementation. |
| 43 | * |
| 44 | * @param[in,out] esysContext The ESYS_CONTEXT. |
Juergen Repp | f7e5bd3 | 2018-04-26 11:11:32 +0200 | [diff] [blame] | 45 | * @param[in] policySession Handle for the policy session being extended. |
| 46 | * @param[in] shandle1 First session handle. |
| 47 | * @param[in] shandle2 Second session handle. |
| 48 | * @param[in] shandle3 Third session handle. |
| 49 | * @param[in] operandB The second operand. |
| 50 | * @param[in] offset The offset in TPMS_TIME_INFO structure for the start of |
| 51 | * operand A. |
| 52 | * @param[in] operation The comparison to make. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 53 | * @retval TSS2_RC_SUCCESS on success |
Juergen Repp | f7e5bd3 | 2018-04-26 11:11:32 +0200 | [diff] [blame] | 54 | * @retval ESYS_RC_SUCCESS if the function call was a success. |
| 55 | * @retval TSS2_ESYS_RC_BAD_REFERENCE if the esysContext or required input |
| 56 | * pointers or required output handle references are NULL. |
| 57 | * @retval TSS2_ESYS_RC_BAD_CONTEXT: if esysContext corruption is detected. |
| 58 | * @retval TSS2_ESYS_RC_MEMORY: if the ESAPI cannot allocate enough memory for |
| 59 | * internal operations or return parameters. |
| 60 | * @retval TSS2_ESYS_RC_BAD_SEQUENCE: if the context has an asynchronous |
| 61 | * operation already pending. |
| 62 | * @retval TSS2_ESYS_RC_INSUFFICIENT_RESPONSE: if the TPM's response does not |
| 63 | * at least contain the tag, response length, and response code. |
| 64 | * @retval TSS2_ESYS_RC_MALFORMED_RESPONSE: if the TPM's response is corrupted. |
| 65 | * @retval TSS2_ESYS_RC_MULTIPLE_DECRYPT_SESSIONS: if more than one session has |
| 66 | * the 'decrypt' attribute bit set. |
| 67 | * @retval TSS2_ESYS_RC_MULTIPLE_ENCRYPT_SESSIONS: if more than one session has |
| 68 | * the 'encrypt' attribute bit set. |
| 69 | * @retval TSS2_ESYS_RC_BAD_TR: if any of the ESYS_TR objects are unknown to the |
| 70 | * ESYS_CONTEXT or are of the wrong type or if required ESYS_TR objects |
| 71 | * are ESYS_TR_NONE. |
| 72 | * @retval TSS2_ESYS_RC_NO_ENCRYPT_PARAM: if one of the sessions has the |
| 73 | * 'encrypt' attribute set and the command does not support encryption |
| 74 | * of the first response parameter. |
| 75 | * @retval TSS2_RCs produced by lower layers of the software stack may be |
| 76 | * returned to the caller unaltered unless handled internally. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 77 | */ |
| 78 | TSS2_RC |
| 79 | Esys_PolicyCounterTimer( |
| 80 | ESYS_CONTEXT *esysContext, |
| 81 | ESYS_TR policySession, |
| 82 | ESYS_TR shandle1, |
| 83 | ESYS_TR shandle2, |
| 84 | ESYS_TR shandle3, |
| 85 | const TPM2B_OPERAND *operandB, |
| 86 | UINT16 offset, |
| 87 | TPM2_EO operation) |
| 88 | { |
Juergen Repp | 3b7b41b | 2018-03-19 15:58:04 +0100 | [diff] [blame] | 89 | TSS2_RC r; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 90 | |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 91 | r = Esys_PolicyCounterTimer_Async(esysContext, |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 92 | policySession, |
| 93 | shandle1, |
| 94 | shandle2, |
| 95 | shandle3, |
| 96 | operandB, |
| 97 | offset, |
| 98 | operation); |
| 99 | return_if_error(r, "Error in async function"); |
| 100 | |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 101 | /* Set the timeout to indefinite for now, since we want _Finish to block */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 102 | int32_t timeouttmp = esysContext->timeout; |
| 103 | esysContext->timeout = -1; |
| 104 | /* |
| 105 | * Now we call the finish function, until return code is not equal to |
| 106 | * from TSS2_BASE_RC_TRY_AGAIN. |
| 107 | * Note that the finish function may return TSS2_RC_TRY_AGAIN, even if we |
| 108 | * have set the timeout to -1. This occurs for example if the TPM requests |
| 109 | * a retransmission of the command via TPM2_RC_YIELDED. |
| 110 | */ |
| 111 | do { |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 112 | r = Esys_PolicyCounterTimer_Finish(esysContext); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 113 | /* This is just debug information about the reattempt to finish the |
| 114 | command */ |
| 115 | if ((r & ~TSS2_RC_LAYER_MASK) == TSS2_BASE_RC_TRY_AGAIN) |
| 116 | LOG_DEBUG("A layer below returned TRY_AGAIN: %" PRIx32 |
| 117 | " => resubmitting command", r); |
| 118 | } while ((r & ~TSS2_RC_LAYER_MASK) == TSS2_BASE_RC_TRY_AGAIN); |
| 119 | |
| 120 | /* Restore the timeout value to the original value */ |
| 121 | esysContext->timeout = timeouttmp; |
| 122 | return_if_error(r, "Esys Finish"); |
| 123 | |
| 124 | return TSS2_RC_SUCCESS; |
| 125 | } |
| 126 | |
| 127 | /** Asynchronous function for TPM2_PolicyCounterTimer |
| 128 | * |
| 129 | * This function invokes the TPM2_PolicyCounterTimer command in a asynchronous |
| 130 | * variant. This means the function will return as soon as the command has been |
| 131 | * sent downwards the stack to the TPM. All input parameters are const. |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 132 | * In order to retrieve the TPM's response call Esys_PolicyCounterTimer_Finish. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 133 | * |
| 134 | * @param[in,out] esysContext The ESYS_CONTEXT. |
Juergen Repp | f7e5bd3 | 2018-04-26 11:11:32 +0200 | [diff] [blame] | 135 | * @param[in] policySession Handle for the policy session being extended. |
| 136 | * @param[in] shandle1 First session handle. |
| 137 | * @param[in] shandle2 Second session handle. |
| 138 | * @param[in] shandle3 Third session handle. |
| 139 | * @param[in] operandB The second operand. |
| 140 | * @param[in] offset The offset in TPMS_TIME_INFO structure for the start of |
| 141 | * operand A. |
| 142 | * @param[in] operation The comparison to make. |
| 143 | * @retval ESYS_RC_SUCCESS if the function call was a success. |
| 144 | * @retval TSS2_ESYS_RC_BAD_REFERENCE if the esysContext or required input |
| 145 | * pointers or required output handle references are NULL. |
| 146 | * @retval TSS2_ESYS_RC_BAD_CONTEXT: if esysContext corruption is detected. |
| 147 | * @retval TSS2_ESYS_RC_MEMORY: if the ESAPI cannot allocate enough memory for |
| 148 | * internal operations or return parameters. |
| 149 | * @retval TSS2_RCs produced by lower layers of the software stack may be |
| 150 | returned to the caller unaltered unless handled internally. |
| 151 | * @retval TSS2_ESYS_RC_MULTIPLE_DECRYPT_SESSIONS: if more than one session has |
| 152 | * the 'decrypt' attribute bit set. |
| 153 | * @retval TSS2_ESYS_RC_MULTIPLE_ENCRYPT_SESSIONS: if more than one session has |
| 154 | * the 'encrypt' attribute bit set. |
| 155 | * @retval TSS2_ESYS_RC_BAD_TR: if any of the ESYS_TR objects are unknown to the |
| 156 | ESYS_CONTEXT or are of the wrong type or if required ESYS_TR objects |
| 157 | are ESYS_TR_NONE. |
| 158 | * @retval TSS2_ESYS_RC_NO_ENCRYPT_PARAM: if one of the sessions has the |
| 159 | * 'encrypt' attribute set and the command does not support encryption |
| 160 | * of the first response parameter. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 161 | */ |
| 162 | TSS2_RC |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 163 | Esys_PolicyCounterTimer_Async( |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 164 | ESYS_CONTEXT *esysContext, |
| 165 | ESYS_TR policySession, |
| 166 | ESYS_TR shandle1, |
| 167 | ESYS_TR shandle2, |
| 168 | ESYS_TR shandle3, |
| 169 | const TPM2B_OPERAND *operandB, |
| 170 | UINT16 offset, |
| 171 | TPM2_EO operation) |
| 172 | { |
Juergen Repp | 3b7b41b | 2018-03-19 15:58:04 +0100 | [diff] [blame] | 173 | TSS2_RC r; |
Andreas Fuchs | 15bbb67 | 2018-03-27 13:21:13 +0200 | [diff] [blame] | 174 | LOG_TRACE("context=%p, policySession=%"PRIx32 ", operandB=%p," |
| 175 | "offset=%04"PRIx16", operation=%04"PRIx16"", |
| 176 | esysContext, policySession, operandB, offset, operation); |
Andreas Fuchs | c5a73eb | 2018-03-19 16:01:00 +0100 | [diff] [blame] | 177 | TSS2L_SYS_AUTH_COMMAND auths; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 178 | RSRC_NODE_T *policySessionNode; |
| 179 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 180 | /* Check context, sequence correctness and set state to error for now */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 181 | if (esysContext == NULL) { |
| 182 | LOG_ERROR("esyscontext is NULL."); |
| 183 | return TSS2_ESYS_RC_BAD_REFERENCE; |
| 184 | } |
| 185 | r = iesys_check_sequence_async(esysContext); |
| 186 | if (r != TSS2_RC_SUCCESS) |
| 187 | return r; |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 188 | esysContext->state = _ESYS_STATE_INTERNALERROR; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 189 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 190 | /* Check and store input parameters */ |
dantpm | f6ef247 | 2018-04-06 15:21:59 -0700 | [diff] [blame] | 191 | r = check_session_feasibility(shandle1, shandle2, shandle3, 0); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 192 | return_state_if_error(r, _ESYS_STATE_INIT, "Check session usage"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 193 | store_input_parameters(esysContext, policySession, |
| 194 | operandB, |
| 195 | offset, |
| 196 | operation); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 197 | |
| 198 | /* Retrieve the metadata objects for provided handles */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 199 | r = esys_GetResourceObject(esysContext, policySession, &policySessionNode); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 200 | return_state_if_error(r, _ESYS_STATE_INIT, "policySession unknown."); |
| 201 | |
| 202 | /* Initial invocation of SAPI to prepare the command buffer with parameters */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 203 | r = Tss2_Sys_PolicyCounterTimer_Prepare(esysContext->sys, |
| 204 | (policySessionNode == NULL) ? TPM2_RH_NULL : policySessionNode->rsrc.handle, |
| 205 | operandB, |
| 206 | offset, |
| 207 | operation); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 208 | return_state_if_error(r, _ESYS_STATE_INIT, "SAPI Prepare returned error."); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 209 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 210 | /* Calculate the cpHash Values */ |
| 211 | r = init_session_tab(esysContext, shandle1, shandle2, shandle3); |
| 212 | return_state_if_error(r, _ESYS_STATE_INIT, "Initialize session resources"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 213 | iesys_compute_session_value(esysContext->session_tab[0], NULL, NULL); |
| 214 | iesys_compute_session_value(esysContext->session_tab[1], NULL, NULL); |
| 215 | iesys_compute_session_value(esysContext->session_tab[2], NULL, NULL); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 216 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 217 | /* Generate the auth values and set them in the SAPI command buffer */ |
| 218 | r = iesys_gen_auths(esysContext, policySessionNode, NULL, NULL, &auths); |
| 219 | return_state_if_error(r, _ESYS_STATE_INIT, "Error in computation of auth values"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 220 | esysContext->authsCount = auths.count; |
| 221 | r = Tss2_Sys_SetCmdAuths(esysContext->sys, &auths); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 222 | return_state_if_error(r, _ESYS_STATE_INIT, "SAPI error on SetCmdAuths"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 223 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 224 | /* Trigger execution and finish the async invocation */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 225 | r = Tss2_Sys_ExecuteAsync(esysContext->sys); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 226 | return_state_if_error(r, _ESYS_STATE_INTERNALERROR, "Finish (Execute Async)"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 227 | |
| 228 | esysContext->state = _ESYS_STATE_SENT; |
| 229 | |
| 230 | return r; |
| 231 | } |
| 232 | |
| 233 | /** Asynchronous finish function for TPM2_PolicyCounterTimer |
| 234 | * |
| 235 | * This function returns the results of a TPM2_PolicyCounterTimer command |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 236 | * invoked via Esys_PolicyCounterTimer_Finish. All non-simple output parameters |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 237 | * are allocated by the function's implementation. NULL can be passed for every |
| 238 | * output parameter if the value is not required. |
| 239 | * |
| 240 | * @param[in,out] esysContext The ESYS_CONTEXT. |
| 241 | * @retval TSS2_RC_SUCCESS on success |
Juergen Repp | f7e5bd3 | 2018-04-26 11:11:32 +0200 | [diff] [blame] | 242 | * @retval ESYS_RC_SUCCESS if the function call was a success. |
| 243 | * @retval TSS2_ESYS_RC_BAD_REFERENCE if the esysContext or required input |
| 244 | * pointers or required output handle references are NULL. |
| 245 | * @retval TSS2_ESYS_RC_BAD_CONTEXT: if esysContext corruption is detected. |
| 246 | * @retval TSS2_ESYS_RC_MEMORY: if the ESAPI cannot allocate enough memory for |
| 247 | * internal operations or return parameters. |
| 248 | * @retval TSS2_ESYS_RC_BAD_SEQUENCE: if the context has an asynchronous |
| 249 | * operation already pending. |
| 250 | * @retval TSS2_ESYS_RC_TRY_AGAIN: if the timeout counter expires before the |
| 251 | * TPM response is received. |
| 252 | * @retval TSS2_ESYS_RC_INSUFFICIENT_RESPONSE: if the TPM's response does not |
| 253 | * at least contain the tag, response length, and response code. |
| 254 | * @retval TSS2_ESYS_RC_MALFORMED_RESPONSE: if the TPM's response is corrupted. |
| 255 | * @retval TSS2_RCs produced by lower layers of the software stack may be |
| 256 | * returned to the caller unaltered unless handled internally. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 257 | */ |
| 258 | TSS2_RC |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 259 | Esys_PolicyCounterTimer_Finish( |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 260 | ESYS_CONTEXT *esysContext) |
| 261 | { |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 262 | TSS2_RC r; |
Andreas Fuchs | 15bbb67 | 2018-03-27 13:21:13 +0200 | [diff] [blame] | 263 | LOG_TRACE("context=%p", |
| 264 | esysContext); |
| 265 | |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 266 | if (esysContext == NULL) { |
| 267 | LOG_ERROR("esyscontext is NULL."); |
| 268 | return TSS2_ESYS_RC_BAD_REFERENCE; |
| 269 | } |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 270 | |
| 271 | /* Check for correct sequence and set sequence to irregular for now */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 272 | if (esysContext->state != _ESYS_STATE_SENT) { |
| 273 | LOG_ERROR("Esys called in bad sequence."); |
| 274 | return TSS2_ESYS_RC_BAD_SEQUENCE; |
| 275 | } |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 276 | esysContext->state = _ESYS_STATE_INTERNALERROR; |
| 277 | |
| 278 | /*Receive the TPM response and handle resubmissions if necessary. */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 279 | r = Tss2_Sys_ExecuteFinish(esysContext->sys, esysContext->timeout); |
| 280 | if ((r & ~TSS2_RC_LAYER_MASK) == TSS2_BASE_RC_TRY_AGAIN) { |
| 281 | LOG_DEBUG("A layer below returned TRY_AGAIN: %" PRIx32, r); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 282 | esysContext->state = _ESYS_STATE_SENT; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 283 | return r; |
| 284 | } |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 285 | /* This block handle the resubmission of TPM commands given a certain set of |
| 286 | * TPM response codes. */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 287 | if (r == TPM2_RC_RETRY || r == TPM2_RC_TESTING || r == TPM2_RC_YIELDED) { |
| 288 | LOG_DEBUG("TPM returned RETRY, TESTING or YIELDED, which triggers a " |
| 289 | "resubmission: %" PRIx32, r); |
Andreas Fuchs | 631d7e6 | 2018-03-19 10:54:56 +0100 | [diff] [blame] | 290 | if (esysContext->submissionCount >= _ESYS_MAX_SUBMISSIONS) { |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 291 | LOG_WARNING("Maximum number of (re)submissions has been reached."); |
| 292 | esysContext->state = _ESYS_STATE_INIT; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 293 | return r; |
| 294 | } |
| 295 | esysContext->state = _ESYS_STATE_RESUBMISSION; |
Juergen Repp | add438d | 2018-04-09 10:00:19 +0200 | [diff] [blame] | 296 | r = Esys_PolicyCounterTimer_Async(esysContext, |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 297 | esysContext->in.PolicyCounterTimer.policySession, |
| 298 | esysContext->session_type[0], |
| 299 | esysContext->session_type[1], |
| 300 | esysContext->session_type[2], |
| 301 | esysContext->in.PolicyCounterTimer.operandB, |
| 302 | esysContext->in.PolicyCounterTimer.offset, |
| 303 | esysContext->in.PolicyCounterTimer.operation); |
| 304 | if (r != TSS2_RC_SUCCESS) { |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 305 | LOG_WARNING("Error attempting to resubmit"); |
| 306 | /* We do not set esysContext->state here but inherit the most recent |
| 307 | * state of the _async function. */ |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 308 | return r; |
| 309 | } |
| 310 | r = TSS2_ESYS_RC_TRY_AGAIN; |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 311 | LOG_DEBUG("Resubmission initiated and returning RC_TRY_AGAIN."); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 312 | return r; |
| 313 | } |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 314 | /* The following is the "regular error" handling. */ |
Juergen Repp | 033da11 | 2018-07-10 13:06:18 +0200 | [diff] [blame^] | 315 | if (iesys_tpm_error(r)) { |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 316 | LOG_WARNING("Received TPM Error"); |
| 317 | esysContext->state = _ESYS_STATE_INIT; |
| 318 | return r; |
| 319 | } else if (r != TSS2_RC_SUCCESS) { |
| 320 | LOG_ERROR("Received a non-TPM Error"); |
| 321 | esysContext->state = _ESYS_STATE_INTERNALERROR; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 322 | return r; |
| 323 | } |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 324 | |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 325 | /* |
| 326 | * Now the verification of the response (hmac check) and if necessary the |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 327 | * parameter decryption have to be done. |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 328 | */ |
Juergen Repp | 109de7d | 2018-02-23 13:42:08 +0100 | [diff] [blame] | 329 | r = iesys_check_response(esysContext); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 330 | return_state_if_error(r, _ESYS_STATE_INTERNALERROR, "Error: check response"); |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 331 | /* |
| 332 | * After the verification of the response we call the complete function |
| 333 | * to deliver the result. |
| 334 | */ |
| 335 | r = Tss2_Sys_PolicyCounterTimer_Complete(esysContext->sys); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 336 | return_state_if_error(r, _ESYS_STATE_INTERNALERROR, "Received error from SAPI" |
dantpm | f6ef247 | 2018-04-06 15:21:59 -0700 | [diff] [blame] | 337 | " unmarshaling" ); |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 338 | esysContext->state = _ESYS_STATE_INIT; |
Juergen Repp | ff821bd | 2017-12-11 15:21:42 +0100 | [diff] [blame] | 339 | |
Andreas Fuchs | 4d9961e | 2018-03-20 15:51:48 +0100 | [diff] [blame] | 340 | return TSS2_RC_SUCCESS; |
Philip Tricca | 910f17c | 2018-03-15 12:38:37 -0700 | [diff] [blame] | 341 | } |