Skip to content

Commit f47ad87

Browse files
author
Mika Leppänen
committed
PAE supplicant and authenticator GTK update procedure
Added support for GTK key and active key set test commands. GTK update procedure is following: - Authenticator adds new GTK to GTK HASH and updates PAN version - Nodes receive updated GTK HASH on PAN configuration message and detect that new GTK is inserted - Nodes send EAPOL-Key to request new GTK from authenticator - Authenticator initates GTK handshakes towards nodes to update GTKs - After the GTKs are updated, authenticator takes new key index index into use (on sending) and updates PAN version - Nodes receive updated key index on PAN configuration message and take it into use - Authenticator removes old GTK from GTK HASH
1 parent b400a6a commit f47ad87

32 files changed

+1659
-332
lines changed

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,26 @@ int8_t mac_helper_security_default_key_set(protocol_interface_info_entry_t *inte
339339
return 0;
340340
}
341341

342+
int8_t mac_helper_security_default_recv_key_set(protocol_interface_info_entry_t *interface, const uint8_t *key, uint8_t id, uint8_t keyid_mode)
343+
{
344+
if (id == 0 || keyid_mode > 3) {
345+
return -1;
346+
}
347+
348+
mac_helper_keytable_descriptor_set(interface->mac_api, key, id, interface->mac_parameters->mac_default_key_attribute_id);
349+
return 0;
350+
}
351+
352+
int8_t mac_helper_security_auto_request_key_index_set(protocol_interface_info_entry_t *interface, uint8_t id)
353+
{
354+
if (id == 0) {
355+
return -1;
356+
}
357+
358+
mac_helper_pib_8bit_set(interface, macAutoRequestKeyIndex, id);
359+
return 0;
360+
}
361+
342362

343363
int8_t mac_helper_security_pairwisekey_set(protocol_interface_info_entry_t *interface, const uint8_t *key, const uint8_t *mac_64, uint8_t key_attribute)
344364
{

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ uint8_t mac_helper_default_key_index_get(struct protocol_interface_info_entry *i
6767

6868
int8_t mac_helper_security_default_key_set(struct protocol_interface_info_entry *interface, const uint8_t *key, uint8_t id, uint8_t keyid_mode);
6969

70+
int8_t mac_helper_security_default_recv_key_set(struct protocol_interface_info_entry *interface, const uint8_t *key, uint8_t id, uint8_t keyid_mode);
71+
72+
int8_t mac_helper_security_auto_request_key_index_set(struct protocol_interface_info_entry *interface, uint8_t id);
73+
7074
int8_t mac_helper_security_next_key_set(struct protocol_interface_info_entry *interface, uint8_t *key, uint8_t id, uint8_t keyid_mode);
7175

7276
int8_t mac_helper_security_prev_key_set(struct protocol_interface_info_entry *interface, uint8_t *key, uint8_t id, uint8_t keyid_mode);

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ static uint16_t ws_bootstrap_routing_cost_calculate(protocol_interface_info_entr
8585
static uint16_t ws_bootstrap_rank_get(protocol_interface_info_entry_t *cur);
8686
static uint16_t ws_bootstrap_min_rank_inc_get(protocol_interface_info_entry_t *cur);
8787

88-
static void ws_bootstrap_key_insert(protocol_interface_info_entry_t *cur, uint8_t gtk_index, uint8_t *gtk);
88+
static void ws_bootstrap_nw_key_insert(protocol_interface_info_entry_t *cur, uint8_t operation, uint8_t index, uint8_t *key);
89+
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index);
8990
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success);
91+
static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t *cur);
9092

9193
mac_neighbor_table_entry_t *ws_bootstrap_mac_neighbor_add(struct protocol_interface_info_entry *interface, const uint8_t *src64)
9294

@@ -1027,7 +1029,10 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
10271029

