blob: 903e6a6c5c89dbaa6d5b0ddf9b8fc0ec6313cf29 [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 Toth3460b422023-07-17 10:29:24 +020014#include "libpsa.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 Toth3460b422023-07-17 10:29:24 +020023 psa_status = libpsa_init_crypto_context("sn:trustedfirmware.org:crypto:0");
24 if (psa_status) {
25 printf("libpsa_init_crypto_context failed: %d\n", psa_status);
26 goto cleanup;
27 }
Julian Hallb2954bc2021-08-12 11:52:11 +010028
Gabor Toth3460b422023-07-17 10:29:24 +020029 psa_status = libpsa_init_attestation_context("sn:trustedfirmware.org:attestation:0");
30 if (psa_status) {
31 printf("libpsa_init_crypto_context failed: %d\n", psa_status);
32 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:
48 libpsa_deinit_crypto_context();
49 libpsa_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}