Skip to content

Commit c870b76

Browse files
author
Mika Leppänen
committed
Added skipping of fragment length to EAP-TLS protocol and other improvements
- Fragment length field is now skipped if present in other messages than in first message with more fragments flag set. - For EAP-TLS start message on supplicant side: stops processing to flags field and ignores fields after it. - For TLS initialization errors (e.g. due to no-memory) on supplicant side, no longer sends empty EAP-TLS message, instead terminates the EAP-TLS and TLS sessions silently.
1 parent 561280b commit c870b76

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

source/Security/protocols/eap_tls_sec_prot/eap_tls_sec_prot_lib.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@ int8_t eap_tls_sec_prot_lib_message_handle(uint8_t *data, uint16_t length, bool
119119
data += 4;
120120
}
121121
result = EAP_TLS_MSG_MORE_FRAG;
122-
} else if (data[0] == 0) {
122+
} else if (data[0] == 0 || data[0] == EAP_TLS_FRAGMENT_LENGTH) {
123+
// Skip fragment length if present
124+
if (data[0] & EAP_TLS_FRAGMENT_LENGTH) {
125+
if (length < 5) {
126+
tr_error("EAP-TLS: decode error");
127+
return EAP_TLS_MSG_DECODE_ERROR;
128+
}
129+
length -= 4;
130+
data += 4;
131+
}
123132
// Last (or only) fragment or fragment acknowledge. If sending data
124133
// updates acknowledged fragments.
125134
if (new_seq_id && eap_tls_sec_prot_lib_ack_update(tls_send)) {
@@ -132,10 +141,15 @@ int8_t eap_tls_sec_prot_lib_message_handle(uint8_t *data, uint16_t length, bool
132141
length -= 1; // EAP-TLS flags
133142
data += 1;
134143

144+
// No further processing for EAP-TLS start
145+
if (result == EAP_TLS_MSG_START) {
146+
return EAP_TLS_MSG_START;
147+
}
148+
135149
// TLS data not included
136150
if (length == 0) {
137151
if (new_seq_id && result == EAP_TLS_MSG_CONTINUE) {
138-
// If received only EAP-TLS header fails, and is not start,
152+
// If received only EAP-TLS header fails, and is not
139153
// fragment acknowledge or last frame
140154
result = EAP_TLS_MSG_FAIL;
141155
}

source/Security/protocols/eap_tls_sec_prot/supp_eap_tls_sec_prot.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ static void supp_eap_tls_sec_prot_state_machine(sec_prot_t *prot)
466466
// Initialize TLS protocol
467467
if (supp_eap_tls_sec_prot_init_tls(prot) < 0) {
468468
tr_error("TLS init failed");
469+
// If fatal error terminates EAP-TLS
470+
sec_prot_result_set(&data->common, SEC_RESULT_ERROR);
471+
sec_prot_state_set(prot, &data->common, EAP_TLS_STATE_FINISH);
469472
return;
470473
}
471474
// Request TLS to start (send client hello)
@@ -508,7 +511,12 @@ static void supp_eap_tls_sec_prot_state_machine(sec_prot_t *prot)
508511
}
509512
} else {
510513
data->wait_tls = false;
511-
if (!data->tls_send.data || data->tls_result == EAP_TLS_RESULT_HANDSHAKE_FATAL_ERROR) {
514+
if (data->tls_result == EAP_TLS_RESULT_HANDSHAKE_FATAL_ERROR) {
515+
// If fatal error terminates EAP-TLS (TLS init has failed)
516+
sec_prot_result_set(&data->common, SEC_RESULT_ERROR);
517+
sec_prot_state_set(prot, &data->common, EAP_TLS_STATE_FINISH);
518+
return;
519+
} else if (!data->tls_send.data) {
512520
// If no more data send response, TLS EAP (empty)
513521
eap_tls_sec_prot_lib_message_allocate(&data->tls_send, TLS_HEAD_LEN, 0);
514522
}

0 commit comments

Comments
 (0)