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 | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 24 | |
| 25 | |
| 26 | /* A shared storage backend - should be removed when proxy backends are added */ |
| 27 | static struct storage_backend *shared_storage_backend = NULL; |
| 28 | |
| 29 | |
| 30 | struct rpc_interface *attest_proxy_create(void) |
| 31 | { |
| 32 | struct rpc_interface *attest_iface; |
| 33 | struct claim_source *claim_source; |
| 34 | |
| 35 | /* Static objects for proxy instance */ |
| 36 | static struct attest_provider attest_provider; |
| 37 | |
| 38 | /* Claim sources for deployment */ |
| 39 | static struct event_log_claim_source event_log_claim_source; |
| 40 | static struct boot_seed_generator boot_seed_claim_source; |
| 41 | static struct null_lifecycle_claim_source lifecycle_claim_source; |
| 42 | static struct instance_id_claim_source instance_id_claim_source; |
| 43 | |
| 44 | /* Register claim sources for deployment */ |
| 45 | claims_register_init(); |
| 46 | |
| 47 | /* Boot measurement claim source */ |
| 48 | claim_source = event_log_claim_source_init_from_config(&event_log_claim_source); |
| 49 | claims_register_add_claim_source(CLAIM_CATEGORY_BOOT_MEASUREMENT, claim_source); |
| 50 | |
| 51 | /* Boot seed claim source */ |
| 52 | claim_source = boot_seed_generator_init(&boot_seed_claim_source); |
| 53 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 54 | |
| 55 | /* Lifecycle state claim source */ |
| 56 | claim_source = null_lifecycle_claim_source_init(&lifecycle_claim_source); |
| 57 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 58 | |
| 59 | /* Instance ID claim source */ |
| 60 | claim_source = instance_id_claim_source_init(&instance_id_claim_source); |
| 61 | claims_register_add_claim_source(CLAIM_CATEGORY_DEVICE, claim_source); |
| 62 | |
| 63 | /* Initialize the service provider */ |
| 64 | attest_iface = attest_provider_init(&attest_provider, ATTEST_KEY_MNGR_VOLATILE_IAK); |
| 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 | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 75 | |
| 76 | /* Static objects for proxy instance */ |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame^] | 77 | static struct crypto_provider crypto_provider; |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 78 | |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame^] | 79 | if (mbedcrypto_backend_init(shared_storage_backend, 0) == PSA_SUCCESS) { |
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 | crypto_iface = crypto_provider_init(&crypto_provider); |
| 82 | |
| 83 | crypto_provider_register_serializer(&crypto_provider, |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 84 | TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance()); |
| 85 | |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame^] | 86 | crypto_provider_register_serializer(&crypto_provider, |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 87 | TS_RPC_ENCODING_PACKED_C, packedc_crypto_provider_serializer_instance()); |
Julian Hall | 9061e6c | 2021-06-29 14:24:20 +0100 | [diff] [blame^] | 88 | } |
Julian Hall | 527ddd5 | 2021-06-28 11:57:17 +0100 | [diff] [blame] | 89 | |
| 90 | return crypto_iface; |
| 91 | } |
| 92 | |
| 93 | struct rpc_interface *ps_proxy_create(void) |
| 94 | { |
| 95 | if (!shared_storage_backend) shared_storage_backend = sfs_init(); |
| 96 | |
| 97 | static struct secure_storage_provider ps_provider; |
| 98 | |
| 99 | return secure_storage_provider_init(&ps_provider, shared_storage_backend); |
| 100 | } |
| 101 | |
| 102 | struct rpc_interface *its_proxy_create(void) |
| 103 | { |
| 104 | if (!shared_storage_backend) shared_storage_backend = sfs_init(); |
| 105 | |
| 106 | static struct secure_storage_provider its_provider; |
| 107 | |
| 108 | return secure_storage_provider_init(&its_provider, shared_storage_backend); |
| 109 | } |