@@ -97,7 +97,8 @@ typedef struct {
97
97
uint16_t initial_key_retry_timer ; /**< Timer to trigger initial EAPOL-Key 1st retry */
98
98
trickle_t auth_trickle_timer ; /**< Trickle timer for re-sending initial EAPOL-key or for GTK mismatch */
99
99
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 */
101
102
sec_prot_keys_nw_info_t * sec_keys_nw_info ; /**< Security keys network information */
102
103
sec_timer_cfg_t * sec_timer_cfg ; /**< Timer configuration */
103
104
sec_prot_cfg_t * sec_prot_cfg ; /**< Protocol Configuration */
@@ -106,8 +107,9 @@ typedef struct {
106
107
bool auth_trickle_running : 1 ; /**< Initial EAPOL-Key Trickle timer running */
107
108
bool auth_requested : 1 ; /**< Authentication has been requested by the bootstrap */
108
109
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 */
110
111
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 */
111
113
bool entry_address_active : 1 ; /**< EAPOL target address is set */
112
114
bool tx_failure_on_initial_key : 1 ; /**< TX failure has happened on initial EAPOL-key sequence */
113
115
} pae_supp_t ;
@@ -124,7 +126,7 @@ static void ws_pae_supp_free(pae_supp_t *pae_supp);
124
126
static void ws_pae_supp_authenticate_response (pae_supp_t * pae_supp , auth_result_e result );
125
127
static int8_t ws_pae_supp_initial_key_send (pae_supp_t * pae_supp );
126
128
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 );
128
130
static int8_t ws_pae_supp_nvm_keys_write (pae_supp_t * pae_supp );
129
131
static pae_supp_t * ws_pae_supp_get (protocol_interface_info_entry_t * interface_ptr );
130
132
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)
180
182
return pae_supp -> entry_address_active ;
181
183
}
182
184
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 )
184
186
{
185
187
pae_supp_t * pae_supp = ws_pae_supp_get (interface_ptr );
186
188
if (!pae_supp ) {
187
189
return -1 ;
188
190
}
189
191
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 ) {
191
193
pae_supp -> auth_completed (interface_ptr , AUTH_RESULT_OK , NULL );
192
194
return 0 ;
193
195
}
194
196
195
197
// Delete GTKs
196
198
sec_prot_keys_gtks_init (pae_supp -> sec_keys_nw_info -> gtks );
197
199
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
199
201
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 )) {
201
204
sec_prot_keys_pmk_delete (& pae_supp -> entry .sec_keys );
202
205
sec_prot_keys_ptk_delete (& pae_supp -> entry .sec_keys );
203
206
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,
207
210
208
211
// Prepare to receive new border router address
209
212
pae_supp -> new_br_eui_64_fresh = false;
213
+ pae_supp -> comp_br_eui_64_set = false;
210
214
211
215
// Stores target/parent address
212
216
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
247
251
return -1 ;
248
252
}
249
253
254
+ // Check if there is border router EUI-64 on used on 4WH PTK generation
250
255
uint8_t * br_eui_64 = sec_prot_keys_ptk_eui_64_get (& pae_supp -> entry .sec_keys );
251
256
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 ;
253
262
}
254
263
255
264
memcpy (eui_64 , br_eui_64 , 8 );
256
265
257
266
return 0 ;
258
267
}
259
268
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 )
261
270
{
262
271
pae_supp_t * pae_supp = ws_pae_supp_get (interface_ptr );
263
272
if (!pae_supp ) {
264
273
return -1 ;
265
274
}
266
275
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
+ }
268
294
269
295
// Stored keys are valid
270
296
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)
461
487
return 0 ;
462
488
}
463
489
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 )
465
491
{
466
492
// Checks how many times authentication has been tried with current network keys
467
493
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
476
502
return -1 ;
477
503
}
478
504
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 ) &&
482
510
(sec_prot_keys_gtk_count (pae_supp -> sec_keys_nw_info -> gtks ) > 0 ) &&
483
511
(sec_prot_keys_pmk_get (& pae_supp -> entry .sec_keys ) != NULL ) &&
484
512
(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
542
570
pae_supp -> timer_running = false;
543
571
pae_supp -> new_br_eui_64_set = false;
544
572
pae_supp -> new_br_eui_64_fresh = false;
573
+ pae_supp -> comp_br_eui_64_set = false;
545
574
pae_supp -> entry_address_active = false;
546
575
547
576
ws_pae_lib_supp_init (& pae_supp -> entry );
0 commit comments