Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wi-Sun certificate options to mesh api configuration json #10598

Merged
merged 2 commits into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions features/nanostack/mbed-mesh-api/mbed_lib.json
Expand Up @@ -153,6 +153,22 @@
"wisun-uc-dwell-interval": {
"help": "Unicast dwell interval. Range: 15-255 milliseconds",
"value": 0
},
"certificate-header": {
"help": "File name of the certificate header file (used on include directive)",
"value": null
},
"root-certificate": {
"help": "Root certificate in PEM format (must be a null terminated c-string)",
"value": null
},
"own-certificate": {
"help": "Own certificate in PEM format (must be a null terminated c-string)",
"value": null
},
"own-certificate-key": {
"help": "Own certificate's key in PEM format (must be a null terminated c-string)",
"value": null
}
},
"target_overrides": {
Expand Down
19 changes: 19 additions & 0 deletions features/nanostack/mbed-mesh-api/source/wisun_tasklet.c
Expand Up @@ -28,6 +28,13 @@
#include "mac_api.h"
#include "sw_mac.h"
#include "ws_management_api.h" //ws_management_node_init
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) || \
!defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY)
#error Invalid Wi-SUN certificate configuration
#endif
#include MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
#endif

// For tracing we need to define flag, have include and define group
//#define HAVE_DEBUG
Expand Down Expand Up @@ -210,6 +217,18 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
network_name,
fhss_timer_ptr);

#if defined(MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER)
arm_certificate_chain_entry_s chain_info;
memset(&chain_info, 0, sizeof(arm_certificate_chain_entry_s));
chain_info.cert_chain[0] = (const uint8_t *) MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE;
chain_info.cert_len[0] = strlen((const char *) MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check configuration validity at compile time to avoid hard fault caused by illegal configuration?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check added

chain_info.cert_chain[1] = (const uint8_t *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE;
chain_info.cert_len[1] = strlen((const char *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) + 1;
chain_info.key_chain[1] = (const uint8_t *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY;
chain_info.chain_length = 2;
arm_network_certificate_chain_set((const arm_certificate_chain_entry_s *) &chain_info);
#endif

status = arm_nwk_interface_up(wisun_tasklet_data_ptr->network_interface_id);
if (status >= 0) {
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
Expand Down