Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 1 | /* |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 2 | * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <cstdint> |
| 8 | #include <cstdio> |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 9 | #include <service/attestation/reporter/dump/pretty/pretty_report_dump.h> |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 12 | |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 13 | #include "attest_report_fetcher.h" |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 14 | #include "libpsa.h" |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 15 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 16 | int main(void) |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 17 | { |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 18 | 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 Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 22 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 23 | 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 Hall | b2954bc | 2021-08-12 11:52:11 +0100 | [diff] [blame] | 28 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 29 | 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 Hall | b2954bc | 2021-08-12 11:52:11 +0100 | [diff] [blame] | 34 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 35 | psa_status = psa_crypto_init(); |
| 36 | if (psa_status) { |
| 37 | printf("psa_crypto_init failed: %d\n", psa_status); |
| 38 | goto cleanup; |
| 39 | } |
Julian Hall | b2954bc | 2021-08-12 11:52:11 +0100 | [diff] [blame] | 40 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 41 | /* 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 Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 46 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 47 | cleanup: |
| 48 | libpsa_deinit_crypto_context(); |
| 49 | libpsa_deinit_attestation_context(); |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 50 | |
Gabor Toth | 3460b42 | 2023-07-17 10:29:24 +0200 | [diff] [blame] | 51 | return rval; |
Julian Hall | 4834e63 | 2021-05-26 15:33:06 +0100 | [diff] [blame] | 52 | } |