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