Skip to content

Commit da732bc

Browse files
author
Mika Leppänen
committed
When network name or PAN ID is changed authenticator updates MAC keys
1 parent 59397d1 commit da732bc

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed

source/6LoWPAN/ws/ws_pae_auth.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@
7676

7777
typedef struct {
7878
ns_list_link_t link; /**< Link */
79+
uint16_t pan_id; /**< PAN ID */
80+
char network_name[33]; /**< Network name */
7981
kmp_service_t *kmp_service; /**< KMP service */
8082
protocol_interface_info_entry_t *interface_ptr; /**< Interface pointer */
8183
ws_pae_auth_gtk_hash_set *hash_set; /**< GTK hash set callback */
8284
ws_pae_auth_nw_key_insert *nw_key_insert; /**< Key insert callback */
85+
ws_pae_auth_nw_keys_remove *nw_keys_remove; /**< Network keys remove callback */
8386
ws_pae_auth_nw_key_index_set *nw_key_index_set; /**< Key index set callback */
8487
supp_list_t active_supp_list; /**< List of active supplicants */
8588
supp_list_t inactive_supp_list; /**< List of inactive supplicants */
@@ -140,13 +143,17 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot
140143
return -1;
141144
}
142145

146+
147+
memset(&pae_auth->network_name, 0, 33);
148+
pae_auth->pan_id = 0xffff;
143149
pae_auth->interface_ptr = interface_ptr;
144150
ws_pae_lib_supp_list_init(&pae_auth->active_supp_list);
145151
ws_pae_lib_supp_list_init(&pae_auth->inactive_supp_list);
146152
pae_auth->timer = NULL;
147153

148154
pae_auth->hash_set = NULL;
149155
pae_auth->nw_key_insert = NULL;
156+
pae_auth->nw_keys_remove = NULL;
150157
pae_auth->nw_key_index_set = NULL;
151158

152159
pae_auth->gtks = gtks;
@@ -254,7 +261,7 @@ int8_t ws_pae_auth_delete(protocol_interface_info_entry_t *interface_ptr)
254261
return 0;
255262
}
256263

257-
void ws_pae_auth_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_pae_auth_gtk_hash_set *hash_set, ws_pae_auth_nw_key_insert *nw_key_insert, ws_pae_auth_nw_key_index_set *nw_key_index_set)
264+
void ws_pae_auth_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_pae_auth_gtk_hash_set *hash_set, ws_pae_auth_nw_key_insert *nw_key_insert, ws_pae_auth_nw_key_index_set *nw_key_index_set, ws_pae_auth_nw_keys_remove *nw_keys_remove)
258265
{
259266
if (!interface_ptr) {
260267
return;
@@ -268,6 +275,7 @@ void ws_pae_auth_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_
268275
pae_auth->hash_set = hash_set;
269276
pae_auth->nw_key_insert = nw_key_insert;
270277
pae_auth->nw_key_index_set = nw_key_index_set;
278+
pae_auth->nw_keys_remove = nw_keys_remove;
271279
}
272280

273281
void ws_pae_auth_start(protocol_interface_info_entry_t *interface_ptr)
@@ -455,6 +463,48 @@ void ws_pae_auth_forced_gc(protocol_interface_info_entry_t *interface_ptr)
455463
ws_pae_lib_supp_list_purge(&pae_auth->active_supp_list, &pae_auth->inactive_supp_list, 0, SUPPLICANT_NUMBER_TO_PURGE);
456464
}
457465

