Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stddef.h> |
Julian Hall | 3b2fc5c | 2021-08-12 15:56:07 +0100 | [diff] [blame] | 8 | #include <psa/crypto.h> |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 9 | #include <service_locator.h> |
| 10 | #include <service/attestation/client/psa/iat_client.h> |
| 11 | #include <service/attestation/client/provision/attest_provision_client.h> |
| 12 | #include <protocols/rpc/common/packed-c/encoding.h> |
| 13 | #include "../service_under_test.h" |
| 14 | |
| 15 | /* RPC context */ |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 16 | static struct rpc_caller_session *session = NULL; |
| 17 | static struct service_context *attestation_service_context = NULL; |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 18 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 19 | int locate_service_under_test(void) |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 20 | { |
| 21 | int status = -1; |
| 22 | |
Julian Hall | 3b2fc5c | 2021-08-12 15:56:07 +0100 | [diff] [blame] | 23 | /* Attestation tests depend on PSA crypto so ensure library is initialised */ |
| 24 | psa_status_t psa_status = psa_crypto_init(); |
| 25 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 26 | if ((psa_status == PSA_SUCCESS) && !session && !attestation_service_context) { |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 27 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 28 | service_locator_init(); |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 29 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 30 | attestation_service_context = |
| 31 | service_locator_query("sn:trustedfirmware.org:attestation:0"); |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 32 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 33 | if (attestation_service_context) { |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 34 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 35 | session = service_context_open(attestation_service_context); |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 36 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 37 | if (session) { |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 38 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 39 | psa_iat_client_init(session); |
| 40 | attest_provision_client_init(session); |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 41 | |
| 42 | status = 0; |
| 43 | } |
| 44 | else { |
| 45 | |
| 46 | status = -1; |
| 47 | relinquish_service_under_test(); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return status; |
| 53 | } |
| 54 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 55 | int relinquish_service_under_test(void) |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 56 | { |
| 57 | psa_iat_client_deinit(); |
| 58 | attest_provision_client_deinit(); |
| 59 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 60 | if (attestation_service_context && session) { |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 61 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 62 | service_context_close(attestation_service_context, session); |
| 63 | session = NULL; |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 66 | if (attestation_service_context) { |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 67 | |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 68 | service_context_relinquish(attestation_service_context); |
| 69 | attestation_service_context = NULL; |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 70 | } |
Balint Dobszay | 3d9403a | 2023-07-11 16:47:21 +0200 | [diff] [blame] | 71 | |
| 72 | return 0; |
Julian Hall | b7db580 | 2021-07-26 16:20:40 +0100 | [diff] [blame] | 73 | } |