10281030
cur->ws_info->pan_version_timeout_timer = PAN_VERSION_TIMEOUT;
10291031
cur->ws_info->pan_information.pan_version = pan_version;
1030-
memcpy(cur->ws_info->gtkhash, gtkhash_ptr, 32);
1032+
1033+
ws_pae_controller_gtk_hash_update(cur, gtkhash_ptr);
1034+
1035+
ws_pae_controller_nw_key_index_update(cur, data->Key.KeyIndex - 1);
10311036

10321037
if (!cur->ws_info->configuration_learned) {
10331038
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
@@ -1452,7 +1457,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
14521457
ret_val = -4;
14531458
goto init_fail;
14541459
}
1455-
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_key_insert) < 0) {
1460+
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_nw_key_insert, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_pan_version_increment) < 0) {
14561461
ret_val = -4;
14571462
goto init_fail;
14581463
}
@@ -1619,7 +1624,8 @@ static void ws_bootstrap_network_configuration_learn(protocol_interface_info_ent
16191624

16201625
// Timing information can be modified here
16211626
ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information);
1622-
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
1627+
uint8_t *gtkhash = ws_pae_controller_gtk_hash_ptr_get(cur);
1628+
ws_llc_set_gtkhash(cur, gtkhash);
16231629
// TODO update own fhss schedules we are starting to follow first parent
16241630

16251631
return;
@@ -1845,6 +1851,11 @@ static void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur)
18451851
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config, &cur->ws_info->trickle_params_pan_discovery);
18461852
}
18471853

1854+
static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t *cur)
1855+
{
1856+
cur->ws_info->pan_version_timer = randLIB_get_random_in_range(5, 15);
1857+
}
1858+
18481859
// Start network scan
18491860
static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
18501861
{
@@ -1883,23 +1894,33 @@ static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *c
18831894
ws_pae_controller_authenticate(cur);
18841895
}
18851896

1886-
1887-
static void ws_bootstrap_key_insert(protocol_interface_info_entry_t *cur, uint8_t gtk_index, uint8_t *gtk)
1897+
static void ws_bootstrap_nw_key_insert(protocol_interface_info_entry_t *cur, uint8_t operation, uint8_t index, uint8_t *key)
18881898
{
1889-
// Convert GTK to Group AES Key (GAK)
1890-
1891-
// Verify HASH etc.
1892-
1893-
// Check index, for now only reacts to keys of index 0
1894-
if (gtk_index == 0) {
1895-
mac_helper_security_key_clean(cur);
1896-
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1897-
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1898-
//Set Keys
1899-
mac_helper_security_default_key_set(cur, gtk, gtk_index + 1, MAC_KEY_ID_MODE_IDX);
1899+
switch (operation) {
1900+
case 0:
1901+
mac_helper_security_key_clean(cur);
1902+
mac_helper_default_security_level_set(cur, AES_SECURITY_LEVEL_ENC_MIC64);
1903+
mac_helper_default_security_key_id_mode_set(cur, MAC_KEY_ID_MODE_IDX);
1904+
break;
1905+
case 1:
1906+
mac_helper_security_default_recv_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
1907+
break;
1908+
case 2:
1909+
mac_helper_security_prev_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
1910+
break;
1911+
case 3:
1912+
mac_helper_security_next_key_set(cur, key, index + 1, MAC_KEY_ID_MODE_IDX);
1913+
break;
1914+
default:
1915+
break;
19001916
}
19011917
}
19021918

1919+
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index)
1920+
{
1921+
mac_helper_security_auto_request_key_index_set(cur, index + 1);
1922+
}
1923+
19031924
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, bool success)
19041925
{
19051926
if (success) {
@@ -2167,7 +2188,9 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
21672188
cur->ws_info->pan_information.rpl_routing_method = true;
21682189
cur->ws_info->pan_information.use_parent_bs = true;
21692190
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
2170-
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
2191+
2192+
uint8_t *gtkhash = ws_pae_controller_gtk_hash_ptr_get(cur);
2193+
ws_llc_set_gtkhash(cur, gtkhash);
21712194
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
21722195

21732196
// Set default parameters for FHSS when starting a discovery

0 commit comments

Comments
 (0)