466+
int8_t ws_pae_auth_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name)
467+
{
468+
if (!interface_ptr || !network_name) {
469+
return -1;
470+
}
471+
472+
pae_auth_t *pae_auth = ws_pae_auth_get(interface_ptr);
473+
if (!pae_auth) {
474+
return -1;
475+
}
476+
477+
bool update_keys = false;
478+
if (pae_auth->pan_id != 0xffff && pae_auth->pan_id != pan_id) {
479+
update_keys = true;
480+
}
481+
pae_auth->pan_id = pan_id;
482+
483+
if (strlen((char *) &pae_auth->network_name) > 0 && strcmp((char *) &pae_auth->network_name, network_name) != 0) {
484+
update_keys = true;
485+
}
486+
strcpy((char *) &pae_auth->network_name, network_name);
487+
488+
if (!update_keys) {
489+
return 0;
490+
}
491+
492+
if (pae_auth->nw_keys_remove) {
493+
pae_auth->nw_keys_remove(pae_auth->interface_ptr);
494+
}
495+
496+
ws_pae_auth_network_keys_from_gtks_set(pae_auth);
497+
498+
int8_t index = sec_prot_keys_gtk_status_active_get(pae_auth->gtks);
499+
if (index >= 0) {
500+
// Sets active key index
501+
ws_pae_auth_network_key_index_set(pae_auth, index);
502+
}
503+
504+
return 0;
505+
}
506+
507+
458508
static int8_t ws_pae_auth_network_keys_from_gtks_set(pae_auth_t *pae_auth)
459509
{
460510
// Authenticator keys are always fresh

source/6LoWPAN/ws/ws_pae_auth.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ int8_t ws_pae_auth_node_limit_set(protocol_interface_info_entry_t *interface_ptr
168168
*/
169169
void ws_pae_auth_forced_gc(protocol_interface_info_entry_t *interface_ptr);
170170

171+
/**
172+
* ws_pae_auth_nw_info_set set network information
173+
*
174+
* \param interface_ptr interface
175+
* \param pan_id PAD ID
176+
* \param network_name network name
177+
*
178+
*/
179+
int8_t ws_pae_auth_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name);
180+
171181
/**
172182
* ws_pae_auth_gtk_hash_set GTK hash set callback
173183
*
@@ -189,6 +199,14 @@ typedef void ws_pae_auth_gtk_hash_set(protocol_interface_info_entry_t *interface
189199
*/
190200
typedef int8_t ws_pae_auth_nw_key_insert(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks);
191201

202+
/**
203+
* ws_pae_auth_nw_keys_remove remove network keys callback
204+
*
205+
* \param interface_ptr interface
206+
*
207+
*/
208+
typedef void ws_pae_auth_nw_keys_remove(protocol_interface_info_entry_t *interface_ptr);
209+
192210
/**
193211
* ws_pae_auth_nw_key_index_set network send key index set callback
194212
*
@@ -205,20 +223,22 @@ typedef void ws_pae_auth_nw_key_index_set(protocol_interface_info_entry_t *inter
205223
* \param hash_set GTK hash set callback
206224
* \param nw_key_insert network key index callback
207225
* \param nw_key_index_set network send key index callback
226+
* \param nw_keys_remove network keys remove callback
208227
*
209228
*/
210-
void ws_pae_auth_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_pae_auth_gtk_hash_set *hash_set, ws_pae_auth_nw_key_insert *nw_key_insert, ws_pae_auth_nw_key_index_set *nw_key_index_set);
229+
void ws_pae_auth_cb_register(protocol_interface_info_entry_t *interface_ptr, ws_pae_auth_gtk_hash_set *hash_set, ws_pae_auth_nw_key_insert *nw_key_insert, ws_pae_auth_nw_key_index_set *nw_key_index_set, ws_pae_auth_nw_keys_remove *nw_keys_remove);
211230

212231
#else
213232

214233
#define ws_pae_auth_init(interface_ptr, gtks, next_gtks, certs, sec_timer_cfg, sec_prot_cfg) 1
215234
#define ws_pae_auth_timing_adjust(timing)
216235
#define ws_pae_auth_addresses_set(interface_ptr, local_port, remote_addr, remote_port) 1
217236
#define ws_pae_auth_delete NULL
218-
#define ws_pae_auth_cb_register(interface_ptr, hash_set, nw_key_insert, nw_key_index_set) {(void) hash_set;}
237+
#define ws_pae_auth_cb_register(interface_ptr, hash_set, nw_key_insert, nw_key_index_set, nw_keys_remove) {(void) hash_set;}
219238
#define ws_pae_auth_start(interface_ptr)
220239
#define ws_pae_auth_gtks_updated NULL
221240
#define ws_pae_auth_nw_key_index_update NULL
241+
#define ws_pae_auth_nw_info_set NULL
222242
#define ws_pae_auth_node_keys_remove(interface_ptr, eui64) -1
223243
#define ws_pae_auth_node_access_revoke_start(interface_ptr)
224244
#define ws_pae_auth_node_limit_set(interface_ptr, limit)

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef int8_t ws_pae_br_addr_read(protocol_interface_info_entry_t *interface_pt
4949
typedef void ws_pae_gtks_updated(protocol_interface_info_entry_t *interface_ptr);
5050
typedef int8_t ws_pae_gtk_hash_update(protocol_interface_info_entry_t *interface_ptr, uint8_t *gtkhash);
5151
typedef int8_t ws_pae_nw_key_index_update(protocol_interface_info_entry_t *interface_ptr, uint8_t index);
52+
typedef int8_t ws_pae_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name);
5253

