Skip to content

Commit

Permalink
GTKs are removed only when fresh GTK hash is received
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mika Leppänen committed Jun 29, 2021
1 parent 81ecdc2 commit ed9eb05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions source/6LoWPAN/ws/ws_pae_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef void ws_pae_timer(uint16_t ticks);
typedef int8_t ws_pae_br_addr_write(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64);
typedef int8_t ws_pae_br_addr_read(protocol_interface_info_entry_t *interface_ptr, uint8_t *eui_64);
typedef void ws_pae_gtks_updated(protocol_interface_info_entry_t *interface_ptr);
typedef int8_t ws_pae_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash);
typedef int8_t ws_pae_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch);
typedef int8_t ws_pae_nw_key_index_update(protocol_interface_info_entry_t *interface_ptr, uint8_t index);
typedef int8_t ws_pae_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name, bool updated);

Expand Down Expand Up @@ -196,7 +196,7 @@ int8_t ws_pae_controller_bootstrap_done(protocol_interface_info_entry_t *interfa

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

return 0;
Expand Down Expand Up @@ -1662,7 +1662,7 @@ int8_t ws_pae_controller_gtk_hash_update(protocol_interface_info_entry_t *interf
memcpy(controller->gtkhash, gtkhash, 32);

if (controller->pae_gtk_hash_update) {
return controller->pae_gtk_hash_update(interface_ptr, controller->gtkhash);
return controller->pae_gtk_hash_update(interface_ptr, controller->gtkhash, true);
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/ws/ws_pae_supp.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static int8_t ws_pae_supp_gtk_hash_mismatch_check(pae_supp_t *pae_supp)
}

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

int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash)
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch)
{
pae_supp_t *pae_supp = ws_pae_supp_get(interface_ptr);
if (!pae_supp) {
return -1;
}

// Check GTK hashes and initiate EAPOL procedure if mismatch is detected */
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash);
gtk_mismatch_e mismatch = sec_prot_keys_gtks_hash_update(pae_supp->sec_keys_nw_info->gtks, gtkhash, del_gtk_on_mismatch);
if (mismatch > GTK_NO_MISMATCH) {
tr_info("GTK hash update %s %s %s %s",
trace_array(&gtkhash[0], 8),
Expand Down
3 changes: 2 additions & 1 deletion source/6LoWPAN/ws/ws_pae_supp.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr,
*
* \param interface_ptr interface
* \param gtkhash GTK hash, 32 bytes
* \param del_gtk_on_mismatch Delete GTK in case of mismatch
*
* \return < 0 failure
* \return >= 0 success
*
*/
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash);
int8_t ws_pae_supp_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash, bool del_gtk_on_mismatch);

/**
* ws_pae_supp_nw_key_index_update key index been updated (on PAN configuration)
Expand Down
15 changes: 11 additions & 4 deletions source/Security/protocols/sec_prot_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ int8_t sec_prot_keys_gtk_valid_check(uint8_t *gtk)
return 0;
}

gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash)
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash, bool del_gtk_on_mismatch)
{
uint8_t *gtk_hash_ptr = gtkhash;

Expand All @@ -729,11 +729,15 @@ gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t
uint32_t lifetime = sec_prot_keys_gtk_lifetime_get(gtks, i);
if (lifetime > GTK_EXPIRE_MISMATCH_TIME) {
tr_info("GTK mismatch %i expired time, lifetime: %"PRIu32"", i, lifetime);
if (mismatch < GTK_LIFETIME_MISMATCH) {
// Only indicate mismatch in case fresh hash is received
if (mismatch < GTK_LIFETIME_MISMATCH && del_gtk_on_mismatch) {
mismatch = GTK_LIFETIME_MISMATCH;
}
}
sec_prot_keys_gtk_clear(gtks, i);
// Only delete in case fresh hash is received
if (del_gtk_on_mismatch) {
sec_prot_keys_gtk_clear(gtks, i);
}
}
} else {
// Check is hash matches to existing key
Expand All @@ -759,7 +763,10 @@ gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t
if (mismatch < GTK_HASH_MISMATCH) {
mismatch = GTK_HASH_MISMATCH;
}
sec_prot_keys_gtk_clear(gtks, i);
// Only delete in case fresh hash is received
if (del_gtk_on_mismatch) {
sec_prot_keys_gtk_clear(gtks, i);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion source/Security/protocols/sec_prot_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,12 @@ int8_t sec_prot_keys_gtk_valid_check(uint8_t *gtk);
*
* \param gtks GTK keys
* \param gtk_hash GTK hash
* \param del_gtk_on_mismatch Delete GTK in case of mismatch
*
* \return GTK mismatch type or no mismatch
*
*/
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash);
gtk_mismatch_e sec_prot_keys_gtks_hash_update(sec_prot_gtk_keys_t *gtks, uint8_t *gtkhash, bool del_gtk_on_mismatch);

/**
* sec_prot_keys_gtk_hash_empty checks if GTK hash field is empty
Expand Down

0 comments on commit ed9eb05

Please sign in to comment.