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 "test-esapi.h"
16 #include "esys_iutil.h"
17 #define LOGMODULE test
18 #include "util/log.h"
19 #include "util/aux_util.h"
20
21 /** Test the ESAPI function Esys_PP_Commands.
22 *
23 * If the test requires physical presence, the test is skipped.
24 *
25 *\b Note: platform authorization needed.
26 *
27 * Tested ESAPI commands:
28 * - Esys_PP_Commands() (O)
29 *
30 * @param[in,out] esys_context The ESYS_CONTEXT.
31 * @retval EXIT_FAILURE
32 * @retval EXIT_SKIP
33 * @retval EXIT_SUCCESS
34 */
35
36 int
test_esys_pp_commands(ESYS_CONTEXT * esys_context)37 test_esys_pp_commands(ESYS_CONTEXT * esys_context)
38 {
39 TSS2_RC r;
40 int failure_return = EXIT_FAILURE;
41
42 ESYS_TR auth_handle = ESYS_TR_RH_PLATFORM;
43 TPML_CC setList = {
44 .count = 1,
45 .commandCodes = { TPM2_CC_PP_Commands }
46 };
47 TPML_CC clearList = {0};
48
49 r = Esys_PP_Commands(esys_context, auth_handle,
50 ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
51 &setList, &clearList);
52
53 if ((r == TPM2_RC_COMMAND_CODE) ||
54 (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) ||
55 (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) {
56 LOG_WARNING("Command TPM2_PP_Commands not supported by TPM.");
57 failure_return = EXIT_SKIP;
58 }
59
60 if (r == (TPM2_RC_WARN | TPM2_RC_PP)) {
61 LOG_INFO("Command TPM2_PP_Commands requires physical presence.");
62 return EXIT_SUCCESS;
63 }
64
65 if ((r & ~TPM2_RC_N_MASK) == TPM2_RC_BAD_AUTH) {
66 /* Platform authorization not possible test will be skipped */
67 LOG_WARNING("Platform authorization not possible.");
68 failure_return = EXIT_SKIP;
69 }
70 goto_if_error(r, "Error: PP_Commands", error);
71
72 return EXIT_SUCCESS;
73
74 error:
75 return failure_return;
76 }
77
78 int
test_invoke_esapi(ESYS_CONTEXT * esys_context)79 test_invoke_esapi(ESYS_CONTEXT * esys_context) {
80 return test_esys_pp_commands(esys_context);
81 }
82