Skip to content

Commit e5f1627

Browse files
author
Mika Leppänen
committed
Increased TLS queue size, corrected EUI-64 read and added traces
Increased TLS queue size to three for now (thus disabling it in most cases). The randomization caused by EAP-TLS initial negotiation (identity / TLS start) with ongoing EAP-TLS limit of three, should be enough to limit resources used by TLS calculations on border router. Previous small TLS queue size resulted that failing TLS negotiation prevented other nodes to authenticate for a long time. Corrected null pointer read on border router traces, and added traces to TLS library failure cases.
1 parent 67bb748 commit e5f1627

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

source/Security/protocols/sec_prot_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ int8_t sec_prot_lib_gtkhash_generate(uint8_t *gtk, uint8_t *gtk_hash)
511511

512512
uint8_t *sec_prot_remote_eui_64_addr_get(sec_prot_t *prot)
513513
{
514-
if (prot->sec_keys->ptk_eui_64_set) {
514+
if (prot->sec_keys && prot->sec_keys->ptk_eui_64_set) {
515515
return prot->sec_keys->ptk_eui_64;
516516
} else {
517517
return NULL;

source/Security/protocols/tls_sec_prot/tls_sec_prot.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,17 @@ static void server_tls_sec_prot_state_machine(sec_prot_t *prot)
472472
data->library_init = false;
473473
break;
474474

475-
case TLS_STATE_FINISHED:
476-
tr_debug("TLS: finished, eui-64: %s free %s", trace_array(sec_prot_remote_eui_64_addr_get(prot), 8), data->library_init ? "T" : "F");
475+
case TLS_STATE_FINISHED: {
476+
uint8_t *remote_eui_64 = sec_prot_remote_eui_64_addr_get(prot);
477+
tr_debug("TLS: finished, eui-64: %s free %s", remote_eui_64 ? trace_array(sec_prot_remote_eui_64_addr_get(prot), 8) : "not set", data->library_init ? "T" : "F");
477478
if (data->library_init) {
478479
tls_sec_prot_lib_free((tls_security_t *) &data->tls_sec_inst);
479480
data->library_init = false;
480481
}
481482
prot->timer_stop(prot);
482483
prot->finished(prot);
483484
break;
484-
485+
}
485486
default:
486487
break;
487488
}
@@ -597,6 +598,7 @@ static int8_t tls_sec_prot_tls_configure_and_connect(sec_prot_t *prot, bool is_s
597598
// Must be free if library initialize is done
598599
data->library_init = true;
599600
if (tls_sec_prot_lib_init((tls_security_t *)&data->tls_sec_inst) < 0) {
601+
tr_error("TLS: library init fail");
600602
return -1;
601603
}
602604

@@ -605,6 +607,7 @@ static int8_t tls_sec_prot_tls_configure_and_connect(sec_prot_t *prot, bool is_s
605607
tls_sec_prot_tls_set_timer, tls_sec_prot_tls_get_timer);
606608

607609
if (tls_sec_prot_lib_connect((tls_security_t *)&data->tls_sec_inst, is_server, prot->sec_keys->certs) < 0) {
610+
tr_error("TLS: library connect fail");
608611
return -1;
609612
}
610613

@@ -615,30 +618,29 @@ static bool tls_sec_prot_queue_check(sec_prot_t *prot)
615618
{
616619
bool queue_add = true;
617620
bool queue_continue = false;
618-
bool first_entry = true;
621+
uint8_t entry_index = 0;
619622

620623
// Checks if TLS queue is empty or this instance is the first entry
621624
if (ns_list_is_empty(&tls_sec_prot_queue)) {
622625
queue_continue = true;
623626
} else {
624-
625627
ns_list_foreach(tls_sec_prot_queue_t, entry, &tls_sec_prot_queue) {
626628
if (entry->prot == prot) {
627629
queue_add = false;
628-
if (first_entry) {
630+
if (entry_index < 3) {
629631
queue_continue = true;
630632
break;
631633
} else {
632634
queue_continue = false;
633635
}
634636
}
635-
first_entry = false;
637+
entry_index++;
636638
}
637639
}
638640

639641
// Adds entry to queue if not there already
640642
if (queue_add) {
641-
tr_debug("TLS QUEUE add%s, eui-64: %s", first_entry ? " first" : "", trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
643+
tr_debug("TLS QUEUE add index: %i, eui-64: %s", entry_index, trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
642644
tls_sec_prot_queue_t *entry = ns_dyn_mem_temporary_alloc(sizeof(tls_sec_prot_queue_t));
643645
if (entry) {
644646
entry->prot = prot;
@@ -655,11 +657,15 @@ static bool tls_sec_prot_queue_process(sec_prot_t *prot)
655657
return true;
656658
}
657659

660+
uint8_t entry_index = 0;
658661
ns_list_foreach(tls_sec_prot_queue_t, entry, &tls_sec_prot_queue) {
659662
if (entry->prot == prot) {
660663
return true;
661664
}
662-
return false;
665+
if (entry_index > 2) {
666+
return false;
667+
}
668+
entry_index++;
663669
}
664670

665671
return false;

source/Security/protocols/tls_sec_prot/tls_sec_prot_lib.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ int8_t tls_sec_prot_lib_init(tls_security_t *sec)
126126

127127
if (mbedtls_entropy_add_source(&sec->entropy, tls_sec_lib_entropy_poll, NULL,
128128
128, MBEDTLS_ENTROPY_SOURCE_WEAK) < 0) {
129+
tr_error("Entropy add fail");
129130
return -1;
130131
}
131132

132133
if ((mbedtls_ctr_drbg_seed(&sec->ctr_drbg, mbedtls_entropy_func, &sec->entropy,
133134
(const unsigned char *) pers, strlen(pers))) != 0) {
135+
tr_error("drbg seed fail");
134136
return -1;
135137
}
136138

@@ -177,6 +179,7 @@ void tls_sec_prot_lib_free(tls_security_t *sec)
177179
static int tls_sec_prot_lib_configure_certificates(tls_security_t *sec, const sec_prot_certs_t *certs)
178180
{
179181
if (!certs->own_cert_chain.cert[0]) {
182+
tr_error("no own cert");
180183
return -1;
181184
}
182185

@@ -282,6 +285,7 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
282285
}
283286

284287
if ((mbedtls_ssl_config_defaults(&sec->conf, endpoint, MBEDTLS_SSL_TRANSPORT_STREAM, 0)) != 0) {
288+
tr_error("config defaults fail");
285289
return -1;
286290
}
287291

@@ -294,6 +298,7 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
294298
#endif
295299

296300
if ((mbedtls_ssl_setup(&sec->ssl, &sec->conf)) != 0) {
301+
tr_error("ssl setup fail");
297302
return -1;
298303
}
299304

@@ -303,10 +308,10 @@ int8_t tls_sec_prot_lib_connect(tls_security_t *sec, bool is_server, const sec_p
303308

304309
// Configure certificates, keys and certificate revocation list
305310
if (tls_sec_prot_lib_configure_certificates(sec, certs) != 0) {
311+
tr_error("cert conf fail");
306312
return -1;
307313
}
308314

309-
310315
// Configure ciphersuites
311316
static const int sec_suites[] = {
312317
MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8,
@@ -471,6 +476,7 @@ static int tls_sec_lib_entropy_poll(void *ctx, unsigned char *output, size_t len
471476

472477
char *c = (char *)ns_dyn_mem_temporary_alloc(len);
473478
if (!c) {
479+
tr_error("entropy alloca fail");
474480
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
475481
}
476482
memset(c, 0, len);

0 commit comments

Comments
 (0)