blob: ae1330bbfd56d91ac9147d90bde2b8168290ba1c [file] [log] [blame]
Julian Hall4834e632021-05-26 15:33:06 +01001/*
Gabor Toth3460b422023-07-17 10:29:24 +02002 * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
Julian Hall4834e632021-05-26 15:33:06 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <cstdint>
8#include <cstdio>
Gabor Toth3460b422023-07-17 10:29:24 +02009#include <service/attestation/reporter/dump/pretty/pretty_report_dump.h>
Julian Hall4834e632021-05-26 15:33:06 +010010#include <string>
11#include <vector>
Gabor Toth3460b422023-07-17 10:29:24 +020012
Julian Hall4834e632021-05-26 15:33:06 +010013#include "attest_report_fetcher.h"
Gabor Tothee2e7cb2024-10-07 17:02:56 +020014#include "libpsats.h"
Julian Hall4834e632021-05-26 15:33:06 +010015
Gabor Toth3460b422023-07-17 10:29:24 +020016int main(void)
Julian Hall4834e632021-05-26 15:33:06 +010017{
Gabor Toth3460b422023-07-17 10:29:24 +020018 psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
19 int rval = -1;
20 std::string error_msg;
21 std::vector<uint8_t> attest_report;
Julian Hall4834e632021-05-26 15:33:06 +010022
Gabor Tothee2e7cb2024-10-07 17:02:56 +020023 psa_status = libpsats_init_crypto_context("sn:trustedfirmware.org:crypto:0");
Gabor Toth3460b422023-07-17 10:29:24 +020024 if (psa_status) {
Gabor Tothee2e7cb2024-10-07 17:02:56 +020025 printf("libpsats_init_crypto_context failed: %d\n", psa_status);
Gabor Toth3460b422023-07-17 10:29:24 +020026 goto cleanup;
27 }
Julian Hallb2954bc2021-08-12 11:52:11 +010028
Gabor Tothee2e7cb2024-10-07 17:02:56 +020029 psa_status = libpsats_init_attestation_context("sn:trustedfirmware.org:attestation:0");
Gabor Toth3460b422023-07-17 10:29:24 +020030 if (psa_status) {
Gabor Tothee2e7cb2024-10-07 17:02:56 +020031 printf("libpsats_init_crypto_context failed: %d\n", psa_status);
Gabor Toth3460b422023-07-17 10:29:24 +020032 goto cleanup;
33 }
Julian Hallb2954bc2021-08-12 11:52:11 +010034
Gabor Toth3460b422023-07-17 10:29:24 +020035 psa_status = psa_crypto_init();
36 if (psa_status) {
37 printf("psa_crypto_init failed: %d\n", psa_status);
38 goto cleanup;
39 }
Julian Hallb2954bc2021-08-12 11:52:11 +010040
Gabor Toth3460b422023-07-17 10:29:24 +020041 /* Fetch platform info */
42 if (fetch_and_verify(attest_report, error_msg))
43 rval = pretty_report_dump(attest_report.data(), attest_report.size());
44 else
45 printf("%s\n", error_msg.c_str());
Julian Hall4834e632021-05-26 15:33:06 +010046
Gabor Toth3460b422023-07-17 10:29:24 +020047cleanup:
Gabor Tothee2e7cb2024-10-07 17:02:56 +020048 libpsats_deinit_crypto_context();
49 libpsats_deinit_attestation_context();
Julian Hall4834e632021-05-26 15:33:06 +010050
Gabor Toth3460b422023-07-17 10:29:24 +020051 return rval;
Julian Hall4834e632021-05-26 15:33:06 +010052}