Skip to content

Commit

Permalink
ETag: Add CRC64 checksum for each stored resource
Browse files Browse the repository at this point in the history
- Implemented the calculation of a CRC64 checksum for each resource
payload.
- By default, the GET payload with the "oic.if.baseline" interface
is used for a resource.
- Special handling is added for resources `/x.plgd.dev/time` and
`/oic/res`, which contain properties that might change on each GET
request. For these resources, an internal "x.plgd.if.etag"
interface is used to filter out problematic properties from the
payload.
- Updated the ETag storage payload to include not only the ETag
of the given resource but also the checksum for the resource.
- When data is loaded from storage, it now verifies the checksum
before processing, ensuring data integrity.
  • Loading branch information
Danielius1922 authored and Daniel Adam committed Oct 23, 2023
1 parent b9277a1 commit afb52af
Show file tree
Hide file tree
Showing 25 changed files with 1,374 additions and 357 deletions.
3 changes: 2 additions & 1 deletion api/cloud/rd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ _add_resource_payload(CborEncoder *parent, oc_resource_t *resource,
oc_rep_start_object(parent, links);
oc_rep_set_text_string(links, href, oc_string(resource->uri));
oc_rep_set_string_array(links, rt, resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links), resource->interfaces);
oc_core_encode_interfaces_mask(oc_rep_object(links), resource->interfaces,
false);
if (rel)
oc_rep_set_text_string(links, rel, rel);
oc_rep_set_int(links, ins, ins);
Expand Down
8 changes: 5 additions & 3 deletions api/oc_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ oc_handle_collection_create_request(oc_method_t method, oc_request_t *request)
oc_string_len(new_res->resource->uri));
oc_rep_set_string_array(root, rt, new_res->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(root),
new_res->resource->interfaces);
new_res->resource->interfaces, false);
oc_rep_set_object(root, p);
oc_rep_set_uint(p, bm, (uint8_t)(bm & ~(OC_PERIODIC | OC_SECURE)));
oc_rep_close_object(root, p);
Expand Down Expand Up @@ -676,7 +676,8 @@ collection_encode_links(const oc_collection_t *collection,
oc_rep_set_text_string_v1(links, href, oc_string(link->resource->uri),
oc_string_len(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces,
false);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
Expand Down Expand Up @@ -814,7 +815,8 @@ oc_handle_collection_linked_list_request(oc_request_t *request)
oc_rep_set_text_string_v1(links, href, oc_string(link->resource->uri),
oc_string_len(link->resource->uri));
oc_rep_set_string_array(links, rt, link->resource->types);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces);
oc_core_encode_interfaces_mask(oc_rep_object(links), link->interfaces,
false);
oc_rep_set_string_array(links, rel, link->rel);
oc_rep_set_int(links, ins, link->ins);
oc_link_params_t *p = (oc_link_params_t *)oc_list_head(link->params);
Expand Down
10 changes: 9 additions & 1 deletion api/oc_core_res.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ oc_core_shutdown(void)
}

void
oc_core_encode_interfaces_mask(CborEncoder *parent, unsigned iface_mask)
oc_core_encode_interfaces_mask(CborEncoder *parent, unsigned iface_mask,
bool include_private)
{
oc_rep_set_key((parent), "if");
oc_rep_start_array((parent), if);
Expand Down Expand Up @@ -201,6 +202,13 @@ oc_core_encode_interfaces_mask(CborEncoder *parent, unsigned iface_mask)
if ((iface_mask & OC_IF_STARTUP_REVERT) != 0) {
oc_rep_add_text_string(if, OC_IF_STARTUP_REVERT_STR);
}
#ifdef OC_HAS_FEATURE_ETAG_INTERFACE
if (include_private && (iface_mask & PLGD_IF_ETAG) != 0) {
oc_rep_add_text_string(if, PLGD_IF_ETAG_STR);
}
#else /* OC_HAS_FEATURE_ETAG_INTERFACE */
(void)include_private;
#endif /* OC_HAS_FEATURE_ETAG_INTERFACE */
oc_rep_end_array((parent), if);
}

Expand Down
5 changes: 3 additions & 2 deletions api/oc_core_res_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ oc_device_info_t *oc_core_add_new_device(oc_add_new_device_t cfg);
*
* @param parent the cbor encoder (cannot be NULL)
* @param iface_mask the interfaces (as bit mask)
* @param include_private include private interfaces
*/
void oc_core_encode_interfaces_mask(CborEncoder *parent, unsigned iface_mask)
OC_NONNULL();
void oc_core_encode_interfaces_mask(CborEncoder *parent, unsigned iface_mask,
bool include_private) OC_NONNULL();

/**
* @brief store the uri as a string
Expand Down
Loading

0 comments on commit afb52af

Please sign in to comment.