Skip to content

Commit 52e4c3f

Browse files
author
Mika Leppänen
committed
Added supplicant PAE NVM storage
Stores and reads network related info (PAN ID, network name, GTKs) and key information (PMK, PMK replay counter, PTK and BR EUI-64 used to derive PTK) to/from file system. Added PTK (PTKID) and PMK (PMKID) hashes to initial EAPOL-Key send by the supplicant.
1 parent 92df57b commit 52e4c3f

21 files changed

+1325
-71
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,10 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
16961696
tr_debug("Start EAPOL relay");
16971697
// Set both own port and border router port to 10253
16981698
ws_eapol_relay_start(cur, EAPOL_RELAY_SOCKET_PORT, dodag_info.dodag_id, EAPOL_RELAY_SOCKET_PORT);
1699+
// Set network information to PAE
1700+
ws_pae_controller_nw_info_set(cur, cur->ws_info->network_pan_id, cur->ws_info->network_name);
1701+
// Network key is valid
1702+
ws_pae_controller_nw_key_valid(cur);
16991703
}
17001704

17011705
ws_set_fhss_hop(cur);
@@ -2144,6 +2148,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
21442148

21452149
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
21462150
tr_debug("Border router start network");
2151+
ws_pae_controller_auth_init(cur);
2152+
21472153
// Randomize fixed channels. Only used if channel plan is fixed.
21482154
cur->ws_info->fhss_uc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_uc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
21492155
cur->ws_info->fhss_bc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_bc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
@@ -2178,6 +2184,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
21782184
ws_pae_controller_authenticator_start(cur, PAE_AUTH_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);
21792185
break;
21802186
}
2187+
ws_pae_controller_supp_init(cur);
2188+
21812189
// Configure LLC for network discovery
21822190
ws_bootstrap_network_discovery_configure(cur);
21832191
ws_bootstrap_fhss_activate(cur);
@@ -2282,7 +2290,7 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
22822290
ws_bootstrap_network_information_learn(cur);
22832291
ws_bootstrap_fhss_activate(cur);
22842292

2285-
ws_pae_controller_set_target(cur, cur->ws_info->parent_info.addr); // temporary!!! store since auth
2293+
ws_pae_controller_set_target(cur, cur->ws_info->parent_info.pan_id, cur->ws_info->parent_info.addr); // temporary!!! store since auth
22862294
ws_bootstrap_event_authentication_start(cur);
22872295
return;
22882296
}

source/6LoWPAN/ws/ws_pae_auth.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ static void ws_pae_auth_kmp_api_finished(kmp_api_t *kmp);
8888
static int8_t tasklet_id = -1;
8989
static NS_LIST_DEFINE(pae_auth_list, pae_auth_t, link);
9090

91-
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port, sec_prot_gtk_keys_t *gtks, const sec_prot_certs_t *certs)
91+
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks, const sec_prot_certs_t *certs)
9292
{
93-
if (!interface_ptr || !remote_addr || !gtks) {
93+
if (!interface_ptr || !gtks || !certs) {
9494
return -1;
9595
}
9696

@@ -128,10 +128,6 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
128128
goto error;
129129
}
130130

131-
if (kmp_socket_if_register(pae_auth->kmp_service, local_port, remote_addr, remote_port) < 0) {
132-
goto error;
133-
}
134-
135131
if (key_sec_prot_register(pae_auth->kmp_service) < 0) {
136132
goto error;
137133
}
@@ -173,6 +169,27 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
173169
return -1;
174170
}
175171

172+
int8_t ws_pae_auth_addresses_set(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port)
173+
{
174+
if (!interface_ptr || !remote_addr) {
175+
return -1;
176+
}
177+
178+
pae_auth_t *pae_auth = ws_pae_auth_get(interface_ptr);
179+
if (!pae_auth) {
180+
return -1;
181+
}
182+
if (!pae_auth->kmp_service) {
183+
return -1;
184+
}
185+
186+
if (kmp_socket_if_register(pae_auth->kmp_service, local_port, remote_addr, remote_port) < 0) {
187+
return -1;
188+
}
189+
190+
return 0;
191+
}
192+
176193
int8_t ws_pae_auth_delete(protocol_interface_info_entry_t *interface_ptr)
177194
{
178195
if (!interface_ptr) {

source/6LoWPAN/ws/ws_pae_auth.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,21 @@
5050
* \return >= 0 success
5151
*
5252
*/
53-
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port, sec_prot_gtk_keys_t *gtks, const sec_prot_certs_t *certs);
53+
int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, sec_prot_gtk_keys_t *gtks, const sec_prot_certs_t *certs);
54+
55+
/**
56+
* ws_pae_auth_addresses_set set relay addresses
57+
*
58+
* \param interface_ptr interface
59+
* \param local_port local port
60+
* \param remote_addr remote address
61+
* \param remote_port remote port
62+
*
63+
* \return < 0 failure
64+
* \return >= 0 success
65+
*
66+
*/
67+
int8_t ws_pae_auth_addresses_set(protocol_interface_info_entry_t *interface_ptr, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port);
5468

