Skip to content

Commit 3b2d906

Browse files
author
Mika Leppänen
authored
Added check for network name and DODAG ID IID (EUI-64) (ARMmbed#2373)
- When using stored keys on NVM, supplicant now compares that both the PAN ID and network name of the BR matches to keys. - When RPL completes, and bootstrap indicates that to supplicant, bootstrap now includes the BR EUI-64 from DODAG ID to indication. If supplicant detects that BR EUI-64 does not match to keys, it destroyes the keys. Also the BR EUI-64 received from bootstrap is sent on EA-IE to nodes authenticating through the node. This corrects the case when PAN ID and network name of BR stay the same but EUI-64 changes.
1 parent ee45f4b commit 3b2d906

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,8 +2279,8 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
22792279
ws_eapol_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, dodag_info.dodag_id, EAPOL_RELAY_SOCKET_PORT);
22802280
// Set network information to PAE
22812281
ws_pae_controller_nw_info_set(cur, cur->ws_info->network_pan_id, cur->ws_info->cfg->gen.network_name);
2282-
// Network key is valid
2283-
ws_pae_controller_nw_key_valid(cur);
2282+
// Network key is valid, indicate border router IID to controller
2283+
ws_pae_controller_nw_key_valid(cur, &dodag_info.dodag_id[8]);
22842284

22852285
// After successful DAO ACK connection to border router is verified
22862286
cur->ws_info->pan_timeout_timer = cur->ws_info->cfg->timing.pan_timeout;

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface
166166
return 0;
167167
}
168168

169-
if (ws_pae_supp_authenticate(controller->interface_ptr, controller->target_pan_id, controller->target_eui_64) < 0) {
169+
if (ws_pae_supp_authenticate(controller->interface_ptr, controller->target_pan_id, controller->target_eui_64, controller->sec_keys_nw_info.network_name) < 0) {
170170
controller->auth_completed(interface_ptr, AUTH_RESULT_ERR_UNSPEC, controller->target_eui_64);
171171
}
172172
#endif
@@ -327,7 +327,7 @@ static void ws_pae_controller_nw_info_updated_check(protocol_interface_info_entr
327327
}
328328
}
329329

330-
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr)
330+
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr, uint8_t *br_iid)
331331
{
332332
if (!interface_ptr) {
333333
return -1;
@@ -338,7 +338,7 @@ int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface
338338
return -1;
339339
}
340340

341-
return ws_pae_supp_nw_key_valid(interface_ptr);
341+
return ws_pae_supp_nw_key_valid(interface_ptr, br_iid);
342342
}
343343

344344
static int8_t ws_pae_controller_nw_key_check_and_insert(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks)

source/6LoWPAN/ws/ws_pae_controller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,13 @@ int8_t ws_pae_controller_nw_info_set(protocol_interface_info_entry_t *interface_
249249
* ws_pae_controller_nw_key_valid network key is valid i.e. used successfully on bootstrap
250250
*
251251
* \param interface_ptr interface
252+
* \param br_iid border router IID for which the keys are valid
252253
*
253254
* \return < 0 failure
254255
* \return >= 0 success
255256
*
256257
*/
257-
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr);
258+
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr, uint8_t *br_iid);
258259

259260
/**
260261
* ws_pae_controller_border_router_addr_write write border router address
@@ -278,7 +279,7 @@ int8_t ws_pae_controller_border_router_addr_write(protocol_interface_info_entry_
278279
* \return >= 0 success
279280
*
280281
*/
281-
int8_t ws_pae_controller_border_router_addr_read(protocol_interface_info_entry_t *interface_ptr, uint8_t *eui_64);
282+
int8_t ws_pae_controller_border_router_addr_read(protocol_interface_info_entry_t *interface_ptr, uint8_t *iid);
282283

