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