From 2e591da2797a7ab557178b35de6170b1db21cabd Mon Sep 17 00:00:00 2001 From: Ken Takayama Date: Tue, 26 Nov 2024 00:17:12 +0000 Subject: [PATCH] add: process component metadata --- inc/csuit/suit_manifest_decode.h | 9 +++- src/suit_manifest_process.c | 87 +++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 31 deletions(-) diff --git a/inc/csuit/suit_manifest_decode.h b/inc/csuit/suit_manifest_decode.h index 5898482..683d71a 100644 --- a/inc/csuit/suit_manifest_decode.h +++ b/inc/csuit/suit_manifest_decode.h @@ -67,12 +67,17 @@ suit_err_t suit_decode_dependencies_from_item(suit_decode_mode_t mode, bool next, suit_dependencies_t *dependencies); +suit_err_t suit_decode_version_match_from_item(QCBORDecodeContext *context, + QCBORItem *item, + bool next, + suit_version_match_t *version_match); +suit_err_t suit_decode_version_match(const suit_buf_t *buf, + suit_version_match_t *version_match); + suit_err_t suit_decode_wait_event_from_item(QCBORDecodeContext *context, QCBORItem *item, bool next, suit_wait_event_t *wait_event); -suit_err_t suit_decode_version_match(const suit_buf_t *buf, - suit_version_match_t *version_match); suit_err_t suit_decode_wait_event(const suit_buf_t *buf, suit_wait_event_t *wait_event); diff --git a/src/suit_manifest_process.c b/src/suit_manifest_process.c index 97d2b5b..a14a383 100644 --- a/src/suit_manifest_process.c +++ b/src/suit_manifest_process.c @@ -41,7 +41,9 @@ suit_err_t suit_set_parameters(QCBORDecodeContext *context, UsefulBufC str; bool b; suit_digest_t digest; + suit_version_match_t version_match; suit_wait_event_t wait_event; + suit_component_metadata_t component_metadata; } val; size_t length = item.val.uCount; @@ -258,8 +260,8 @@ suit_err_t suit_set_parameters(QCBORDecodeContext *context, break; #endif /* !LIBCSUIT_DISABLE_PARAMETER_FETCH_ARGS */ - /* bstr .cbor COSE_Encrypt0 // bstr .cbor COSE_Encrypt */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_ENCRYPTION_INFO) + /* bstr .cbor COSE_Encrypt0 // bstr .cbor COSE_Encrypt */ case SUIT_PARAMETER_ENCRYPTION_INFO: QCBORDecode_GetByteString(context, &val.str); for (size_t j = 0; j < suit_index->len; j++) { @@ -277,55 +279,71 @@ suit_err_t suit_set_parameters(QCBORDecodeContext *context, QCBORDecode_EnterBstrWrapped(context, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL); result = suit_decode_digest_from_item(SUIT_DECODE_MODE_STRICT, context, &item, true, &val.digest); QCBORDecode_ExitBstrWrapped(context); - for (size_t j = 0; j < suit_index->len; j++) { - uint8_t tmp_index = suit_index->index[j]; - if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_IMAGE_DIGEST) || override) { - parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_IMAGE_DIGEST; - parameters[tmp_index].image_digest = val.digest; + if (result == SUIT_SUCCESS) { + for (size_t j = 0; j < suit_index->len; j++) { + uint8_t tmp_index = suit_index->index[j]; + if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_IMAGE_DIGEST) || override) { + parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_IMAGE_DIGEST; + parameters[tmp_index].image_digest = val.digest; + } } } break; - /* SUIT_Parameter_Version_Match */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION) + /* bstr .cbor SUIT_Parameter_Version_Match */ case SUIT_PARAMETER_VERSION: QCBORDecode_EnterBstrWrapped(context, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL); - QCBORDecode_EnterArray(context, &item); - for (size_t j = 0; j < suit_index->len; j++) { - uint8_t tmp_index = suit_index->index[j]; - if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_VERSION) || override) { - parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_VERSION; - QCBORDecode_GetInt64(context, &val.i64); - parameters[tmp_index].version_match.type = val.i64; - QCBORDecode_EnterArray(context, &item); - parameters[tmp_index].version_match.value.len = item.val.uCount; - for (size_t k = 0; k < parameters[tmp_index].version_match.value.len; k++) { - QCBORDecode_GetInt64(context, ¶meters[tmp_index].version_match.value.int64[k]); + result = suit_decode_version_match_from_item(context, &item, true, &val.version_match); + QCBORDecode_ExitBstrWrapped(context); + if (result == SUIT_SUCCESS) { + for (size_t j = 0; j < suit_index->len; j++) { + uint8_t tmp_index = suit_index->index[j]; + if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_VERSION) || override) { + parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_VERSION; + parameters[tmp_index].version_match = val.version_match; } - QCBORDecode_ExitArray(context); } } - QCBORDecode_ExitArray(context); - QCBORDecode_ExitBstrWrapped(context); break; #endif /* !LIBCSUIT_DISABLE_PARAMETER_VERSION */ - /* bstr .cbor SUIT_Wait_Event */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO) + /* bstr .cbor SUIT_Wait_Event */ case SUIT_PARAMETER_WAIT_INFO: QCBORDecode_EnterBstrWrapped(context, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL); result = suit_decode_wait_event_from_item(context, &item, true, &val.wait_event); QCBORDecode_ExitBstrWrapped(context); - for (size_t j = 0; j < suit_index->len; j++) { - uint8_t tmp_index = suit_index->index[j]; - if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_WAIT_INFO) || override) { - parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_WAIT_INFO; - parameters[tmp_index].wait_info = val.wait_event; + if (result == SUIT_SUCCESS) { + for (size_t j = 0; j < suit_index->len; j++) { + uint8_t tmp_index = suit_index->index[j]; + if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_WAIT_INFO) || override) { + parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_WAIT_INFO; + parameters[tmp_index].wait_info = val.wait_event; + } } } break; #endif /* !LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO */ +#if !defined(LIBCSUIT_DISABLE_PARAMETER_COMPONENT_METADATA) + /* bstr .cbor SUIT_Component_Metadata */ + case SUIT_PARAMETER_COMPONENT_METADATA: + QCBORDecode_EnterBstrWrapped(context, QCBOR_TAG_REQUIREMENT_NOT_A_TAG, NULL); + result = suit_decode_component_metadata_from_item(context, &item, true, &val.component_metadata); + QCBORDecode_ExitBstrWrapped(context); + if (result == SUIT_SUCCESS) { + for (size_t j = 0; j < suit_index->len; j++) { + uint8_t tmp_index = suit_index->index[j]; + if (!(parameters[tmp_index].exists & SUIT_PARAMETER_CONTAINS_COMPONENT_METADATA) || override) { + parameters[tmp_index].exists |= SUIT_PARAMETER_CONTAINS_COMPONENT_METADATA; + parameters[tmp_index].component_metadata = val.component_metadata; + } + } + } + break; +#endif + case SUIT_PARAMETER_INVALID: default: result = SUIT_ERR_NOT_IMPLEMENTED; @@ -1340,8 +1358,8 @@ suit_err_t suit_process_copy_params(QCBORDecodeContext *context, parameters[tmp_index].image_digest = parameters[src_index].image_digest; break; - /* SUIT_Parameter_Version_Match */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_VERSION) + /* SUIT_Parameter_Version_Match */ case SUIT_PARAMETER_VERSION: if (!(parameters[src_index].exists & SUIT_PARAMETER_CONTAINS_VERSION)) { return SUIT_ERR_PARAMETER_NOT_FOUND; @@ -1351,8 +1369,8 @@ suit_err_t suit_process_copy_params(QCBORDecodeContext *context, break; #endif - /* bstr .cbor SUIT_Wait_Event */ #if !defined(LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO) + /* SUIT_Wait_Event */ case SUIT_PARAMETER_WAIT_INFO: if (!(parameters[src_index].exists & SUIT_PARAMETER_CONTAINS_WAIT_INFO)) { return SUIT_ERR_PARAMETER_NOT_FOUND; @@ -1362,6 +1380,17 @@ suit_err_t suit_process_copy_params(QCBORDecodeContext *context, break; #endif /* !LIBCSUIT_DISABLE_PARAMETER_WAIT_INFO */ +#if !defined(LIBCSUIT_DISABLE_PARAMETER_COMPONENT_METADATA) + /* SUIT_Component_Metadata */ + case SUIT_PARAMETER_COMPONENT_METADATA: + if (!(parameters[src_index].exists & SUIT_PARAMETER_COMPONENT_METADATA)) { + return SUIT_ERR_PARAMETER_NOT_FOUND; + } + parameters[tmp_index].exists != SUIT_PARAMETER_CONTAINS_COMPONENT_METADATA; + parameters[tmp_index].component_metadata = parameters[src_index].component_metadata; + break; +#endif + case SUIT_PARAMETER_INVALID: default: return SUIT_ERR_NOT_IMPLEMENTED;