Skip to content

Commit 57c4a08

Browse files
authored
Merge pull request #11539 from mikaleppanen/cert_key_len_supp
Enable DER coded certificate support to Wi-SUN mesh API
2 parents f05f03f + 47e5dd7 commit 57c4a08

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

features/nanostack/mbed-mesh-api/mbed_lib.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,29 @@
159159
"value": null
160160
},
161161
"root-certificate": {
162-
"help": "Root certificate in PEM format (must be a null terminated c-string)",
162+
"help": "Root certificate; in PEM format must be a null terminated c-string, in DER format the root-certificate-len must be set",
163163
"value": null
164164
},
165+
"root-certificate-len": {
166+
"help": "Root certificate length; optional for PEM format, must be defined for DER format",
167+
"value": null
168+
},
165169
"own-certificate": {
166-
"help": "Own certificate in PEM format (must be a null terminated c-string)",
170+
"help": "Own certificate; in PEM format must be a null terminated c-string, in DER format the own-certificate-len must be set",
171+
"value": null
172+
},
173+
"own-certificate-len": {
174+
"help": "Own certificate length; optional for PEM format, must be defined for DER format",
167175
"value": null
168176
},
169177
"own-certificate-key": {
170-
"help": "Own certificate's key in PEM format (must be a null terminated c-string)",
178+
"help": "Own certificate's key; in PEM format must be a null terminated c-string, in DER format the own-certificate-key-len must be set",
171179
"value": null
172-
}
180+
},
181+
"own-certificate-key-len": {
182+
"help": "Own certificate's key length; optional for PEM format, must be defined for DER format",
183+
"value": null
184+
}
173185
},
174186
"target_overrides": {
175187
"KW24D": {

features/nanostack/mbed-mesh-api/source/wisun_tasklet.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,36 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
269269
}
270270

271271
#if defined(MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER)
272-
arm_certificate_chain_entry_s chain_info;
273-
memset(&chain_info, 0, sizeof(arm_certificate_chain_entry_s));
274-
chain_info.cert_chain[0] = (const uint8_t *) MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE;
275-
chain_info.cert_len[0] = strlen((const char *) MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) + 1;
276-
chain_info.cert_chain[1] = (const uint8_t *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE;
277-
chain_info.cert_len[1] = strlen((const char *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) + 1;
278-
chain_info.key_chain[1] = (const uint8_t *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY;
279-
chain_info.chain_length = 2;
280-
arm_network_certificate_chain_set((const arm_certificate_chain_entry_s *) &chain_info);
272+
arm_certificate_entry_s trusted_cert = {
273+
.cert = MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE,
274+
.key = NULL,
275+
.cert_len = 0,
276+
.key_len = 0
277+
};
278+
#ifdef MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE_LEN
279+
trusted_cert.cert_len = MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE_LEN;
280+
#else
281+
trusted_cert.cert_len = strlen((const char *) MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE) + 1;
282+
#endif
283+
arm_network_trusted_certificate_add((const arm_certificate_entry_s *)&trusted_cert);
284+
285+
arm_certificate_entry_s own_cert = {
286+
.cert = MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE,
287+
.key = MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY,
288+
.cert_len = 0,
289+
.key_len = 0
290+
};
291+
#ifdef MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_LEN
292+
own_cert.cert_len = MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_LEN;
293+
#else
294+
own_cert.cert_len = strlen((const char *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE) + 1;
295+
#endif
296+
#ifdef MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY_LEN
297+
own_cert.key_len = MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY_LEN;
298+
#else
299+
own_cert.key_len = strlen((const char *) MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE_KEY) + 1;
300+
#endif
301+
arm_network_own_certificate_add((const arm_certificate_entry_s *)&own_cert);
281302
#endif
282303

283304
status = arm_nwk_interface_up(wisun_tasklet_data_ptr->network_interface_id);

features/nanostack/sal-stack-nanostack/source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,40 @@ int8_t ws_pae_controller_own_certificates_remove(void)
821821
return 0;
822822
}
823823

824+
int8_t ws_pae_controller_own_certificate_add(const arm_certificate_entry_s *cert)
825+
{
826+
if (!cert) {
827+
return -1;
828+
}
829+
830+
int8_t ret = -1;
831+
832+
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {
833+
for (uint8_t i = 0; i < SEC_PROT_CERT_CHAIN_DEPTH; i++) {
834+
if (entry->certs.own_cert_chain.cert[i] == NULL) {
835+
sec_prot_certs_cert_set(&entry->certs.own_cert_chain, i, (uint8_t *) cert->cert, cert->cert_len);
836+
// Set private key if set for the certificate that is added
837+
if (cert->key && cert->key_len > 0) {
838+
sec_prot_certs_priv_key_set(&entry->certs.own_cert_chain, (uint8_t *) cert->key, cert->key_len);
839+
}
840+
ret = 0;
841+
break;
842+
}
843+
}
844+
}
845+
846+
return ret;
847+
}
848+
849+
int8_t ws_pae_controller_own_certificates_remove(void)
850+
{
851+
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {
852+
sec_prot_certs_chain_entry_init(&entry->certs.own_cert_chain);
853+
}
854+
855+
return 0;
856+
}
857+
824858
int8_t ws_pae_controller_trusted_certificate_add(const arm_certificate_entry_s *cert)
825859
{
826860
if (!cert) {

0 commit comments

Comments
 (0)