Skip to content

Commit 87a4f69

Browse files
author
Mika Leppänen
authored
Added EAPOL key storage to authenticator and unified GTK storage (#2345)
Added EAPOL key storage to authenticator: - Application can give the memory areas and their sizes to Nanostack - If application does not define specific areas, memory is allocated from heap as needed - Memory key storage has identical structure to the one stored/read from NVM i.e. the file - When supplicant goes inactive it's security data is stored onto array on memory - On memory key storage array - Lifetimes are converted to time stamps - Time stamps are calculated as difference to the reference time of the heap array - Reference time is set when memory array is created (from system time) and updated in maximum once a day on a NVM write or after 31 days if no other NVM writes - PMK security key counters are stored to array, but not written to NVM if no other need to write - Uniqueness of the PMK security key counters is achieved by including re-start counter to PMK counter on NVM read i.e. startup. - Limit for simultaneously authenticating supplicants is 200 - Key data on NVM needs to be updated when new supplicants appear and they are authenticated, they are removed via access revoke, GKTs are updated, or PMK or PTK keys need to be re-negotiated or heap array reference time is updated after 31 days Added PAE time module: - If system real time clock is available application can set its callback - If there is no clock from application, authenticator maintains rough system clock by incrementing time when running, and storing/reading it to/from NVM when frame counters are read/stored Unified GTK storage between supplicant and authenticator and moved it to PAE controller
1 parent ff1ca25 commit 87a4f69

28 files changed

+2656
-380
lines changed

nanostack/ns_time_api.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2020, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* \file ns_time_api.h
20+
* \brief Nanostack time API
21+
*
22+
* This is Nanostack time API.
23+
*
24+
*/
25+
26+
#ifndef NS_TIME_API_H_
27+
#define NS_TIME_API_H_
28+
29+
#include "ns_types.h"
30+
31+
/**
32+
* System time callback.
33+
*
34+
* Callback shall return the system time in seconds after 1970.
35+
*
36+
* \param seconds system time in seconds
37+
*
38+
*/
39+
typedef uint64_t ns_time_api_system_time_callback(void);
40+
41+
/**
42+
* System time callback set.
43+
*
44+
* Sets callback for the system time.
45+
*
46+
* \param callback system time callback
47+
*
48+
*/
49+
void ns_time_api_system_time_callback_set(ns_time_api_system_time_callback callback);
50+
51+
#endif /* NS_TIME_API_H_ */

nanostack/ws_bbr_api.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,40 @@ int ws_bbr_pan_configuration_get(int8_t interface_id, uint16_t *pan_id);
243243
*/
244244
int ws_bbr_pan_configuration_validate(int8_t interface_id, uint16_t pan_id);
245245

246+
/**
247+
* ws_bbr_key_storage_memory_set sets memory used for key storages
248+
*
249+
* This functions can be used to set memory used by EAPOL key storage. When memory
250+
* areas are set, module does not allocate memory internally from heap.
251+
*
252+
* \param interface_id Network interface ID.
253+
* \param key_storages_number number of memory areas.
254+
* \param key_storage_size array of memory area sizes.
255+
* \param key_storages array of memory area start pointers.
256+
*
257+
* \return < 0 failure
258+
* \return >= 0 success
259+
*
260+
*/
261+
int ws_bbr_key_storage_memory_set(int8_t interface_id, uint8_t key_storages_number, const uint16_t *key_storage_size, void **key_storages);
262+
263+
/**
264+
* ws_bbr_key_storage_settings_set sets key storage settings
265+
*
266+
* This functions can be used to set the settings of EAPOL key storage.
267+
* Allocation max number and allocation size sets the settings that are used when key storage
268+
* memory is allocated dynamically from heap. These settings must be set before (first) interface
269+
* up and shall not be set if key storage memory is set by ws_pae_key_storage_memory_set() call.
270+
*
271+
* \param interface_id Network interface ID.
272+
* \param alloc_max_number maximum number of allocation made to dynamic memory.
273+
* \param alloc_size size of each allocation.
274+
* \param storing_interval interval in which the check to store to NVM is made.
275+
*
276+
* \return < 0 failure
277+
* \return >= 0 success
278+
*
279+
*/
280+
int ws_bbr_key_storage_settings_set(int8_t interface_id, uint8_t alloc_max_number, uint16_t alloc_size, uint16_t storing_interval);
281+
246282
#endif /* WS_BBR_API_H_ */

source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "6LoWPAN/ws/ws_common.h"
2929
#include "6LoWPAN/ws/ws_bootstrap.h"
3030
#include "6LoWPAN/ws/ws_cfg_settings.h"
31+
#include "6LoWPAN/ws/ws_pae_key_storage.h"
3132
#include "RPL/rpl_control.h"
3233
#include "RPL/rpl_data.h"
3334
#include "Common_Protocols/icmpv6.h"
@@ -943,3 +944,29 @@ int ws_bbr_pan_configuration_validate(int8_t interface_id, uint16_t pan_id)
943944
return -1;
944945
#endif
945946
}
947+
948+
int ws_bbr_key_storage_memory_set(int8_t interface_id, uint8_t key_storages_number, const uint16_t *key_storage_size, void **key_storages)
949+
{
950+
(void) interface_id;
951+
#ifdef HAVE_WS_BORDER_ROUTER
952+
return ws_pae_key_storage_memory_set(key_storages_number, key_storage_size, key_storages);
953+
#else
954+
(void) key_storages_number;
955+
(void) key_storage_size;
956+
(void) key_storages;
957+
return -1;
958+
#endif
959+
}
960+
961+
int ws_bbr_key_storage_settings_set(int8_t interface_id, uint8_t alloc_max_number, uint16_t alloc_size, uint16_t storing_interval)
962+
{
963+
(void) interface_id;
964+
#ifdef HAVE_WS_BORDER_ROUTER
965+
return ws_pae_key_storage_settings_set(alloc_max_number, alloc_size, storing_interval);
966+
#else
967+
(void) alloc_max_number;
968+
(void) alloc_size;
969+
(void) storing_interval;
970+
return -1;
971+
#endif
972+
}

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static void ws_bootstrap_nw_key_clear(protocol_interface_info_entry_t *cur, uint
9595
static void ws_bootstrap_nw_key_index_set(protocol_interface_info_entry_t *cur, uint8_t index);
9696
static void ws_bootstrap_nw_frame_counter_set(protocol_interface_info_entry_t *cur, uint32_t counter, uint8_t slot);
9797
static void ws_bootstrap_nw_frame_counter_read(protocol_interface_info_entry_t *cur, uint32_t *counter, uint8_t slot);
98+
static void ws_bootstrap_nw_info_updated(protocol_interface_info_entry_t *interface_ptr, uint16_t pan_id, char *network_name);
9899
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, auth_result_e result, uint8_t *target_eui_64);
99100
static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t *cur);
100101
static ws_nud_table_entry_t *ws_nud_entry_discover(protocol_interface_info_entry_t *cur, void *neighbor);
@@ -1985,7 +1986,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
19851986
ret_val = -4;
19861987
goto init_fail;
19871988
}
1988-
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_nw_key_set, &ws_bootstrap_nw_key_clear, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_nw_frame_counter_set, &ws_bootstrap_nw_frame_counter_read, &ws_bootstrap_pan_version_increment) < 0) {
1989+
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_nw_key_set, &ws_bootstrap_nw_key_clear, &ws_bootstrap_nw_key_index_set, &ws_bootstrap_nw_frame_counter_set, &ws_bootstrap_nw_frame_counter_read, &ws_bootstrap_pan_version_increment, &ws_bootstrap_nw_info_updated) < 0) {
19891990
ret_val = -4;
19901991
goto init_fail;
19911992
}
@@ -2693,6 +2694,32 @@ static void ws_bootstrap_nw_frame_counter_read(protocol_interface_info_entry_t *
26932694
mac_helper_key_link_frame_counter_read(cur->id, counter, slot);
26942695
}
26952696

2697+
static void ws_bootstrap_nw_info_updated(protocol_interface_info_entry_t *cur, uint16_t pan_id, char *network_name)
2698+
{
2699+
/* For border router, the PAE controller reads pan_id and network name from storage.
2700+
* If they are set, takes them into use here.
2701+
*/
2702+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
2703+
// Get pad_id and network name
2704+
ws_gen_cfg_t gen_cfg;
2705+
if (ws_cfg_gen_get(&gen_cfg, NULL) < 0) {
2706+
return;
2707+
}
2708+
2709+
// If pan_id has not been set, set it
2710+
if (gen_cfg.network_pan_id == 0xffff) {
2711+
gen_cfg.network_pan_id = pan_id;
2712+
}
2713+
// If network name has not been set, set it
2714+
if (strlen(gen_cfg.network_name) == 0) {
2715+
strncpy(gen_cfg.network_name, network_name, 32);
2716+
}
2717+
2718+
// Stores the settings
2719+
ws_cfg_gen_set(cur, NULL, &gen_cfg, 0);
2720+
}
2721+
}
2722+
26962723
static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_t *cur, auth_result_e result, uint8_t *target_eui_64)
26972724
{
26982725
(void) target_eui_64;

0 commit comments

Comments
 (0)