283284
/**
284285
* ws_pae_controller_gtk_update update GTKs (test interface)

source/6LoWPAN/ws/ws_pae_supp.c

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ typedef struct {
9797
uint16_t initial_key_retry_timer; /**< Timer to trigger initial EAPOL-Key 1st retry */
9898
trickle_t auth_trickle_timer; /**< Trickle timer for re-sending initial EAPOL-key or for GTK mismatch */
9999
trickle_params_t auth_trickle_params; /**< Trickle parameters for initial EAPOL-key or for GTK mismatch */
100-
uint8_t new_br_eui_64[8]; /**< Border router EUI-64 indicated by bootstrap */
100+
uint8_t new_br_eui_64[8]; /**< Border router EUI-64 indicated by bootstrap after bootstrap start */
101+
uint8_t comp_br_eui_64[8]; /**< Border router EUI-64 indicated by bootstrap after bootstrap completed */
101102
sec_prot_keys_nw_info_t *sec_keys_nw_info; /**< Security keys network information */
102103
sec_timer_cfg_t *sec_timer_cfg; /**< Timer configuration */
103104
sec_prot_cfg_t *sec_prot_cfg; /**< Protocol Configuration */
@@ -106,8 +107,9 @@ typedef struct {
106107
bool auth_trickle_running : 1; /**< Initial EAPOL-Key Trickle timer running */
107108
bool auth_requested : 1; /**< Authentication has been requested by the bootstrap */
108109
bool timer_running : 1; /**< Timer is running */
109-
bool new_br_eui_64_set : 1; /**< Border router address has been set */
110+
bool new_br_eui_64_set : 1; /**< Border router address has been set after bootstrap start */
110111
bool new_br_eui_64_fresh : 1; /**< Border router address is fresh (set during this authentication attempt) */
112+
bool comp_br_eui_64_set : 1; /**< Border router address has been set after bootstrap completed */
111113
bool entry_address_active: 1; /**< EAPOL target address is set */
112114
bool tx_failure_on_initial_key: 1; /**< TX failure has happened on initial EAPOL-key sequence */
113115
} pae_supp_t;
@@ -124,7 +126,7 @@ static void ws_pae_supp_free(pae_supp_t *pae_supp);
124126
static void ws_pae_supp_authenticate_response(pae_supp_t *pae_supp, auth_result_e result);
125127
static int8_t ws_pae_supp_initial_key_send(pae_supp_t *pae_supp);
126128
static void ws_pae_supp_nvm_update(pae_supp_t *pae_supp);
127-
static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan_id);
129+
static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan_id, char *dest_network_name);
128130
static int8_t ws_pae_supp_nvm_keys_write(pae_supp_t *pae_supp);
129131
static pae_supp_t *ws_pae_supp_get(protocol_interface_info_entry_t *interface_ptr);
130132
static int8_t ws_pae_supp_event_send(kmp_service_t *service, void *data);
@@ -180,24 +182,25 @@ static bool ws_pae_supp_address_is_set(pae_supp_t *pae_supp)
180182
return pae_supp->entry_address_active;
181183
}
182184

