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