xref: /aosp_15_r20/external/tpm2-tss/test/integration/esys-change-eps.int.c (revision 758e9fba6fc9adbf15340f70c73baee7b168b1c9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*******************************************************************************
3  * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG
4  * All rights reserved.
5  *******************************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include <stdlib.h>
12 
13 #include "tss2_esys.h"
14 
15 #include "esys_iutil.h"
16 #include "test-esapi.h"
17 #define LOGMODULE test
18 #include "util/log.h"
19 #include "util/aux_util.h"
20 
21 /** Test the ESAPI function Esys_ChangeEPS.
22  *
23  *\b Note: platform authorization needed.
24  *
25  * Tested ESAPI commands:
26  *  - Esys_ChangeEPS() (O)
27  *
28  * @param[in,out] esys_context The ESYS_CONTEXT.
29  * @retval EXIT_FAILURE
30  * @retval EXIT_SKIP
31  * @retval EXIT_SUCCESS
32  */
33 int
test_esys_change_eps(ESYS_CONTEXT * esys_context)34 test_esys_change_eps(ESYS_CONTEXT * esys_context)
35 {
36     TSS2_RC r;
37 
38     ESYS_TR authHandle = ESYS_TR_RH_PLATFORM;
39 
40     r = Esys_ChangeEPS(
41         esys_context,
42         authHandle,
43         ESYS_TR_PASSWORD,
44         ESYS_TR_NONE,
45         ESYS_TR_NONE);
46 
47     if ((r == TPM2_RC_COMMAND_CODE) ||
48         (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) ||
49         (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) {
50         LOG_WARNING("Command TPM2_ChangeEPS not supported by TPM.");
51         return  EXIT_SKIP;
52         goto error;
53     }
54 
55     if ((r & ~TPM2_RC_N_MASK) == TPM2_RC_BAD_AUTH) {
56         /* Platform authorization not possible test will be skipped */
57         LOG_WARNING("Platform authorization not possible.");
58         return EXIT_SKIP;
59     }
60 
61     goto_if_error(r, "Error: ChangeEPS", error);
62 
63     return EXIT_SUCCESS;
64 
65  error:
66     return EXIT_FAILURE;
67 }
68 
69 int
test_invoke_esapi(ESYS_CONTEXT * esys_context)70 test_invoke_esapi(ESYS_CONTEXT * esys_context) {
71     return test_esys_change_eps(esys_context);
72 }
73