Attest: Make possible to remove the optional claims
As part of the optimization work, a compile time switch was
introduced to make possible to exclude the optional claims from
the initial attestation token. Removal of optional claims reduces
the token size and the code size as well. Default behaviour is to
include the optional claims.
Change-Id: Ib48789f8cce1c8fa971ab46d4e09bf2f6bd628a1
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
diff --git a/CommonConfig.cmake b/CommonConfig.cmake
index e409cbe..15635e1 100644
--- a/CommonConfig.cmake
+++ b/CommonConfig.cmake
@@ -300,7 +300,7 @@
#Default TF-M secure storage flags.
#These flags values can be overwritten by setting them in platform/ext/<TARGET_NAME>.cmake
-#Documentation about these flags can be found in docs/user_guides/services/tfm_sst_integration_guide.md
+#Documentation about these flags can be found in docs/user_guides/services/tfm_sst_integration_guide.rst
if (NOT DEFINED SST_ENCRYPTION)
set (SST_ENCRYPTION ON)
endif()
@@ -337,6 +337,12 @@
set(MBEDTLS_DEBUG OFF)
endif()
+#Default TF-M initial-attestation service flags.
+#Documentation about these flags can be found in docs/user_guides/services/tfm_attestation_integration_guide.rst
+if (NOT DEFINED ATTEST_INCLUDE_OPTIONAL_CLAIMS)
+ set(ATTEST_INCLUDE_OPTIONAL_CLAIMS ON)
+endif()
+
##Set mbedTLS compiler flags for BL2 bootloader
set(MBEDTLS_C_FLAGS_BL2 "-D__ARM_FEATURE_CMSE=${ARM_FEATURE_CMSE} -D__thumb2__ ${COMMON_COMPILE_FLAGS_STR} -DMBEDTLS_CONFIG_FILE=\\\\\\\"config-boot.h\\\\\\\" -I${CMAKE_CURRENT_LIST_DIR}/bl2/ext/mcuboot/include")
if (MCUBOOT_SIGNATURE_TYPE STREQUAL "RSA-3072")
diff --git a/docs/user_guides/services/tfm_attestation_integration_guide.rst b/docs/user_guides/services/tfm_attestation_integration_guide.rst
index 32dd586..9a3464e 100644
--- a/docs/user_guides/services/tfm_attestation_integration_guide.rst
+++ b/docs/user_guides/services/tfm_attestation_integration_guide.rst
@@ -422,6 +422,15 @@
attestation key is directly retrieved by the Crypto service then this key
handling is not necessary.
+Initial Attestation Service compile time options
+================================================
+There is a defined set of flags that can be used to compile in/out certain
+service features. The ``CommonConfig.cmake`` file sets the default values of
+those flags. The list of flags are:
+
+- ``ATTEST_INCLUDE_OPTIONAL_CLAIMS``: Include also the optional claims to the
+ attestation token. Default value: True.
+
************
Verification
************
diff --git a/secure_fw/services/initial_attestation/CMakeLists.inc b/secure_fw/services/initial_attestation/CMakeLists.inc
index 5a9c07f..41ca3d9 100644
--- a/secure_fw/services/initial_attestation/CMakeLists.inc
+++ b/secure_fw/services/initial_attestation/CMakeLists.inc
@@ -21,62 +21,66 @@
#Get the current directory where this file is located.
set(INITIAL_ATTESTATION_DIR ${CMAKE_CURRENT_LIST_DIR})
-#Check input variables
-if (NOT DEFINED ENABLE_INITIAL_ATTESTATION)
- message(FATAL_ERROR "Incomplete build configuration: ENABLE_INITIAL_ATTESTATION is undefined. ")
+if (NOT DEFINED ATTEST_INCLUDE_OPTIONAL_CLAIMS)
+ message(FATAL_ERROR "Incomplete build configuration: ATTEST_INCLUDE_OPTIONAL_CLAIMS is undefined. ")
endif()
-if (ENABLE_INITIAL_ATTESTATION)
- if (NOT DEFINED TFM_ROOT_DIR)
- message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
- endif()
+if (NOT DEFINED TFM_ROOT_DIR)
+ message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
- #Append all our source files to global lists.
- list(APPEND ALL_SRC_C
- "${INITIAL_ATTESTATION_DIR}/tfm_attestation_secure_api.c"
- "${INITIAL_ATTESTATION_DIR}/tfm_attestation.c"
- "${INITIAL_ATTESTATION_DIR}/tfm_attestation_req_mngr.c"
- "${INITIAL_ATTESTATION_DIR}/attestation_core.c"
- "${INITIAL_ATTESTATION_DIR}/attestation_key.c"
- "${INITIAL_ATTESTATION_DIR}/attest_token.c"
- )
+list(APPEND ATTEST_C_SRC
+ "${INITIAL_ATTESTATION_DIR}/tfm_attestation_secure_api.c"
+ "${INITIAL_ATTESTATION_DIR}/tfm_attestation.c"
+ "${INITIAL_ATTESTATION_DIR}/tfm_attestation_req_mngr.c"
+ "${INITIAL_ATTESTATION_DIR}/attestation_core.c"
+ "${INITIAL_ATTESTATION_DIR}/attestation_key.c"
+ "${INITIAL_ATTESTATION_DIR}/attest_token.c"
+ )
- #Setting include directories
- embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/platform/ext/common ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/platform/include ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/bl2/include ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/include ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/ext/qcbor/inc ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/t_cose/inc ABSOLUTE)
- embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/t_cose/src ABSOLUTE)
- embedded_include_directories(PATH ${INITIAL_ATTESTATION_DIR} ABSOLUTE)
+if (ATTEST_INCLUDE_OPTIONAL_CLAIMS)
+ set_property(SOURCE ${ATTEST_C_SRC} APPEND PROPERTY COMPILE_DEFINITIONS INCLUDE_OPTIONAL_CLAIMS)
+endif()
- set(BUILD_CMSIS_CORE Off)
- set(BUILD_RETARGET Off)
- set(BUILD_NATIVE_DRIVERS Off)
- set(BUILD_STARTUP Off)
- set(BUILD_TARGET_CFG Off)
- set(BUILD_TARGET_HARDWARE_KEYS Off)
- set(BUILD_TARGET_NV_COUNTERS Off)
- set(BUILD_CMSIS_DRIVERS Off)
- set(BUILD_TIME Off)
- set(BUILD_UART_STDOUT Off)
- set(BUILD_FLASH Off)
- set(BUILD_BOOT_SEED On)
- set(BUILD_DEVICE_ID On)
- set(BUILD_PLAT_TEST Off)
- if(NOT DEFINED PLATFORM_CMAKE_FILE)
- message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
- elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
- message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
- else()
- include(${PLATFORM_CMAKE_FILE})
- endif()
+#Inform the user about attestation service features selected based on the cmake flags
+message("The Initial Attestation service compile configuration is as follows:")
+message("- ATTEST_INCLUDE_OPTIONAL_CLAIMS: ${ATTEST_INCLUDE_OPTIONAL_CLAIMS}")
+#Setting include directories
+embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/platform/ext/common ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/platform/include ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/bl2/include ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/include ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/ext/qcbor/inc ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/t_cose/inc ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/lib/t_cose/src ABSOLUTE)
+embedded_include_directories(PATH ${INITIAL_ATTESTATION_DIR} ABSOLUTE)
+
+set(BUILD_CMSIS_CORE Off)
+set(BUILD_RETARGET Off)
+set(BUILD_NATIVE_DRIVERS Off)
+set(BUILD_STARTUP Off)
+set(BUILD_TARGET_CFG Off)
+set(BUILD_TARGET_HARDWARE_KEYS Off)
+set(BUILD_TARGET_NV_COUNTERS Off)
+set(BUILD_CMSIS_DRIVERS Off)
+set(BUILD_TIME Off)
+set(BUILD_UART_STDOUT Off)
+set(BUILD_FLASH Off)
+set(BUILD_BOOT_SEED On)
+set(BUILD_DEVICE_ID On)
+set(BUILD_PLAT_TEST Off)
+if(NOT DEFINED PLATFORM_CMAKE_FILE)
+ message (FATAL_ERROR "Platform specific CMake is not defined. Please set PLATFORM_CMAKE_FILE.")
+elseif(NOT EXISTS ${PLATFORM_CMAKE_FILE})
+ message (FATAL_ERROR "Platform specific CMake \"${PLATFORM_CMAKE_FILE}\" file does not exist. Please fix value of PLATFORM_CMAKE_FILE.")
else()
- message(FATAL_ERROR "Build system currently doesn't support selectively disabling of a service.")
+ include(${PLATFORM_CMAKE_FILE})
endif()
+#Append all our source files to global lists.
+list(APPEND ALL_SRC_C ${ATTEST_C_SRC})
+unset(ATTEST_C_SRC)
diff --git a/secure_fw/services/initial_attestation/CMakeLists.txt b/secure_fw/services/initial_attestation/CMakeLists.txt
index 7b775db..6ca7da0 100644
--- a/secure_fw/services/initial_attestation/CMakeLists.txt
+++ b/secure_fw/services/initial_attestation/CMakeLists.txt
@@ -23,7 +23,6 @@
embedded_project_fixup()
#Get the definition of what files we need to build
-set (ENABLE_INITIAL_ATTESTATION ON)
include(CMakeLists.inc)
if (NOT DEFINED TFM_LVL)
diff --git a/secure_fw/services/initial_attestation/attestation_core.c b/secure_fw/services/initial_attestation/attestation_core.c
index be5da2c..ac53fd6 100644
--- a/secure_fw/services/initial_attestation/attestation_core.c
+++ b/secure_fw/services/initial_attestation/attestation_core.c
@@ -591,50 +591,6 @@
}
/*!
- * \brief Static function to add hardware version claim to attestation token.
- *
- * \param[in] token_ctx Token encoding context
- *
- * \return Returns error code as specified in \ref psa_attest_err_t
- */
-static enum psa_attest_err_t
-attest_add_hw_version_claim(struct attest_token_ctx *token_ctx)
-{
- uint8_t hw_version[HW_VERSION_MAX_SIZE];
- enum tfm_plat_err_t res_plat;
- uint32_t size = sizeof(hw_version);
- struct q_useful_buf_c claim_value = {0};
- uint16_t tlv_len;
- uint8_t *tlv_ptr = NULL;
- int32_t found = 0;
-
- /* First look up HW version in boot status, it might comes
- * from bootloader
- */
- found = attest_get_tlv_by_id(HW_VERSION, &tlv_len, &tlv_ptr);
- if (found == 1) {
- claim_value.ptr = tlv_ptr + SHARED_DATA_ENTRY_HEADER_SIZE;
- claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
- } else {
- /* If not found in boot status then use callback function to get it
- * from runtime SW
- */
- res_plat = tfm_plat_get_hw_version(&size, hw_version);
- if (res_plat != TFM_PLAT_ERR_SUCCESS) {
- return PSA_ATTEST_ERR_CLAIM_UNAVAILABLE;
- }
- claim_value.ptr = hw_version;
- claim_value.len = size;
- }
-
- attest_token_add_tstr(token_ctx,
- EAT_CBOR_ARM_LABEL_HW_VERSION,
- &claim_value);
-
- return PSA_ATTEST_ERR_SUCCESS;
-}
-
-/*!
* \brief Static function to add caller id claim to attestation token.
*
* \param[in] token_ctx Token encoding context
@@ -727,6 +683,7 @@
return PSA_ATTEST_ERR_SUCCESS;
}
+#ifdef INCLUDE_OPTIONAL_CLAIMS /* Remove them from release build */
/*!
* \brief Static function to add the verification service indicator claim
* to the attestation token.
@@ -779,6 +736,51 @@
}
/*!
+ * \brief Static function to add hardware version claim to attestation token.
+ *
+ * \param[in] token_ctx Token encoding context
+ *
+ * \return Returns error code as specified in \ref psa_attest_err_t
+ */
+static enum psa_attest_err_t
+attest_add_hw_version_claim(struct attest_token_ctx *token_ctx)
+{
+ uint8_t hw_version[HW_VERSION_MAX_SIZE];
+ enum tfm_plat_err_t res_plat;
+ uint32_t size = sizeof(hw_version);
+ struct q_useful_buf_c claim_value = {0};
+ uint16_t tlv_len;
+ uint8_t *tlv_ptr = NULL;
+ int32_t found = 0;
+
+ /* First look up HW version in boot status, it might comes
+ * from bootloader
+ */
+ found = attest_get_tlv_by_id(HW_VERSION, &tlv_len, &tlv_ptr);
+ if (found == 1) {
+ claim_value.ptr = tlv_ptr + SHARED_DATA_ENTRY_HEADER_SIZE;
+ claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
+ } else {
+ /* If not found in boot status then use callback function to get it
+ * from runtime SW
+ */
+ res_plat = tfm_plat_get_hw_version(&size, hw_version);
+ if (res_plat != TFM_PLAT_ERR_SUCCESS) {
+ return PSA_ATTEST_ERR_CLAIM_UNAVAILABLE;
+ }
+ claim_value.ptr = hw_version;
+ claim_value.len = size;
+ }
+
+ attest_token_add_tstr(token_ctx,
+ EAT_CBOR_ARM_LABEL_HW_VERSION,
+ &claim_value);
+
+ return PSA_ATTEST_ERR_SUCCESS;
+}
+#endif /* INCLUDE_OPTIONAL_CLAIMS */
+
+/*!
* \brief Static function to verify the input challenge size
*
* Only discrete sizes are accepted.
@@ -898,31 +900,17 @@
}
if (!(option_flags & TOKEN_OPT_OMIT_CLAIMS)) {
+ /* Mandatory claims in IAT token */
attest_err = attest_add_boot_seed_claim(&attest_token_ctx);
if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
goto error;
}
- attest_err = attest_add_verification_service(&attest_token_ctx);
- if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
- goto error;
- }
-
- attest_err = attest_add_profile_definition(&attest_token_ctx);
- if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
- goto error;
- }
-
attest_err = attest_add_instance_id_claim(&attest_token_ctx);
if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
goto error;
}
- attest_err = attest_add_hw_version_claim(&attest_token_ctx);
- if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
- goto error;
- }
-
attest_err = attest_add_implementation_id_claim(&attest_token_ctx);
if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
goto error;
@@ -942,6 +930,24 @@
if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
goto error;
}
+
+#ifdef INCLUDE_OPTIONAL_CLAIMS
+ /* Optional claims in IAT token, remove them from release build */
+ attest_err = attest_add_verification_service(&attest_token_ctx);
+ if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
+ goto error;
+ }
+
+ attest_err = attest_add_profile_definition(&attest_token_ctx);
+ if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
+ goto error;
+ }
+
+ attest_err = attest_add_hw_version_claim(&attest_token_ctx);
+ if (attest_err != PSA_ATTEST_ERR_SUCCESS) {
+ goto error;
+ }
+#endif /* INCLUDE_OPTIONAL_CLAIMS */
}
/* Finish up creating the token. This is where the actual signature