5569
/**
5670
* ws_pae_auth_delete deletes PAE authenticator
@@ -73,7 +87,8 @@ void ws_pae_auth_timer(uint16_t ticks);
7387

7488
#else
7589

76-
#define ws_pae_auth_init(interface_ptr, local_port, remote_addr, remote_port, gtks, certs) 1
90+
#define ws_pae_auth_init(interface_ptr, gtks, certs) 1
91+
#define ws_pae_auth_addresses_set(interface_ptr, local_port, remote_addr, remote_port) 1
7792
#define ws_pae_auth_delete NULL
7893
#define ws_pae_auth_timer NULL
7994

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 111 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737

3838
typedef int8_t ws_pae_delete(protocol_interface_info_entry_t *interface_ptr);
3939
typedef void ws_pae_timer(uint16_t ticks);
40+
typedef int8_t ws_pae_br_addr_write(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64);
41+
typedef int8_t ws_pae_br_addr_read(protocol_interface_info_entry_t *interface_ptr, uint8_t *eui_64);
42+
4043

4144
typedef struct {
4245
ns_list_link_t link; /**< Link */
4346
uint8_t target_eui_64[8]; /**< EAPOL target */
47+
uint16_t target_pan_id; /**< EAPOL target PAN ID */
4448
uint8_t br_eui_64[8]; /**< Border router EUI-64 */
4549
sec_prot_gtk_keys_t gtks; /**< GTKs */
4650
sec_prot_certs_t certs; /**< Certificates */
@@ -49,6 +53,8 @@ typedef struct {
4953
ws_pae_controller_key_insert *key_insert; /**< Key insert callback */
5054
ws_pae_delete *pae_delete; /**< PAE delete callback */
5155
ws_pae_timer *pae_timer; /**< PAE timer callback */
56+
ws_pae_br_addr_write *pae_br_addr_write; /**< PAE Border router EUI-64 write callback */
57+
ws_pae_br_addr_read *pae_br_addr_read; /**< PAE Border router EUI-64 read callback */
5258
} pae_controller_t;
5359

5460
static void ws_pae_controller_test_keys_set(sec_prot_gtk_keys_t *gtks);
@@ -85,16 +91,7 @@ int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface
8591
return -1;
8692
}
8793

88-
if (ws_pae_supp_init(controller->interface_ptr, &controller->certs) < 0) {
89-
return -1;
90-
}
91-
92-
controller->pae_delete = ws_pae_supp_delete;
93-
controller->pae_timer = ws_pae_supp_timer;
94-
95-
ws_pae_supp_cb_register(controller->interface_ptr, controller->auth_completed, controller->key_insert);
96-
97-
if (ws_pae_supp_authenticate(controller->interface_ptr, controller->target_eui_64) > 0) {
94+
if (ws_pae_supp_authenticate(controller->interface_ptr, controller->target_pan_id, controller->target_eui_64) == PAE_SUPP_NOT_ENABLED) {
9895
// Already authenticated
9996
ws_pae_controller_test_keys_set(&controller->gtks);
10097

@@ -105,6 +102,14 @@ int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface
105102
controller->auth_completed(interface_ptr, true);
106103
}
107104

105+
///////////
106+
// For now fixed since not yet support for EA-IE
107+
const uint8_t addr[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
108+
if (controller->pae_br_addr_write) {
109+
controller->pae_br_addr_write(interface_ptr, addr);
110+
}
111+
////////////////
112+
108113
return 0;
109114
}
110115

@@ -124,18 +129,15 @@ int8_t ws_pae_controller_authenticator_start(protocol_interface_info_entry_t *in
124129

125130
ws_pae_controller_test_keys_set(&controller->gtks);
126131

127-
if (ws_pae_auth_init(controller->interface_ptr, local_port, remote_addr, remote_port, &controller->gtks, &controller->certs) < 0) {
128-
return -1;
129-
}
130-
131-
controller->pae_delete = ws_pae_auth_delete;
132-
controller->pae_timer = ws_pae_auth_timer;
133-
134132
uint8_t index;
135133
uint8_t *gtk = sec_prot_keys_get_gtk_to_insert(&controller->gtks, &index);
136134

137135
controller->key_insert(controller->interface_ptr, index, gtk);
138136

137+
if (ws_pae_auth_addresses_set(interface_ptr, local_port, remote_addr, remote_port) < 0) {
138+
return -1;
139+
}
140+
139141
return 0;
140142
}
141143

@@ -156,7 +158,7 @@ int8_t ws_pae_controller_cb_register(protocol_interface_info_entry_t *interface_
156158
return 0;
157159
}
158160

159-
int8_t ws_pae_controller_set_target(protocol_interface_info_entry_t *interface_ptr, uint8_t *dest_eui_64)
161+
int8_t ws_pae_controller_set_target(protocol_interface_info_entry_t *interface_ptr, uint16_t target_pan_id, uint8_t *target_eui_64)
160162
{
161163
if (!interface_ptr) {
162164
return -1;
@@ -167,11 +169,43 @@ int8_t ws_pae_controller_set_target(protocol_interface_info_entry_t *interface_p
167169
return -1;
168170
}
169171

170-
memcpy(controller->target_eui_64, dest_eui_64, 8);
172+
controller->target_pan_id = target_pan_id;
173+
memcpy(controller->target_eui_64, target_eui_64, 8);
171174

172175
return 0;
173176
}
174177

178+
int8_t ws_pae_controller_nw_info_set(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name)
179+
{
180+
(void) pan_id;
181+
(void) network_name;
182+
183+
if (!interface_ptr) {
184+
return -1;
185+
}
186+
187+
pae_controller_t *controller = ws_pae_controller_get(interface_ptr);
188+
if (!controller) {
189+
return -1;
190+
}
191+
192+
return ws_pae_supp_nw_info_set(interface_ptr, pan_id, network_name);
193+
}
194+
195+
int8_t ws_pae_controller_nw_key_valid(protocol_interface_info_entry_t *interface_ptr)
196+
{
197+
if (!interface_ptr) {
198+
return -1;
199+
}
200+
201+
pae_controller_t *controller = ws_pae_controller_get(interface_ptr);
202+
if (!controller) {
203+
return -1;
204+
}
205+
206+
return ws_pae_supp_nw_key_valid(interface_ptr);
207+
}
208+
175209
int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr)
176210
{
177211
if (!interface_ptr) {
@@ -194,6 +228,8 @@ int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr)
194228
controller->key_insert = NULL;
195229
controller->pae_delete = NULL;
196230
controller->pae_timer = NULL;
231+
controller->pae_br_addr_write = NULL;
232+
controller->pae_br_addr_read = NULL;
197233

198234
sec_prot_keys_gtks_init(&controller->gtks);
199235
sec_prot_certs_init(&controller->certs);
@@ -203,6 +239,51 @@ int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr)
203239
return 0;
204240
}
205241

