Skip to content

Commit 88641c1

Browse files
author
Mika Leppänen
committed
Updates to PAEs and other security protocols
Added certificate interface to PAE controller. TLS security protocol is now created on PAEs when EAP-TLS is created. Added inclusion of certificate interface header to modules.
1 parent f57138f commit 88641c1

File tree

18 files changed

+252
-60
lines changed

18 files changed

+252
-60
lines changed

source/6LoWPAN/ws/ws_pae_auth.c

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
#include "Security/kmp/kmp_addr.h"
3232
#include "Security/kmp/kmp_api.h"
3333
#include "Security/kmp/kmp_socket_if.h"
34+
#include "Security/protocols/sec_prot_certs.h"
3435
#include "Security/protocols/sec_prot_keys.h"
3536
#include "Security/protocols/key_sec_prot/key_sec_prot.h"
36-
#include "Security/protocols/eap_tls_sec_prot/eap_tls_sec_prot.h"
37+
#include "Security/protocols/eap_tls_sec_prot/auth_eap_tls_sec_prot.h"
38+
#include "Security/protocols/tls_sec_prot/tls_sec_prot.h"
3739
#include "Security/protocols/fwh_sec_prot/auth_fwh_sec_prot.h"
3840
#include "Security/protocols/gkh_sec_prot/auth_gkh_sec_prot.h"
3941
#include "6LoWPAN/ws/ws_pae_controller.h"
@@ -60,6 +62,7 @@ typedef struct {
6062
supp_list_t inactive_supp_list; /**< List of inactive supplicants */
6163
arm_event_storage_t *timer; /**< Timer */
6264
sec_prot_gtk_keys_t *gtks; /**< GTKs */
65+
const sec_prot_certs_t *certs; /**< Certificates */
6366
bool timer_running; /**< Timer is running */
6467
} pae_auth_t;
6568

@@ -74,16 +77,18 @@ static int8_t ws_pae_auth_timer_start(pae_auth_t *pae_auth);
7477
static int8_t ws_pae_auth_timer_stop(pae_auth_t *pae_auth);
7578
static bool ws_pae_auth_timer_running(pae_auth_t *pae_auth);
7679
static void ws_pae_auth_kmp_service_addr_get(kmp_service_t *service, kmp_api_t *kmp, kmp_addr_t *local_addr, kmp_addr_t *remote_addr);
80+
static kmp_api_t *ws_pae_auth_kmp_service_api_get(kmp_service_t *service, kmp_api_t *kmp, kmp_type_e type);
7781
static kmp_api_t *ws_pae_auth_kmp_incoming_ind(kmp_service_t *service, kmp_type_e type, const kmp_addr_t *addr);
7882
static void ws_pae_auth_kmp_api_create_confirm(kmp_api_t *kmp, kmp_result_e result);
7983
static void ws_pae_auth_kmp_api_create_indication(kmp_api_t *kmp, kmp_type_e type, kmp_addr_t *addr);
8084
static void ws_pae_auth_kmp_api_finished_indication(kmp_api_t *kmp, kmp_result_e result, kmp_sec_keys_t *sec_keys);
85+
static kmp_api_t *ws_pae_auth_kmp_create_and_start(kmp_service_t *service, kmp_type_e type, supp_entry_t *supp_entry);
8186
static void ws_pae_auth_kmp_api_finished(kmp_api_t *kmp);
8287

8388
static int8_t tasklet_id = -1;
8489
static NS_LIST_DEFINE(pae_auth_list, pae_auth_t, link);
8590