183-
int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr, uint16_t dest_pan_id, uint8_t *dest_eui_64)
185+
int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr, uint16_t dest_pan_id, uint8_t *dest_eui_64, char *dest_network_name)
184186
{
185187
pae_supp_t *pae_supp = ws_pae_supp_get(interface_ptr);
186188
if (!pae_supp) {
187189
return -1;
188190
}
189191

190-
if (ws_pae_supp_nw_keys_valid_check(pae_supp, dest_pan_id) >= 0) {
192+
if (ws_pae_supp_nw_keys_valid_check(pae_supp, dest_pan_id, dest_network_name) >= 0) {
191193
pae_supp->auth_completed(interface_ptr, AUTH_RESULT_OK, NULL);
192194
return 0;
193195
}
194196

195197
// Delete GTKs
196198
sec_prot_keys_gtks_init(pae_supp->sec_keys_nw_info->gtks);
197199

198-
/* PAN ID has changed, delete key data associated with border router
200+
/* Network name or PAN ID has changed, delete key data associated with border router
199201
i.e PMK, PTK, EA-IE data (border router EUI-64) */
200-
if (pae_supp->sec_keys_nw_info->key_pan_id != 0xFFFF && pae_supp->sec_keys_nw_info->key_pan_id != dest_pan_id) {
202+
if (strcmp(pae_supp->sec_keys_nw_info->network_name, dest_network_name) != 0 ||
203+
(pae_supp->sec_keys_nw_info->key_pan_id != 0xFFFF && pae_supp->sec_keys_nw_info->key_pan_id != dest_pan_id)) {
201204
sec_prot_keys_pmk_delete(&pae_supp->entry.sec_keys);
202205
sec_prot_keys_ptk_delete(&pae_supp->entry.sec_keys);
203206
sec_prot_keys_ptk_eui_64_delete(&pae_supp->entry.sec_keys);
@@ -207,6 +210,7 @@ int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr,
207210

208211
// Prepare to receive new border router address
209212
pae_supp->new_br_eui_64_fresh = false;
213+
pae_supp->comp_br_eui_64_set = false;
210214

211215
// Stores target/parent address
212216
kmp_address_init(KMP_ADDR_EUI_64, &pae_supp->target_addr, dest_eui_64);
@@ -247,24 +251,46 @@ int8_t ws_pae_supp_border_router_addr_read(protocol_interface_info_entry_t *inte
247251
return -1;
248252
}
249253

254+
// Check if there is border router EUI-64 on used on 4WH PTK generation
250255
uint8_t *br_eui_64 = sec_prot_keys_ptk_eui_64_get(&pae_supp->entry.sec_keys);
251256
if (!br_eui_64) {
252-
return -1;
257+
// Check if there is border router EUI-64 indicated by the bootstrap when bootstrap completed
258+
if (!pae_supp->comp_br_eui_64_set) {
259+
return -1;
260+
}
261+
br_eui_64 = pae_supp->comp_br_eui_64;
253262
}
254263

255264
memcpy(eui_64, br_eui_64, 8);
256265

257266
return 0;
258267
}
259268

260-
int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr)
269+
int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr, uint8_t *br_iid)
261270
{
262271
pae_supp_t *pae_supp = ws_pae_supp_get(interface_ptr);
263272
if (!pae_supp) {
264273
return -1;
265274
}
266275

267-
tr_info("NW key valid");
276+
tr_info("NW key valid indication");
277+
278+
// Store border router EUI-64 received on bootstrap complete
279+
memcpy(pae_supp->comp_br_eui_64, br_iid, 8);
280+
pae_supp->comp_br_eui_64[0] ^= 0x02;
281+
pae_supp->comp_br_eui_64_set = true;
282+
283+
// Get the EUI-64 used on 4WH handshake PTK generation
284+
uint8_t *ptk_eui_64 = sec_prot_keys_ptk_eui_64_get(&pae_supp->entry.sec_keys);
285+
286+
/* If border router EUI-64 received on bootstrap complete does not match to
287+
EUI-64 stored with keys, delete keys */
288+
if (memcmp(ptk_eui_64, pae_supp->comp_br_eui_64, 8) != 0) {
289+
tr_warn("Delete keys: PTK EUI-64 %s does not match to BR EUI-64 %s", tr_array(ptk_eui_64, 8), tr_array(pae_supp->comp_br_eui_64, 8));
290+
sec_prot_keys_pmk_delete(&pae_supp->entry.sec_keys);
291+
sec_prot_keys_ptk_delete(&pae_supp->entry.sec_keys);
292+
sec_prot_keys_ptk_eui_64_delete(&pae_supp->entry.sec_keys);
293+
}
268294

269295
// Stored keys are valid
270296
pae_supp->nw_keys_used_cnt = 0;
@@ -461,7 +487,7 @@ static int8_t ws_pae_supp_initial_key_send(pae_supp_t *pae_supp)
461487
return 0;
462488
}
463489

464-
static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan_id)
490+
static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan_id, char *dest_network_name)
465491
{
466492
// Checks how many times authentication has been tried with current network keys
467493
if (pae_supp->nw_keys_used_cnt >= STORED_KEYS_MAXIMUM_USE_COUNT) {
@@ -476,9 +502,11 @@ static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan
476502
return -1;
477503
}
478504

479-
/* Checks if keys match to PAN ID and that needed keys exists (PMK, PTK and a GTK),
480-
and calls inserts function that will update the network keys as needed */
481-
if ((pan_id == pae_supp->sec_keys_nw_info->key_pan_id) &&
505+
/* Checks if keys match to network name and PAN ID and that needed keys exists (PMK,
506+
PTK and a GTK), and calls inserts function that will update the network keys as
507+
needed */
508+
if ((strcmp(dest_network_name, pae_supp->sec_keys_nw_info->network_name) == 0 &&
509+
pan_id == pae_supp->sec_keys_nw_info->key_pan_id) &&
482510
(sec_prot_keys_gtk_count(pae_supp->sec_keys_nw_info->gtks) > 0) &&
483511
(sec_prot_keys_pmk_get(&pae_supp->entry.sec_keys) != NULL) &&
484512
(sec_prot_keys_ptk_get(&pae_supp->entry.sec_keys) != NULL)) {
@@ -542,6 +570,7 @@ int8_t ws_pae_supp_init(protocol_interface_info_entry_t *interface_ptr, const se
542570
pae_supp->timer_running = false;
543571
pae_supp->new_br_eui_64_set = false;
544572
pae_supp->new_br_eui_64_fresh = false;
573+
pae_supp->comp_br_eui_64_set = false;
545574
pae_supp->entry_address_active = false;
546575

547576
ws_pae_lib_supp_init(&pae_supp->entry);

source/6LoWPAN/ws/ws_pae_supp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ void ws_pae_supp_slow_timer(uint16_t seconds);
8181
* \param interface_ptr interface
8282
* \param dest_pan_id EAPOL target PAN ID
8383
* \param dest_eui_64 EAPOL target
84+
* \param dest_network_name EAPOL target network name
8485
*
8586
* \return < 0 failure
8687
* \return 0 authentication done, continue
8788
* \return > 0 authentication started
8889
*
8990
*/
90-
int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr, uint16_t dest_pan_id, uint8_t *dest_eui_64);
91+
int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr, uint16_t dest_pan_id, uint8_t *dest_eui_64, char *dest_network_name);
9192

9293
/**
9394
* ws_pae_supp_border_router_addr_write write border router address
@@ -117,12 +118,13 @@ int8_t ws_pae_supp_border_router_addr_read(protocol_interface_info_entry_t *inte
117118
* ws_pae_supp_nw_key_valid network key is valid i.e. used successfully on bootstrap
118119
*
119120
* \param interface_ptr interface
121+
* \param br_iid border router IID for which the keys are valid
120122
*
121123
* \return < 0 failure
122124
* \return >= 0 success
123125
*
124126
*/
125-
int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr);
127+
int8_t ws_pae_supp_nw_key_valid(protocol_interface_info_entry_t *interface_ptr, uint8_t *br_iid);
126128

127129
/**
128130
* ws_pae_supp_gtk_hash_update GTK hash has been updated (on PAN configuration)

0 commit comments

Comments
 (0)