![]() |
Contiki-NG
|
Data Structures | |
| struct | edhoc_client |
| EDHOC client struct. More... | |
| struct | edhoc_client_ad |
| EDHOC client Application data struct. More... | |
| struct | edhoc_data_event |
| EDHOC data event struct. More... | |
| struct | oscore_ctx |
| OSCORE context struct. More... | |
| struct | edhoc_server |
| EDHOC Server Struct. More... | |
| struct | edhoc_server_ad |
| EDHOC server Application data struct. More... | |
| struct | ecc_data_event |
| EDHOC server data event struct. More... | |
Macros | |
| #define | SERVER_EP "coap://[fd00::1]" |
| The CoAP Server IP where run the EDHOC Responder. | |
| #define | CL_TIMEOUT_VAL 10000 |
| Time limit value to EDHOC protocol finished. | |
| #define | EDHOC_MAX_BUFFER 256 |
| The max size of the buffers. | |
| #define | EDHOC_MAX_CRED_LEN 128 |
| Optimized buffer sizes for credentials based on COSE standard analysis CRED_X: 84-120 bytes typical → 128 bytes (safe margin) ID_CRED_X: 4-7 bytes (KID mode) or 84-120 bytes (include mode). | |
| #define | EDHOC_SUITES_MAX_COUNT 10 |
| The max number of suites. | |
| #define | EDHOC_CID 0x1 |
| Set EDHOC connection identifier. | |
| #define | EDHOC_MAX_CID_LEN 8 |
| Maximum length of connection identifiers RFC 9528 allows variable-length CIDs including negative integers. | |
| #define | EDHOC_DEFAULT_CID_LEN 1 |
| Default CID length for backward compatibility. | |
| #define | EDHOC_MAX_KID_LEN 4 |
| Maximum length of Key Identifiers (KID) in credentials COSE Key IDs can be 1-4 bytes typically, but allowing larger for flexibility. | |
| #define | EDHOC_MAX_IDENTITY_LEN 32 |
| Maximum length of identity strings in credentials Used for human-readable credential identities (e.g., "example.edu"). | |
| #define | EDHOC_ROLE EDHOC_INITIATOR |
| Set the EDHOC Protocol role. | |
| #define | EDHOC_METHOD EDHOC_METHOD0 |
| Set the Authentication method. | |
| #define | EDHOC_MAC_OR_SIG_BUF_LEN P256_SIGNATURE_LEN |
| Buffer size for mac_or_sig. | |
| #define | INITIATOR_METHOD2 (EDHOC_METHOD == EDHOC_METHOD2 && EDHOC_ROLE == EDHOC_INITIATOR) |
| Helper defines for method handling on msg. | |
| #define | EDHOC_AUTHENT_TYPE EDHOC_CRED_KID |
| Set the authentication credential type/usage. | |
| #define | P256_SIGNATURE_LEN 64 |
| Length of signatures. | |
| #define | EDHOC_SUPPORTED_SUITE_1 -1 |
| Set EDHOC cipher suite config. | |
| #define | EDHOC_CONF_ATTEMPTS 2 |
| The number of attempts to try to connect with the EDHOC server successfully. | |
| #define | EDHOC_MAX_PAYLOAD_LEN 256 |
| The max length of the EDHOC message. | |
| #define | EDHOC_MAX_AD_SZ 8 |
| The max length of the Application Data. | |
| #define | EDHOC_EAD_PROCESSING 1 |
| Enable/disable External Authorization Data (EAD) processing. | |
| #define | EDHOC_COAP_URI_PATH ".well-known/edhoc" |
| EDHOC resource CoAP URI path. | |
| #define | SERV_TIMEOUT_VAL 10000 |
| Time limit value for EDHOC protocol completion. | |
Typedefs | |
| typedef struct edhoc_client | edhoc_client_t |
| EDHOC client struct. | |
| typedef struct edhoc_client_ad | edhoc_client_ad_t |
| EDHOC client Application data struct. | |
| typedef struct edhoc_data_event | edhoc_data_event_t |
| EDHOC data event struct. | |
| typedef struct oscore_ctx | oscore_ctx_t |
| OSCORE context struct. | |
| typedef struct edhoc_server | edhoc_server_t |
| EDHOC Server Struct. | |
| typedef struct edhoc_server_ad | edhoc_server_ad_t |
| EDHOC server Application data struct. | |
| typedef struct ecc_data_event | ecc_data_event_t |
| EDHOC server data event struct. | |
Functions | |
| void | edhoc_client_run (void) |
| Run the EDHOC Initiator role. | |
| int8_t | edhoc_client_callback (process_event_t ev, void *data) |
| Check if the EDHOC client have finished. | |
| void | edhoc_client_close (void) |
| Close the EDHOC context. | |
| uint8_t | edhoc_client_get_ad_2 (char *buf, size_t buf_sz) |
| Get the Application Data received in EDHOC message 2. | |
| void | edhoc_client_set_ad_1 (const void *data_buffer, uint8_t buffer_size) |
| Set the Application Data to be carried in EDHOC message 1. | |
| void | edhoc_client_set_ad_3 (const void *data_buffer, uint8_t buffer_size) |
| Set the Application Data to be carried in EDHOC message 3. | |
| int8_t | edhoc_exporter_oscore (oscore_ctx_t *osc, edhoc_context_t *ctx) |
| Derive an OSCORE Context from EDHOC. | |
| void | print_oscore_ctx (oscore_ctx_t *osc) |
| Print OSCORE Security Context contents for debugging. | |
| int8_t | edhoc_exporter (const uint8_t *in_key, uint8_t exporter_label, const uint8_t *context, uint8_t context_sz, uint16_t length, uint8_t *result) |
| Derive an application-specific key from EDHOC. | |
| edhoc_error_t | edhoc_generate_message_1 (edhoc_context_t *ctx, uint8_t *ad, size_t ad_sz, bool suite_array) |
| Generate the EDHOC Message 1 and set it in the EDHOC context. | |
| edhoc_error_t | edhoc_generate_message_2 (edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size) |
| Generate the EDHOC Message 2 and set it in the EDHOC context. | |
| edhoc_error_t | edhoc_generate_message_3 (edhoc_context_t *ctx, const uint8_t *auth_data, size_t auth_data_size) |
| Generate the EDHOC Message 3 and set it in the EDHOC context. | |
| edhoc_error_t | edhoc_check_err_rx_msg (uint8_t message, const uint8_t *data, size_t data_size) |
| Try to deserialize data as an EDHOC error message. | |
| int | edhoc_handler_msg_1 (edhoc_context_t *ctx, uint8_t *payload, size_t payload_size, uint8_t *auth_data) |
| Handle the EDHOC Message 1 received. | |
| int | edhoc_handler_msg_2 (edhoc_msg_2_t *msg2, edhoc_context_t *ctx, uint8_t *payload, size_t payload_size) |
| Handle the EDHOC Message 2 received. | |
| int | edhoc_handler_msg_3 (edhoc_msg_3_t *msg3, edhoc_context_t *ctx, uint8_t *payload, size_t payload_size) |
| Handle the EDHOC Message 3 received. | |
| void | edhoc_server_init (void) |
| Activate the EDHOC CoAP Resource. | |
| uint8_t | edhoc_server_start (void) |
| Create a new EDHOC context for a new EDHOC protocol session. | |
| uint8_t | edhoc_server_reset_handshake (void) |
| Reset the EDHOC handshake state for a new client connection. | |
| int8_t | edhoc_server_callback (process_event_t ev, void *data) |
| Check if an EDHOC server session has finished. | |
| void | edhoc_server_close (void) |
| Close the EDHOC context. | |
| void | edhoc_server_process (coap_message_t *req, coap_message_t *res, edhoc_server_t *ser, uint8_t *msg, size_t len) |
| Run the EDHOC Responder role process. | |
| void | edhoc_server_set_ad_2 (const void *buf, uint8_t buf_sz) |
| Set the Application Data to be carried in EDHOC message 2. | |
| uint8_t | edhoc_server_get_ad_1 (char *buf) |
| Get the Application Data received in EDHOC message 1. | |
| uint8_t | edhoc_server_get_ad_3 (char *buf) |
| Get the Application Data received in EDHOC message 3. | |
Variables | |
| coap_resource_t | res_edhoc |
| CoAP resource. | |
| #define EDHOC_EAD_PROCESSING 1 |
Enable/disable External Authorization Data (EAD) processing.
When enabled, the implementation will process EAD items according to RFC 9528 Section 6:
To disable in project-conf.h:
Definition at line 338 of file edhoc-config.h.
| #define EDHOC_MAX_CID_LEN 8 |
Maximum length of connection identifiers RFC 9528 allows variable-length CIDs including negative integers.
To override in project-conf.h:
Definition at line 122 of file edhoc-config.h.
Referenced by edhoc_calc_mac(), edhoc_deserialize_msg_1(), edhoc_handler_msg_2(), and edhoc_initialize_context().
| #define EDHOC_MAX_IDENTITY_LEN 32 |
Maximum length of identity strings in credentials Used for human-readable credential identities (e.g., "example.edu").
To override in project-conf.h:
Definition at line 157 of file edhoc-config.h.
Referenced by edhoc_check_key_list_identity().
| #define EDHOC_MAX_KID_LEN 4 |
Maximum length of Key Identifiers (KID) in credentials COSE Key IDs can be 1-4 bytes typically, but allowing larger for flexibility.
To override in project-conf.h:
Definition at line 142 of file edhoc-config.h.
| #define EDHOC_SUITES_MAX_COUNT 10 |
The max number of suites.
There are nine suites that are defined at the time of writing (0-6 and 24-25). We select just a slightly larger value to avoid using too much unnecessary space for the array of suites.
Definition at line 73 of file edhoc-config.h.
Referenced by edhoc_generate_message_1().
| #define INITIATOR_METHOD2 (EDHOC_METHOD == EDHOC_METHOD2 && EDHOC_ROLE == EDHOC_INITIATOR) |
| edhoc_error_t edhoc_check_err_rx_msg | ( | uint8_t | message, |
| const uint8_t * | data, | ||
| size_t | data_size ) |
Try to deserialize data as an EDHOC error message.
| message | expected type of message |
| data | input CBOR data to parse |
| data_size | input size of CBOR data |
Definition at line 192 of file edhoc-msg-handlers.c.
References edhoc_deserialize_err(), EDHOC_ERR_CREDENTIAL_NOT_FOUND, EDHOC_ERR_MSG_MALFORMED, and EDHOC_ERR_SUITE_NOT_SUPPORTED.
Referenced by edhoc_handler_msg_1(), edhoc_handler_msg_2(), and edhoc_handler_msg_3().
| int8_t edhoc_client_callback | ( | process_event_t | ev, |
| void * | data ) |
Check if the EDHOC client have finished.
| ev | process event |
| data | process data |
| 1 | if EDHOC Client process finished success |
| -1 | if EDHOC Client process expire attempts |
| 0 | if the event is not from EDHOC Client process or the EDHOC client process has not finished yet |
This function checks the events trigger from the EDHOC client process looking for the EVT_FINISHED or EVT_TRIES_EXPIRE events.
Definition at line 109 of file edhoc-client.c.
| void edhoc_client_close | ( | void | ) |
Close the EDHOC context.
This function must be called after the Security Context is exported to free the allocated memory.
Definition at line 566 of file edhoc-client.c.
References coap_timer_stop(), edhoc_ctx, and edhoc_finalize().
| uint8_t edhoc_client_get_ad_2 | ( | char * | buf, |
| size_t | buf_sz ) |
Get the Application Data received in EDHOC message 2.
| buf | A pointer to a buffer to copy the Application data |
| buf_sz | The size of the destination buffer |
This function copies to the buff the Application data from the EDHOC message 2 received. Returns 0 if the destination buffer is too small or invalid.
Definition at line 162 of file edhoc-client.c.
| void edhoc_client_run | ( | void | ) |
Run the EDHOC Initiator role.
This function must be called from the EDHOC Initiator program to start the EDHOC protocol as Initiator. Runs a new process that implements all the EDHOC protocol and exits when the EDHOC protocol finishes successfully or expire the EDHOC_CONF_ATTEMPTS.
Definition at line 126 of file edhoc-client.c.
References process_start().
| void edhoc_client_set_ad_1 | ( | const void * | data_buffer, |
| uint8_t | buffer_size ) |
Set the Application Data to be carried in EDHOC message 1.
| data_buffer | A pointer to a buffer that contains the Application data to be copied |
| buffer_size | The Application data length |
This function sets the Application data to be carried in EDHOC message 1.
Definition at line 132 of file edhoc-client.c.
References EDHOC_MAX_AD_SZ.
| void edhoc_client_set_ad_3 | ( | const void * | data_buffer, |
| uint8_t | buffer_size ) |
Set the Application Data to be carried in EDHOC message 3.
| data_buffer | A pointer to a buffer that contains the Application data to be copied |
| buffer_size | The Application data length |
This function sets the Application data to be carried in EDHOC message 3.
Definition at line 147 of file edhoc-client.c.
References EDHOC_MAX_AD_SZ.
| int8_t edhoc_exporter | ( | const uint8_t * | in_key, |
| uint8_t | exporter_label, | ||
| const uint8_t * | context, | ||
| uint8_t | context_sz, | ||
| uint16_t | length, | ||
| uint8_t * | result ) |
Derive an application-specific key from EDHOC.
| result | Output buffer where the derived key will be stored |
| in_key | PRK_Exporter key to use |
| exporter_label | Label used to differentiate different key derivation outputs |
| context | Context data used to generate the info input for key derivation |
| context_sz | The size of the context data |
| length | Length of the key to be derived |
This function derives a key for application-specific use from the EDHOC shared secret using the EDHOC KDF. The key derivation is based on the provided label and length. This can be used to export keys after the successful completion of the EDHOC protocol.
Definition at line 64 of file edhoc-exporter.c.
References edhoc_kdf().
Referenced by edhoc_exporter_oscore().
| int8_t edhoc_exporter_oscore | ( | oscore_ctx_t * | osc, |
| edhoc_context_t * | ctx ) |
Derive an OSCORE Context from EDHOC.
| osc | Output OSCORE Context struct |
| ctx | Input EDHOC Context struct |
This function derives an OSCORE Security Context [RFC8613] from the EDHOC shared secret. It can be called by both EDHOC Initiator and Responder once the EDHOC protocol has finished successfully.
Definition at line 75 of file edhoc-exporter.c.
References edhoc_exporter(), edhoc_kdf(), and EDHOC_ROLE.
| edhoc_error_t edhoc_generate_message_1 | ( | edhoc_context_t * | ctx, |
| uint8_t * | ad, | ||
| size_t | ad_sz, | ||
| bool | suite_array ) |
Generate the EDHOC Message 1 and set it in the EDHOC context.
| ctx | EDHOC Context struct |
| ad | Application data to include in MSG1 |
| ad_sz | Application data length |
| suite_array | If true, MSG1 includes an array of cipher suites when more than one is supported. If false, MSG1 includes a single unsigned suite value regardless of the number of suites supported by the initiator. |
Composes EDHOC Message 1 as described in RFC9528 for EDHOC authentication with asymmetric keys, encoded as a CBOR sequence in the MSG1 element of the context struct. Uses the ephemeral key, cipher suite, and connection identifier already set in the context (they are established by the caller, not by this function). Used by the Initiator EDHOC role.
Definition at line 199 of file edhoc-msg-generators.c.
| edhoc_error_t edhoc_generate_message_2 | ( | edhoc_context_t * | ctx, |
| const uint8_t * | auth_data, | ||
| size_t | auth_data_size ) |
Generate the EDHOC Message 2 and set it in the EDHOC context.
| ctx | EDHOC Context struct |
| auth_data | Application data to include in MSG2 |
| auth_data_size | Application data length |
Used by the EDHOC Responder role to generate message 2. Computes the transcript hash TH_2 = H(ctx->MSG1, data_2), computes MAC_2 (Message Authentication Code), computes CIPHERTEXT_2, and composes EDHOC Message 2 as described in RFC9528 for EDHOC authentication with asymmetric keys, encoded as a CBOR sequence in the MSG2 element of the context struct. Uses the ephemeral key and connection identifier already set in the context.
Definition at line 258 of file edhoc-msg-generators.c.
| edhoc_error_t edhoc_generate_message_3 | ( | edhoc_context_t * | ctx, |
| const uint8_t * | auth_data, | ||
| size_t | auth_data_size ) |
Generate the EDHOC Message 3 and set it in the EDHOC context.
| ctx | EDHOC Context struct |
| auth_data | Application data to include in MSG3 |
| auth_data_size | Application data length |
Used by the EDHOC Initiator role to generate message 3. Computes the transcript hash TH_3 = H(TH_2, PLAINTEXT_2, data_3), computes MAC_3 (Message Authentication Code), computes CIPHERTEXT_3, and composes EDHOC Message 3 as described in RFC9528 for EDHOC authentication with asymmetric keys, encoded as a CBOR sequence in the MSG3 element of the context struct.
Definition at line 406 of file edhoc-msg-generators.c.
| int edhoc_handler_msg_1 | ( | edhoc_context_t * | ctx, |
| uint8_t * | payload, | ||
| size_t | payload_size, | ||
| uint8_t * | auth_data ) |
Handle the EDHOC Message 1 received.
| ctx | EDHOC Context struct |
| payload | A pointer to the buffer containing the EDHOC message received |
| payload_size | Size of the EDHOC message received |
| auth_data | A pointer to a buffer to copy the Application Data received in Message 1 |
| negative | number (EDHOC ERROR CODES) when an EDHOC ERROR is detected |
| ad_sz | The length of the Application Data received in Message 1, when EDHOC success |
Used by Responder EDHOC role to process the Message 1 received
Definition at line 228 of file edhoc-msg-handlers.c.
References edhoc_check_err_rx_msg(), edhoc_deserialize_msg_1(), EDHOC_ERR_MSG_MALFORMED, EDHOC_MAX_AD_SZ, edhoc_print_session_info(), edhoc_process_ead_item(), and print_msg_1().
| int edhoc_handler_msg_2 | ( | edhoc_msg_2_t * | msg2, |
| edhoc_context_t * | ctx, | ||
| uint8_t * | payload, | ||
| size_t | payload_size ) |
Handle the EDHOC Message 2 received.
| msg2 | A pointer to the buffer containing the received EDHOC message 2 |
| ctx | EDHOC Context struct |
| payload | A pointer to the buffer containing the EDHOC message received |
| payload_size | Size of the EDHOC message received |
| negative | error code when an EDHOC ERROR is detected |
| 1 | when EDHOC decode and verify success |
Used by Initiator EDHOC role to process the Message 2 received
If any verification step fails to return an EDHOC ERROR code and, if all the steps success return 1.
Definition at line 311 of file edhoc-msg-handlers.c.
References cbor_init_reader(), edhoc_check_err_rx_msg(), edhoc_deserialize_msg_2(), edhoc_enc_dec_ciphertext_2(), EDHOC_ERR_MSG_MALFORMED, edhoc_generate_keystream_2e(), edhoc_generate_prk_2e(), edhoc_generate_transcript_hash_2(), EDHOC_MAX_BUFFER, EDHOC_MAX_CID_LEN, edhoc_read_byte_identifier(), and print_msg_2().
| int edhoc_handler_msg_3 | ( | edhoc_msg_3_t * | msg3, |
| edhoc_context_t * | ctx, | ||
| uint8_t * | payload, | ||
| size_t | payload_size ) |
Handle the EDHOC Message 3 received.
| msg3 | A pointer to the buffer containing the received EDHOC message 3 |
| ctx | EDHOC Context struct |
| payload | A pointer to the buffer containing the EDHOC message received |
| payload_size | Size of the EDHOC message received |
| negative | number (EDHOC ERROR CODE) when an EDHOC ERROR is detected |
| 1 | when EDHOC decode and verify success |
Used by Responder EDHOC role to process the Message 3 receive
If any verification step fails to return an EDHOC ERROR code and,if all the steps success return 1.
Definition at line 385 of file edhoc-msg-handlers.c.
References edhoc_check_err_rx_msg(), edhoc_deserialize_msg_3(), EDHOC_ERR_CRYPTO_DECRYPT, edhoc_generate_transcript_hash_3(), and print_msg_3().
| int8_t edhoc_server_callback | ( | process_event_t | ev, |
| void * | data ) |
Check if an EDHOC server session has finished.
| ev | Process event |
| data | Process data |
| SERV_HANDSHAKE_COMPLETE | (non-zero) if the session finished successfully with an EDHOC client |
| SERV_HANDSHAKE_RESET | (non-zero) if the handshake was reset |
| 0 | if the event is not from the EDHOC server or the handshake has not finished yet |
This function checks the events triggered from the EDHOC server protocol, reporting both handshake completion (SERV_HANDSHAKE_COMPLETE) and handshake reset (SERV_HANDSHAKE_RESET). A non-zero return does not by itself imply success, so callers must distinguish the two values.
Definition at line 107 of file edhoc-server.c.
| void edhoc_server_close | ( | void | ) |
Close the EDHOC context.
This function must be called after the Security Context is exported to free the allocated memory.
Definition at line 342 of file edhoc-server.c.
References edhoc_ctx, and edhoc_finalize().
| uint8_t edhoc_server_get_ad_1 | ( | char * | buf | ) |
Get the Application Data received in EDHOC message 1.
| buf | A pointer to a buffer to copy the Application data |
This function copies the Application data from the received EDHOC message 1 to the buffer.
Definition at line 133 of file edhoc-server.c.
| uint8_t edhoc_server_get_ad_3 | ( | char * | buf | ) |
Get the Application Data received in EDHOC message 3.
| buf | A pointer to a buffer to copy the Application data |
This function copies the Application data from the received EDHOC message 3 to the buffer.
Definition at line 140 of file edhoc-server.c.
| void edhoc_server_init | ( | void | ) |
Activate the EDHOC CoAP Resource.
Activate the EDHOC well-known CoAP Resource at the Uri-Path defined in the WELL_KNOW macro.
Definition at line 334 of file edhoc-server.c.
References coap_activate_resource(), EDHOC_COAP_URI_PATH, process_alloc_event(), and res_edhoc.
| void edhoc_server_process | ( | coap_message_t * | req, |
| coap_message_t * | res, | ||
| edhoc_server_t * | ser, | ||
| uint8_t * | msg, | ||
| size_t | len ) |
Run the EDHOC Responder role process.
| req | The request CoAP message received |
| res | The response CoAP message to send back |
| ser | The EDHOC server struct |
| msg | A pointer to the buffer with the received message |
| len | The received message length |
This function must be called from a CoAP POST handler to run the EDHOC protocol Responder role. EDHOC messages 1 and 3 are transferred in POST requests and EDHOC message 2 is transferred in 2.04 (Changed) responses.
Definition at line 348 of file edhoc-server.c.
References coap_timer_set(), coap_timer_set_callback(), EDHOC_MAX_PAYLOAD_LEN, EDHOC_TRACE_STATE, and SERV_TIMEOUT_VAL.
| uint8_t edhoc_server_reset_handshake | ( | void | ) |
Reset the EDHOC handshake state for a new client connection.
| Non-zero | if the authentication credentials for the EDHOC server exist in the key-storage and the EDHOC server resets correctly. |
Resets the EDHOC handshake state to prepare for a new client handshake. This clears the current session state while keeping the server running. Must be called after completing or aborting a handshake before accepting the next client.
Definition at line 307 of file edhoc-server.c.
References edhoc_ctx, edhoc_initialize_context(), and edhoc_setup_suites().
Referenced by edhoc_server_start().
| void edhoc_server_set_ad_2 | ( | const void * | buf, |
| uint8_t | buf_sz ) |
Set the Application Data to be carried in EDHOC message 2.
| buf | A pointer to a buffer that contains the Application data to be copied |
| buf_sz | The Application data length |
This function sets the Application data to be carried in EDHOC message 2.
Definition at line 121 of file edhoc-server.c.
References EDHOC_MAX_AD_SZ.
| uint8_t edhoc_server_start | ( | void | ) |
Create a new EDHOC context for a new EDHOC protocol session.
| Non-zero | if the authentication credentials for the EDHOC server exist in the key-storage and the EDHOC server starts correctly. |
This function retrieves the DH-static authentication key pair of the Server from the edhoc-key-storage. The authentication keys must be established in the EDHOC key storage before running the EDHOC protocol. Creates a new EDHOC context and generates the DH-ephemeral key for the specific session. A new EDHOC protocol session must be created for each new EDHOC client connection attempt.
Definition at line 321 of file edhoc-server.c.
References edhoc_ctx, and edhoc_server_reset_handshake().
| void print_oscore_ctx | ( | oscore_ctx_t * | osc | ) |
Print OSCORE Security Context contents for debugging.
| osc | Input OSCORE Context struct |
Definition at line 51 of file edhoc-exporter.c.