86-
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)
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)
8792
{
8893
if (!interface_ptr || !remote_addr || !gtks) {
8994
return -1;
@@ -104,13 +109,14 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
104109
pae_auth->timer = NULL;
105110

106111
pae_auth->gtks = gtks;
112+
pae_auth->certs = certs;
107113

108114
pae_auth->kmp_service = kmp_service_create();
109115
if (!pae_auth->kmp_service) {
110116
goto error;
111117
}
112118

113-
if (kmp_service_cb_register(pae_auth->kmp_service, ws_pae_auth_kmp_incoming_ind, ws_pae_auth_kmp_service_addr_get)) {
119+
if (kmp_service_cb_register(pae_auth->kmp_service, ws_pae_auth_kmp_incoming_ind, ws_pae_auth_kmp_service_addr_get, ws_pae_auth_kmp_service_api_get)) {
114120
goto error;
115121
}
116122

@@ -130,7 +136,11 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
130136
goto error;
131137
}
132138

133-
if (eap_tls_auth_sec_prot_register(pae_auth->kmp_service) < 0) {
139+
if (auth_eap_tls_sec_prot_register(pae_auth->kmp_service) < 0) {
140+
goto error;
141+
}
142+
143+
if (server_tls_sec_prot_register(pae_auth->kmp_service) < 0) {
134144
goto error;
135145
}
136146

@@ -357,6 +367,18 @@ static void ws_pae_auth_kmp_service_addr_get(kmp_service_t *service, kmp_api_t *
357367
}
358368
}
359369

370+
static kmp_api_t *ws_pae_auth_kmp_service_api_get(kmp_service_t *service, kmp_api_t *kmp, kmp_type_e type)
371+
{
372+
(void) service;
373+
374+
supp_entry_t *supp_entry = kmp_api_data_get(kmp);
375+
if (!supp_entry) {
376+
return NULL;
377+
}
378+
379+
return ws_pae_lib_kmp_list_type_get(&supp_entry->kmp_list, type);
380+
}
381+
360382
static kmp_api_t *ws_pae_auth_kmp_incoming_ind(kmp_service_t *service, kmp_type_e type, const kmp_addr_t *addr)
361383
{
362384
pae_auth_t *pae_auth = ws_pae_auth_by_kmp_service_get(service);
@@ -382,7 +404,7 @@ static kmp_api_t *ws_pae_auth_kmp_incoming_ind(kmp_service_t *service, kmp_type_
382404
if (!supp_entry) {
383405
return 0;
384406
}
385-
sec_prot_keys_init(&supp_entry->sec_keys, pae_auth->gtks);
407+
sec_prot_keys_init(&supp_entry->sec_keys, pae_auth->gtks, pae_auth->certs);
386408
} else {
387409
// Updates relay address
388410
kmp_address_copy(supp_entry->addr, addr);
@@ -494,31 +516,57 @@ static void ws_pae_auth_kmp_api_finished_indication(kmp_api_t *kmp, kmp_result_e
494516
return;
495517
}
496518

497-
// Create KMP instance for new authentication
498-
kmp_api_t *new_kmp = kmp_api_create(pae_auth->kmp_service, type);
499-
kmp_api_data_set(new_kmp, supp_entry);
500-
519+
// Create new instance
520+
kmp_api_t *new_kmp = ws_pae_auth_kmp_create_and_start(pae_auth->kmp_service, type, supp_entry);
501521
if (!new_kmp) {
502522
return;
503523
}
504524

505-
if (ws_pae_lib_kmp_list_add(&supp_entry->kmp_list, new_kmp) == NULL) {
506-
kmp_api_delete(new_kmp);
507-
return;
525+
// For EAP-TLS create also TLS in addition to EAP-TLS
526+
if (type == IEEE_802_1X_MKA) {
527+
if (ws_pae_lib_kmp_list_type_get(&supp_entry->kmp_list, TLS_PROT) != NULL) {
528+
// TLS already exists, wait for it to be deleted
529+
ws_pae_lib_kmp_list_delete(&supp_entry->kmp_list, new_kmp);
530+
return;
531+
}
532+
// Create TLS instance */
533+
if (ws_pae_auth_kmp_create_and_start(service, TLS_PROT, supp_entry) == NULL) {
534+
ws_pae_lib_kmp_list_delete(&supp_entry->kmp_list, new_kmp);
535+
return;
536+
}
508537
}
509538

510-
kmp_api_cb_register(new_kmp,
511-
ws_pae_auth_kmp_api_create_confirm,
512-
ws_pae_auth_kmp_api_create_indication,
513-
ws_pae_auth_kmp_api_finished_indication,
514-
ws_pae_auth_kmp_api_finished);
539+
kmp_api_create_request(new_kmp, type, supp_entry->addr, &supp_entry->sec_keys);
540+
}
515541

516-
if (kmp_api_start(new_kmp) < 0) {
517-
ws_pae_lib_kmp_list_delete(&supp_entry->kmp_list, new_kmp);
518-
return;
542+
static kmp_api_t *ws_pae_auth_kmp_create_and_start(kmp_service_t *service, kmp_type_e type, supp_entry_t *supp_entry)
543+
{
544+
// Create KMP instance for new authentication
545+
kmp_api_t *kmp = kmp_api_create(service, type);
546+
547+
if (!kmp) {
548+
return NULL;
519549
}
520550

521-
kmp_api_create_request(new_kmp, type, supp_entry->addr, &supp_entry->sec_keys);
551+
if (ws_pae_lib_kmp_list_add(&supp_entry->kmp_list, kmp) == NULL) {
552+
kmp_api_delete(kmp);
553+
return NULL;
554+
}
555+
556+
kmp_api_cb_register(kmp,
557+
ws_pae_auth_kmp_api_create_confirm,
558+
ws_pae_auth_kmp_api_create_indication,
559+
ws_pae_auth_kmp_api_finished_indication,
560+
ws_pae_auth_kmp_api_finished);
561+
562+
kmp_api_data_set(kmp, supp_entry);
563+
564+
if (kmp_api_start(kmp) < 0) {
565+
ws_pae_lib_kmp_list_delete(&supp_entry->kmp_list, kmp);
566+
return NULL;
567+
}
568+
569+
return kmp;
522570
}
523571

524572
static void ws_pae_auth_kmp_api_finished(kmp_api_t *kmp)

source/6LoWPAN/ws/ws_pae_auth.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@
4444
* \param remote_addr remote address
4545
* \param remote_port remote port
4646
* \param gtks group keys
47+
* \param cert_chain certificate chain
4748
*
4849
* \return < 0 failure
4950
* \return >= 0 success
5051
*
5152
*/
52-
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);
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);
5354

5455
/**
5556
* ws_pae_auth_delete deletes PAE authenticator
@@ -72,7 +73,7 @@ void ws_pae_auth_timer(uint16_t ticks);
7273

7374
#else
7475

75-
#define ws_pae_auth_init(interface_ptr, local_port, remote_addr, remote_port, gtks) 1
76+
#define ws_pae_auth_init(interface_ptr, local_port, remote_addr, remote_port, gtks, certs) 1
7677
#define ws_pae_auth_delete NULL
7778
#define ws_pae_auth_timer NULL
7879

source/6LoWPAN/ws/ws_pae_controller.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "NWK_INTERFACE/Include/protocol.h"
2727
#include "6LoWPAN/ws/ws_config.h"
2828
#include "6LoWPAN/ws/ws_pae_controller.h"
29+
#include "Security/protocols/sec_prot_certs.h"
2930
#include "Security/protocols/sec_prot_keys.h"
3031
#include "6LoWPAN/ws/ws_pae_supp.h"
3132
#include "6LoWPAN/ws/ws_pae_auth.h"
@@ -41,6 +42,7 @@ typedef struct {
4142
ns_list_link_t link; /**< Link */
4243
uint8_t target_eui_64[8]; /**< EAPOL target */
4344
sec_prot_gtk_keys_t gtks; /**< GTKs */
45+
sec_prot_certs_t certs; /**< Certificates */
4446
protocol_interface_info_entry_t *interface_ptr; /**< List link entry */
4547
ws_pae_controller_auth_completed *auth_completed; /**< Authentication completed callback, continue bootstrap */
4648
ws_pae_controller_key_insert *key_insert; /**< Key insert callback */
@@ -78,7 +80,7 @@ int8_t ws_pae_controller_authenticate(protocol_interface_info_entry_t *interface
7880
return -1;
7981
}
8082

81-
if (ws_pae_supp_init(controller->interface_ptr) < 0) {
83+
if (ws_pae_supp_init(controller->interface_ptr, &controller->certs) < 0) {
8284
return -1;
8385
}
8486

@@ -113,7 +115,7 @@ int8_t ws_pae_controller_authenticator_start(protocol_interface_info_entry_t *in
113115

114116
ws_pae_controller_test_keys_set(&controller->gtks);
115117

116-
if (ws_pae_auth_init(controller->interface_ptr, local_port, remote_addr, remote_port, &controller->gtks) < 0) {
118+
if (ws_pae_auth_init(controller->interface_ptr, local_port, remote_addr, remote_port, &controller->gtks, &controller->certs) < 0) {
117119
return -1;
118120
}
119121

@@ -181,6 +183,7 @@ int8_t ws_pae_controller_init(protocol_interface_info_entry_t *interface_ptr)
181183
controller->pae_timer = NULL;
182184

183185
sec_prot_keys_gtks_init(&controller->gtks);
186+
sec_prot_certs_init(&controller->certs);
184187

185188
ns_list_add_to_end(&pae_controller_list, controller);
186189

@@ -220,11 +223,36 @@ int8_t ws_pae_controller_delete(protocol_interface_info_entry_t *interface_ptr)
220223
}
221224

222225
ns_list_remove(&pae_controller_list, controller);
226+
227+
sec_prot_certs_delete(&controller->certs);
228+
223229
ns_dyn_mem_free(controller);
224230

225231
return 0;
226232
}
227233

234+
int8_t ws_pae_controller_certificate_chain_set(const arm_certificate_chain_entry_s *new_chain)
235+
{
236+
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {
237+
// Delete previous information
238+
sec_prot_certs_delete(&entry->certs);
239+
240+
if (new_chain->cert_chain[0]) {
241+
cert_chain_entry_t *root_ca_chain = sec_prot_certs_chain_entry_create();
242+
sec_prot_certs_cert_set(root_ca_chain, 0, (uint8_t *) new_chain->cert_chain[0], new_chain->cert_len[0]);
243+
sec_prot_certs_chain_list_add(&entry->certs.trusted_cert_chain_list, root_ca_chain);
244+
}
245+
246+
if (new_chain->cert_chain[1] && new_chain->key_chain[1]) {
247+
sec_prot_certs_cert_set(&entry->certs.own_cert_chain, 0, (uint8_t *) new_chain->cert_chain[1], new_chain->cert_len[1]);
248+
uint8_t key_len = strlen((char *) new_chain->key_chain[1]) + 1;
249+
sec_prot_certs_priv_key_set(&entry->certs.own_cert_chain, (uint8_t *) new_chain->key_chain[1], key_len);
250+
}
251+
}
252+
253+
return 0;
254+
}
255+
228256
void ws_pae_controller_timer(uint16_t ticks)
229257
{
230258
ns_list_foreach(pae_controller_t, entry, &pae_controller_list) {

source/6LoWPAN/ws/ws_pae_controller.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ int8_t ws_pae_controller_stop(protocol_interface_info_entry_t *interface_ptr);
9090
*/
9191
int8_t ws_pae_controller_delete(protocol_interface_info_entry_t *interface_ptr);
9292

93+
/**
94+
* ws_pae_controller_certificate_chain_set set certificate chain
95+
*
96+
* \param chain certificate chain
97+
*
98+
* \return < 0 failure
99+
* \return >= 0 success
100+
*
101+
*/
102+
int8_t ws_pae_controller_certificate_chain_set(const arm_certificate_chain_entry_s *chain);
103+
93104
/**
94105
* ws_pae_controller_key_insert new GTK key available callback
95106
*

source/6LoWPAN/ws/ws_pae_lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "6LoWPAN/ws/ws_config.h"
2727
#include "Security/kmp/kmp_addr.h"
2828
#include "Security/kmp/kmp_api.h"
29+
#include "Security/protocols/sec_prot_certs.h"
2930
#include "Security/protocols/sec_prot_keys.h"
3031
#include "6LoWPAN/ws/ws_pae_lib.h"
3132

0 commit comments

Comments
 (0)