Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +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> |
| 8 | #include <rpc/common/endpoint/rpc_interface.h> |
| 9 | #include <service/attestation/provider/attest_provider.h> |
| 10 | #include <service/attestation/provider/serializer/packed-c/packedc_attest_provider_serializer.h> |
Julian Hall | 7bfb18e | 2021-07-13 15:48:13 +0100 | [diff] [blame^] | 11 | #include <service/crypto/factory/crypto_provider_factory.h> |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 12 | #include <components/service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h> |
| 13 | |
| 14 | /* Not needed once proxy backends added */ |
| 15 | #include <service/attestation/claims/claims_register.h> |
| 16 | #include <service/attestation/claims/sources/event_log/event_log_claim_source.h> |
| 17 | #include <service/attestation/claims/sources/boot_seed_generator/boot_seed_generator.h> |
| 18 | #include <service/attestation/claims/sources/null_lifecycle/null_lifecycle_claim_source.h> |
| 19 | #include <service/attestation/claims/sources/instance_id/instance_id_claim_source.h> |
| 20 | #include <service/secure_storage/backend/secure_flash_store/secure_flash_store.h> |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 21 | #include <service/crypto/backend/mbedcrypto/mbedcrypto_backend.h> |
Julian Hall | 644b57a | 2021-06-30 08:45:19 +0100 | [diff] [blame] | 22 | #include <service/attestation/key_mngr/local/local_attest_key_mngr.h> |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /* A shared storage backend - should be removed when proxy backends are added */ |
| 26 | static struct storage_backend *shared_storage_backend = NULL; |
| 27 | |
| 28 | |
| 29 | struct rpc_interface *attest_proxy_create(void) |
| 30 | { |
| 31 | struct rpc_interface *attest_iface; |
| 32 | struct claim_source *claim_source; |
| 33 | |
| 34 | /* Static objects for proxy instance */ |
| 35 | static struct attest_provider attest_provider; |
| 36 | |
| 37 | /* Claim sources for deployment */ |
| 38 | static struct event_log_claim_source event_log_claim_source; |
| 39 | static struct boot_seed_generator boot_seed_claim_source; |
| 40 | static struct null_lifecycle_claim_source lifecycle_claim_source; |
| 41 | static struct instance_id_claim_source instance_id_claim_source; |
| 42 | |
| 43 | /* Register claim sources for deployment */ |
| 44 | claims_register_init(); |
| 45 | |
| 46 | /* Boot measurement claim source */ |
| 47 | claim_source = event_log_claim_source_init_from_config(&event_log_claim_source); |
| 48 | claims_register_add_claim_source(CLAIM_CATEGORY_BOOT_MEASUREMENT, claim_source); |
| 49 | |
| 50 | /* Boot seed claim source */ |
| 51 | claim_source = boot_seed_generator_init(&boot_seed_claim_source); |
| 52 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 53 | |
| 54 | /* Lifecycle state claim source */ |
| 55 | claim_source = null_lifecycle_claim_source_init(&lifecycle_claim_source); |
| 56 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 57 | |
| 58 | /* Instance ID claim source */ |
| 59 | claim_source = instance_id_claim_source_init(&instance_id_claim_source); |
| 60 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 61 | |
| 62 | /* Initialize the service provider */ |
Julian Hall | 644b57a | 2021-06-30 08:45:19 +0100 | [diff] [blame] | 63 | local_attest_key_mngr_init(LOCAL_ATTEST_KEY_MNGR_VOLATILE_IAK); |
| 64 | attest_iface = attest_provider_init(&attest_provider); |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 65 | |
| 66 | attest_provider_register_serializer(&attest_provider, |
| 67 | TS_RPC_ENCODING_PACKED_C, packedc_attest_provider_serializer_instance()); |
| 68 | |
| 69 | return attest_iface; |
| 70 | } |
| 71 | |
| 72 | struct rpc_interface *crypto_proxy_create(void) |
| 73 | { |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 74 | struct rpc_interface *crypto_iface = NULL; |
Julian Hall | 7bfb18e | 2021-07-13 15:48:13 +0100 | [diff] [blame^] | 75 | struct crypto_provider *crypto_provider; |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 76 | |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 77 | if (mbedcrypto_backend_init(shared_storage_backend, 0) == PSA_SUCCESS) { |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 78 | |
Julian Hall | 7bfb18e | 2021-07-13 15:48:13 +0100 | [diff] [blame^] | 79 | crypto_provider = crypto_provider_factory_create(); |
| 80 | crypto_iface = service_provider_get_rpc_interface(&crypto_provider->base_provider); |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame] | 81 | } |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 82 | |
| 83 | return crypto_iface; |
| 84 | } |
| 85 | |
| 86 | struct rpc_interface *ps_proxy_create(void) |
| 87 | { |
| 88 | if (!shared_storage_backend) shared_storage_backend = sfs_init(); |
| 89 | |
| 90 | static struct secure_storage_provider ps_provider; |
| 91 | |
| 92 | return secure_storage_provider_init(&ps_provider, shared_storage_backend); |
| 93 | } |
| 94 | |
| 95 | struct rpc_interface *its_proxy_create(void) |
| 96 | { |
| 97 | if (!shared_storage_backend) shared_storage_backend = sfs_init(); |
| 98 | |
| 99 | static struct secure_storage_provider its_provider; |
| 100 | |
| 101 | return secure_storage_provider_init(&its_provider, shared_storage_backend); |
| 102 | } |