5354
typedef struct {
5455
uint8_t gtk[GTK_LEN]; /**< GTK key */
@@ -88,6 +89,7 @@ typedef struct {
8889
ws_pae_gtks_updated *pae_gtks_updated; /**< PAE GTKs updated */
8990
ws_pae_gtk_hash_update *pae_gtk_hash_update; /**< PAE GTK HASH update */
9091
ws_pae_nw_key_index_update *pae_nw_key_index_update; /**< PAE NW key index update */
92+
ws_pae_nw_info_set *pae_nw_info_set; /**< PAE security key network info set */
9193
nvm_tlv_entry_t *pae_nvm_buffer; /**< Buffer For PAE NVM write operation*/
9294
bool gtks_set : 1; /**< GTKs are set */
9395
bool gtkhash_set : 1; /**< GTK hashes are set */
@@ -238,7 +240,7 @@ int8_t ws_pae_controller_authenticator_start(protocol_interface_info_entry_t *in
238240
ws_pae_auth_node_limit_set(controller->interface_ptr, pae_controller_config.node_limit);
239241
}
240242

241-
ws_pae_auth_cb_register(interface_ptr, ws_pae_controller_gtk_hash_set, ws_pae_controller_nw_key_check_and_insert, ws_pae_controller_nw_key_index_check_and_set);
243+
ws_pae_auth_cb_register(interface_ptr, ws_pae_controller_gtk_hash_set, ws_pae_controller_nw_key_check_and_insert, ws_pae_controller_nw_key_index_check_and_set, ws_pae_controller_nw_keys_remove);
242244

243245
ws_pae_auth_start(interface_ptr);
244246

@@ -300,7 +302,11 @@ int8_t ws_pae_controller_nw_info_set(protocol_interface_info_entry_t *interface_
300302

301303
controller->network_name = network_name;
302304

303-
return ws_pae_supp_nw_info_set(interface_ptr, pan_id, network_name);
305+
if (controller->pae_nw_info_set) {
306+
controller->pae_nw_info_set(interface_ptr, pan_id, network_name);
307+
}
308+
309+
return 0; ;
304310
}
305311

306312
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr)
@@ -707,6 +713,7 @@ int8_t ws_pae_controller_supp_init(protocol_interface_info_entry_t *interface_pt
707713
controller->pae_br_addr_read = ws_pae_supp_border_router_addr_read;
708714
controller->pae_gtk_hash_update = ws_pae_supp_gtk_hash_update;
709715
controller->pae_nw_key_index_update = ws_pae_supp_nw_key_index_update;
716+
controller->pae_nw_info_set = ws_pae_supp_nw_info_set;
710717

711718
ws_pae_supp_cb_register(controller->interface_ptr, controller->auth_completed, ws_pae_controller_nw_key_check_and_insert, ws_pae_controller_active_nw_key_set, ws_pae_controller_gtk_hash_ptr_get);
712719

@@ -731,6 +738,7 @@ int8_t ws_pae_controller_auth_init(protocol_interface_info_entry_t *interface_pt
731738
controller->pae_slow_timer = ws_pae_auth_slow_timer;
732739
controller->pae_gtks_updated = ws_pae_auth_gtks_updated;
733740
controller->pae_nw_key_index_update = ws_pae_auth_nw_key_index_update;
741+
controller->pae_nw_info_set = ws_pae_auth_nw_info_set;
734742

735743
ws_pae_controller_frame_counter_read(controller);
736744

0 commit comments

Comments
 (0)