![]() |
Contiki-NG
|
EDHOC message serialization and parsing implementation using the CBOR library. More...
#include "contiki-lib.h"#include "edhoc-msgs.h"#include "lib/cbor.h"#include <assert.h>#include <inttypes.h>#include "sys/log.h"Go to the source code of this file.
Functions | |
| void | print_msg_1 (edhoc_msg_1_t *msg) |
| Print EDHOC message 1 contents for debugging. | |
| void | print_msg_2 (edhoc_msg_2_t *msg) |
| Print EDHOC message 2 contents for debugging. | |
| void | print_msg_3 (edhoc_msg_3_t *msg) |
| Print EDHOC message 3 contents for debugging. | |
| const uint8_t * | edhoc_read_byte_identifier (cbor_reader_state_t *reader, size_t *size) |
| Read byte identifier from CBOR reader. | |
| void | edhoc_write_byte_identifier (cbor_writer_state_t *state, const uint8_t *bytes, size_t byte_length) |
| Write EDHOC byte identifier according to RFC 9528 rules. | |
| size_t | edhoc_serialize_msg_1 (edhoc_msg_1_t *msg, unsigned char *buffer, size_t buffer_sz, bool suite_array) |
| Serialize EDHOC message 1 to CBOR format. | |
| size_t | edhoc_serialize_err (const edhoc_msg_error_t *msg, unsigned char *buffer, size_t buffer_sz) |
| Serialize EDHOC error message to CBOR format. | |
| bool | edhoc_deserialize_err (edhoc_msg_error_t *msg, const uint8_t *data, size_t data_size) |
| Deserialize EDHOC error message from CBOR data. | |
| edhoc_error_t | edhoc_deserialize_msg_1 (edhoc_msg_1_t *msg, unsigned char *buffer, size_t buff_sz) |
| Deserialize EDHOC message 1 from CBOR data. | |
| edhoc_error_t | edhoc_deserialize_msg_2 (edhoc_msg_2_t *msg, unsigned char *buffer, size_t buff_sz) |
| Deserialize EDHOC message 2 from CBOR data. | |
| edhoc_error_t | edhoc_deserialize_msg_3 (edhoc_msg_3_t *msg, unsigned char *buffer, size_t buff_sz) |
| Deserialize EDHOC message 3 from CBOR data. | |
| edhoc_error_t | edhoc_get_auth_key_from_kid (uint8_t *kid, uint8_t kid_sz, cose_key_t **key) |
| Get authentication key by Key ID (KID). | |
| int8_t | edhoc_get_key_id_cred_x (cbor_reader_state_t *reader, uint8_t *out_id_cred_x, size_t id_cred_x_buffer_size, cose_key_t *key) |
| Parse ID_CRED_X from CBOR data and extract authentication key. | |
| uint8_t | edhoc_get_sign (cbor_reader_state_t *reader, uint8_t **sign) |
| Parse signature data from CBOR reader. | |
| uint8_t | edhoc_get_ad (cbor_reader_state_t *reader, uint8_t *ad, size_t ad_buffer_size) |
| Parse Additional Data (AD) from CBOR reader. | |
| edhoc_error_t | edhoc_process_ead_item (const edhoc_ead_data_t *ead_data) |
| Process and validate EAD (External Authorization Data) items. | |
EDHOC message serialization and parsing implementation using the CBOR library.
Definition in file edhoc-msgs.c.
| bool edhoc_deserialize_err | ( | edhoc_msg_error_t * | msg, |
| const uint8_t * | data, | ||
| size_t | data_size ) |
Deserialize EDHOC error message from CBOR data.
| msg | output error message structure |
| data | input CBOR data to parse |
| data_size | input size of CBOR data |
true if the data could be parsed as an EDHOC error message, or false on error. Definition at line 227 of file edhoc-msgs.c.
References cbor_get_remaining(), cbor_init_reader(), cbor_read_signed(), cbor_read_simple(), cbor_read_text(), CBOR_SIZE_NONE, cbor_skip_next(), and value().
Referenced by edhoc_check_err_rx_msg().
| edhoc_error_t edhoc_deserialize_msg_1 | ( | edhoc_msg_1_t * | msg, |
| unsigned char * | buffer, | ||
| size_t | buff_sz ) |
Deserialize EDHOC message 1 from CBOR data.
| msg | output message 1 structure |
| buffer | input CBOR data to parse |
| buff_sz | input size of CBOR data |
Definition at line 299 of file edhoc-msgs.c.
References cbor_get_remaining(), cbor_init_reader(), cbor_read_data(), cbor_read_signed(), cbor_read_unsigned(), CBOR_SIZE_1, CBOR_SIZE_NONE, EDHOC_ERR_MSG_MALFORMED, EDHOC_MAX_CID_LEN, edhoc_read_byte_identifier(), and value().
Referenced by edhoc_handler_msg_1().
| edhoc_error_t edhoc_deserialize_msg_2 | ( | edhoc_msg_2_t * | msg, |
| unsigned char * | buffer, | ||
| size_t | buff_sz ) |
Deserialize EDHOC message 2 from CBOR data.
| msg | output message 2 structure |
| buffer | input CBOR data to parse |
| buff_sz | input size of CBOR data |
Definition at line 388 of file edhoc-msgs.c.
References cbor_init_reader(), cbor_read_data(), EDHOC_ERR_MSG_MALFORMED, EDHOC_ERR_NULL_POINTER, and EDHOC_MAX_PAYLOAD_LEN.
Referenced by edhoc_handler_msg_2().
| edhoc_error_t edhoc_deserialize_msg_3 | ( | edhoc_msg_3_t * | msg, |
| unsigned char * | buffer, | ||
| size_t | buff_sz ) |
Deserialize EDHOC message 3 from CBOR data.
| msg | output message 3 structure |
| buffer | input CBOR data to parse |
| buff_sz | input size of CBOR data |
Definition at line 425 of file edhoc-msgs.c.
References cbor_init_reader(), cbor_read_data(), EDHOC_ERR_MSG_MALFORMED, EDHOC_ERR_NULL_POINTER, and EDHOC_MAX_PAYLOAD_LEN.
Referenced by edhoc_handler_msg_3().
| uint8_t edhoc_get_ad | ( | cbor_reader_state_t * | reader, |
| uint8_t * | ad, | ||
| size_t | ad_buffer_size ) |
Parse Additional Data (AD) from CBOR reader.
| reader | input CBOR reader state positioned at AD data |
| ad | output buffer to store parsed AD |
| ad_buffer_size | input size of ad buffer |
Reads Additional Data from CBOR stream and copies it to the provided buffer. Validates that the AD size does not exceed buffer or protocol limits.
Definition at line 734 of file edhoc-msgs.c.
References cbor_read_data(), and EDHOC_MAX_AD_SZ.
Referenced by edhoc_authenticate_msg().
| edhoc_error_t edhoc_get_auth_key_from_kid | ( | uint8_t * | kid, |
| uint8_t | kid_sz, | ||
| cose_key_t ** | key ) |
Get authentication key by Key ID (KID).
| kid | input key identifier bytes |
| kid_sz | input key identifier length |
| key | output pointer to retrieved authentication key |
Searches the key repository for a key matching the provided KID.
Definition at line 462 of file edhoc-msgs.c.
References edhoc_check_key_list_kid().
| int8_t edhoc_get_key_id_cred_x | ( | cbor_reader_state_t * | reader, |
| uint8_t * | id_cred_x, | ||
| size_t | id_cred_x_buffer_size, | ||
| cose_key_t * | key ) |
Parse ID_CRED_X from CBOR data and extract authentication key.
| reader | input CBOR reader state positioned at ID_CRED_X data |
| id_cred_x | output buffer to store parsed ID_CRED_X (can be NULL) |
| id_cred_x_buffer_size | input size of id_cred_x buffer |
| key | output parsed authentication key information |
Parses ID_CRED_X in three supported formats:
Definition at line 670 of file edhoc-msgs.c.
References cbor_get_position(), EDHOC_ERR_ID_CRED_MALFORMED, EDHOC_FAILED, and start().
Referenced by edhoc_authenticate_msg().
| uint8_t edhoc_get_sign | ( | cbor_reader_state_t * | reader, |
| uint8_t ** | sign ) |
Parse signature data from CBOR reader.
| reader | input CBOR reader state positioned at signature data |
| sign | output pointer to signature data (points into reader buffer) |
Reads and validates signature data from CBOR stream. The returned pointer references data within the reader's buffer and remains valid until the reader is reinitialized or goes out of scope.
Definition at line 709 of file edhoc-msgs.c.
References cbor_read_data().
Referenced by edhoc_authenticate_msg().
| edhoc_error_t edhoc_process_ead_item | ( | const edhoc_ead_data_t * | ead_data | ) |
Process and validate EAD (External Authorization Data) items.
| ead_data | input EAD data structure containing label and value |
Processes EAD items according to RFC 9528 Section 6:
Definition at line 765 of file edhoc-msgs.c.
References EDHOC_ERR_CRITICAL_EAD_UNSUPPORTED, and EDHOC_ERR_NULL_POINTER.
Referenced by edhoc_handler_msg_1().
| const uint8_t * edhoc_read_byte_identifier | ( | cbor_reader_state_t * | reader, |
| size_t * | size ) |
Read byte identifier from CBOR reader.
Reads byte identifiers following RFC 9528 optimization. Returns pointer to the identifier bytes and sets size to the length.
Definition at line 85 of file edhoc-msgs.c.
References cbor_get_position(), cbor_peek_next(), cbor_read_data(), cbor_read_signed(), CBOR_SIZE_1, and value().
Referenced by edhoc_authenticate_msg(), edhoc_deserialize_msg_1(), and edhoc_handler_msg_2().
| size_t edhoc_serialize_err | ( | const edhoc_msg_error_t * | msg, |
| unsigned char * | buffer, | ||
| size_t | buffer_sz ) |
Serialize EDHOC error message to CBOR format.
| msg | input error message structure to serialize |
| buffer | output buffer for serialized data |
| buffer_sz | input size of output buffer |
Definition at line 201 of file edhoc-msgs.c.
References cbor_end_writer(), cbor_init_writer(), cbor_write_bool(), cbor_write_text(), and cbor_write_unsigned().
Referenced by edhoc_generate_error_message().
| size_t edhoc_serialize_msg_1 | ( | edhoc_msg_1_t * | msg, |
| unsigned char * | buffer, | ||
| size_t | buffer_sz, | ||
| bool | suite_array ) |
Serialize EDHOC message 1 to CBOR format.
| msg | input message 1 structure to serialize |
| buffer | output buffer for serialized data |
| buffer_sz | input size of output buffer |
| suite_array | input whether to encode suites as array (unused) |
Definition at line 177 of file edhoc-msgs.c.
References cbor_end_writer(), cbor_init_writer(), cbor_write_data(), cbor_write_unsigned(), and edhoc_write_byte_identifier().
| void edhoc_write_byte_identifier | ( | cbor_writer_state_t * | state, |
| const uint8_t * | bytes, | ||
| size_t | len ) |
Write EDHOC byte identifier according to RFC 9528 rules.
| state | output CBOR writer state |
| bytes | input identifier bytes to write |
| len | input length of identifier |
Writes byte identifiers following RFC 9528 optimization: single-byte identifiers that coincide with CBOR integer encoding (0x00-0x17, 0x20-0x37) are written as integers, others as byte strings.
Definition at line 108 of file edhoc-msgs.c.
References cbor_write_data(), and cbor_write_object().
Referenced by edhoc_serialize_msg_1().
| void print_msg_1 | ( | edhoc_msg_1_t * | msg | ) |
Print EDHOC message 1 contents for debugging.
| msg | input message 1 structure to print |
Definition at line 51 of file edhoc-msgs.c.
Referenced by edhoc_handler_msg_1().
| void print_msg_2 | ( | edhoc_msg_2_t * | msg | ) |
Print EDHOC message 2 contents for debugging.
| msg | input message 2 structure to print |
Definition at line 69 of file edhoc-msgs.c.
Referenced by edhoc_handler_msg_2().
| void print_msg_3 | ( | edhoc_msg_3_t * | msg | ) |
Print EDHOC message 3 contents for debugging.
| msg | input message 3 structure to print |
Definition at line 77 of file edhoc-msgs.c.
Referenced by edhoc_handler_msg_3().