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_fapi.h"
14
15 #include "test-fapi.h"
16
17 #define LOGMODULE test
18 #include "util/log.h"
19 #include "util/aux_util.h"
20
21 /** Test the FAPI functions for platform certificates.
22 *
23 * Tested FAPI commands:
24 * - Fapi_Provision()
25 * - Fapi_GetPlatformCertificates()
26 * - Fapi_Delete()
27 *
28 * @param[in,out] context The FAPI_CONTEXT.
29 * @retval EXIT_FAILURE
30 * @retval EXIT_SUCCESS
31 */
32 int
test_fapi_platform_certificates(FAPI_CONTEXT * context)33 test_fapi_platform_certificates(FAPI_CONTEXT *context)
34 {
35 TSS2_RC r;
36 uint8_t *certs = NULL;
37 size_t certsSize = 0;
38
39 r = Fapi_Provision(context, NULL, NULL, NULL);
40 goto_if_error(r, "Error Fapi_Provision", error);
41
42 r = Fapi_GetPlatformCertificates(context, &certs, &certsSize);
43 if (r == TSS2_FAPI_RC_NO_CERT)
44 goto skip;
45 goto_if_error(r, "Error Fapi_GetPlatformCertificates", error);
46
47 Fapi_Free(certs);
48
49 /* Cleanup */
50 r = Fapi_Delete(context, "/HS/SRK");
51 goto_if_error(r, "Error Fapi_Delete", error);
52
53 return EXIT_SUCCESS;
54
55 error:
56 Fapi_Delete(context, "/HS/SRK");
57 return EXIT_FAILURE;
58
59 skip:
60 Fapi_Delete(context, "/HS/SRK");
61 return EXIT_SKIP;
62 }
63
64 int
test_invoke_fapi(FAPI_CONTEXT * fapi_context)65 test_invoke_fapi(FAPI_CONTEXT *fapi_context)
66 {
67 return test_fapi_platform_certificates(fapi_context);
68 }
69