242+
int8_t ws_pae_controller_supp_init(protocol_interface_info_entry_t *interface_ptr)
243+
{
244+
if (!interface_ptr) {
245+
return -1;
246+
}
247+
248+
pae_controller_t *controller = ws_pae_controller_get(interface_ptr);
249+
if (!controller) {
250+
return -1;
251+
}
252+
253+
if (ws_pae_supp_init(controller->interface_ptr, &controller->certs) < 0) {
254+
return -1;
255+
}
256+
257+
controller->pae_delete = ws_pae_supp_delete;
258+
controller->pae_timer = ws_pae_supp_timer;
259+
controller->pae_br_addr_write = ws_pae_supp_border_router_addr_write;
260+
controller->pae_br_addr_read = ws_pae_supp_border_router_addr_read;
261+
262+
ws_pae_supp_cb_register(controller->interface_ptr, controller->auth_completed, controller->key_insert);
263+
264+
return 0;
265+
}
266+
267+
int8_t ws_pae_controller_auth_init(protocol_interface_info_entry_t *interface_ptr)
268+
{
269+
if (!interface_ptr) {
270+
return -1;
271+
}
272+
273+
pae_controller_t *controller = ws_pae_controller_get(interface_ptr);
274+
if (!controller) {
275+
return -1;
276+
}
277+
278+
if (ws_pae_auth_init(controller->interface_ptr, &controller->gtks, &controller->certs) < 0) {
279+
return -1;
280+
}
281+
282+
controller->pae_delete = ws_pae_auth_delete;
283+
controller->pae_timer = ws_pae_auth_timer;
284+
285+
return 0;
286+
}
206287
int8_t ws_pae_controller_stop(protocol_interface_info_entry_t *interface_ptr)
207288
{
208289
if (!interface_ptr) {
@@ -266,7 +347,7 @@ int8_t ws_pae_controller_certificate_chain_set(const arm_certificate_chain_entry
266347
return 0;
267348
}
268349

269-
int8_t ws_pae_controller_border_router_addr_write(protocol_interface_info_entry_t *interface_ptr, uint8_t *eui_64)
350+
int8_t ws_pae_controller_border_router_addr_write(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64)
270351
{
271352
if (!interface_ptr || !eui_64) {
272353
return -1;
@@ -277,7 +358,11 @@ int8_t ws_pae_controller_border_router_addr_write(protocol_interface_info_entry_
277358
return -1;
278359
}
279360

280-
memcpy(controller->br_eui_64, eui_64, 8);
361+
if (controller->pae_br_addr_write) {
362+
return controller->pae_br_addr_write(interface_ptr, eui_64);
363+
} else {
364+
memcpy(controller->br_eui_64, eui_64, 8);
365+
}
281366

282367
return 0;
283368

@@ -294,7 +379,11 @@ int8_t ws_pae_controller_border_router_addr_read(protocol_interface_info_entry_t
294379
return -1;
295380
}
296381

297-
memcpy(eui_64, controller->br_eui_64, 8);
382+
if (controller->pae_br_addr_read) {
383+
return controller->pae_br_addr_read(interface_ptr, eui_64);
384+
} else {
385+
memcpy(eui_64, controller->br_eui_64, 8);
386+
}
298387

299388
return 0;
300389
}

0 commit comments

Comments
 (0)