Skip to content

Commit ed9eb05

Browse files
author
Mika Leppänen
committed
GTKs are removed only when fresh GTK hash is received
On some timing cases after bootstrap, nodes could remove GTK keys based on previous GTK hash received (hash had been updated by BR but indication had not reached all nodes yet). This is now corrected so that GTKs are removed only when fresh GTK hash is received.
1 parent 81ecdc2 commit ed9eb05

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef void ws_pae_timer(uint16_t ticks);
5151
typedef int8_t ws_pae_br_addr_write(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64);
5252
typedef int8_t ws_pae_br_addr_read(protocol_interface_info_entry_t *interface_ptr, uint8_t *eui_64);
5353
typedef void ws_pae_gtks_updated(protocol_interface_info_entry_t *interface_ptr);
54-
typedef int8_t ws_pae_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash);
54+
typedef int8_t ws_pae_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch);
5555
typedef int8_t ws_pae_nw_key_index_update(protocol_interface_info_entry_t *interface_ptr, uint8_t index);
5656
typedef int8_t ws_pae_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name, bool updated);
5757

@@ -196,7 +196,7 @@ int8_t ws_pae_controller_bootstrap_done(protocol_interface_info_entry_t *interfa
196196

197197
/* Trigger GTK hash update to supplicant, so it can check whether keys have been updated
198198
during bootstrap. Does nothing if GTKs are up to date. */
199-
ws_pae_supp_gtk_hash_update(interface_ptr, controller->gtkhash);
199+
ws_pae_supp_gtk_hash_update(interface_ptr, controller->gtkhash, false);
200200
#endif
201201

202202
return 0;
@@ -1662,7 +1662,7 @@ int8_t ws_pae_controller_gtk_hash_update(protocol_interface_info_entry_t *interf
16621662
memcpy(controller->gtkhash, gtkhash, 32);
16631663

16641664
if (controller->pae_gtk_hash_update) {
1665-
return controller->pae_gtk_hash_update(interface_ptr, controller->gtkhash);
1665+
return controller->pae_gtk_hash_update(interface_ptr, controller->gtkhash, true);
16661666
}
16671667

16681668
return 0;

source/6LoWPAN/ws/ws_pae_supp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int8_t ws_pae_supp_gtk_hash_mismatch_check(pae_supp_t *pae_supp)
294294
}
295295

296296
// Check GTK hashes and initiate EAPOL procedure if mismatch is detected */
297-
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash);
297+
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash, false);
298298
if (mismatch != GTK_NO_MISMATCH) {
299299
return -1;
300300
}
@@ -303,15 +303,15 @@ static int8_t ws_pae_supp_gtk_hash_mismatch_check(pae_supp_t *pae_supp)
303303
return 0;
304304
}
305305

306-
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash)
306+
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch)
307307
{
308308
pae_supp_t *pae_supp = ws_pae_supp_get(interface_ptr);
309309
if (!pae_supp) {
310310
return -1;
311311
}
312312

313313
// Check GTK hashes and initiate EAPOL procedure if mismatch is detected */
314-
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash);
314+
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash, del_gtk_on_mismatch);
315315
if (mismatch > GTK_NO_MISMATCH) {
316316
tr_info("GTK hash update %s %s %s %s",
317317
trace_array(&gtkhash[0], 8),

source/6LoWPAN/ws/ws_pae_supp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr,
130130
*
131131
* \param interface_ptr interface
132132
* \param gtkhash GTK hash, 32 bytes
133+
* \param del_gtk_on_mismatch Delete GTK in case of mismatch
133134
*
134135
* \return < 0 failure
135136
* \return >= 0 success
136137
*
137138
*/
138-
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash);
139+
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch);
139140

140141
/**
141142
* ws_pae_supp_nw_key_index_update key index been updated (on PAN configuration)

source/Security/protocols/sec_prot_keys.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ int8_t sec_prot_keys_gtk_valid_check(uint8_t *gtk)
716716
return 0;
717717
}
718718

719-
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash)
719+
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash, bool del_gtk_on_mismatch)
720720
{
721721
uint8_t *gtk_hash_ptr = gtkhash;
722722

@@ -729,11 +729,15 @@ gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t
729729
uint32_t lifetime = sec_prot_keys_gtk_lifetime_get(gtks, i);
730730
if (lifetime > GTK_EXPIRE_MISMATCH_TIME) {
731731
tr_info("GTK mismatch %i expired time, lifetime: %"PRIu32"", i, lifetime);
732-
if (mismatch < GTK_LIFETIME_MISMATCH) {
732+
// Only indicate mismatch in case fresh hash is received
733+
if (mismatch < GTK_LIFETIME_MISMATCH && del_gtk_on_mismatch) {
733734
mismatch = GTK_LIFETIME_MISMATCH;
734735
}
735736
}
736-
sec_prot_keys_gtk_clear(gtks, i);
737+
// Only delete in case fresh hash is received
738+
if (del_gtk_on_mismatch) {
739+
sec_prot_keys_gtk_clear(gtks, i);
740+
}
737741
}
738742
} else {
739743
// Check is hash matches to existing key
@@ -759,7 +763,10 @@ gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t
759763
if (mismatch < GTK_HASH_MISMATCH) {
760764
mismatch = GTK_HASH_MISMATCH;
761765
}
762-
sec_prot_keys_gtk_clear(gtks, i);
766+
// Only delete in case fresh hash is received
767+
if (del_gtk_on_mismatch) {
768+
sec_prot_keys_gtk_clear(gtks, i);
769+
}
763770
}
764771
}
765772
}

source/Security/protocols/sec_prot_keys.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,12 @@ int8_t sec_prot_keys_gtk_valid_check(uint8_t *gtk);
806806
*
807807
* \param gtks GTK keys
808808
* \param gtk_hash GTK hash
809+
* \param del_gtk_on_mismatch Delete GTK in case of mismatch
809810
*
810811
* \return GTK mismatch type or no mismatch
811812
*
812813
*/
813-
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash);
814+
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash, bool del_gtk_on_mismatch);
814815

815816
/**
816817
* sec_prot_keys_gtk_hash_empty checks if GTK hash field is empty

0 commit comments

Comments
 (0)