31
31
#include "Security/kmp/kmp_addr.h"
32
32
#include "Security/kmp/kmp_api.h"
33
33
#include "Security/kmp/kmp_socket_if.h"
34
+ #include "Security/protocols/sec_prot_certs.h"
34
35
#include "Security/protocols/sec_prot_keys.h"
35
36
#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"
37
39
#include "Security/protocols/fwh_sec_prot/auth_fwh_sec_prot.h"
38
40
#include "Security/protocols/gkh_sec_prot/auth_gkh_sec_prot.h"
39
41
#include "6LoWPAN/ws/ws_pae_controller.h"
@@ -60,6 +62,7 @@ typedef struct {
60
62
supp_list_t inactive_supp_list ; /**< List of inactive supplicants */
61
63
arm_event_storage_t * timer ; /**< Timer */
62
64
sec_prot_gtk_keys_t * gtks ; /**< GTKs */
65
+ const sec_prot_certs_t * certs ; /**< Certificates */
63
66
bool timer_running ; /**< Timer is running */
64
67
} pae_auth_t ;
65
68
@@ -74,16 +77,18 @@ static int8_t ws_pae_auth_timer_start(pae_auth_t *pae_auth);
74
77
static int8_t ws_pae_auth_timer_stop (pae_auth_t * pae_auth );
75
78
static bool ws_pae_auth_timer_running (pae_auth_t * pae_auth );
76
79
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 );
77
81
static kmp_api_t * ws_pae_auth_kmp_incoming_ind (kmp_service_t * service , kmp_type_e type , const kmp_addr_t * addr );
78
82
static void ws_pae_auth_kmp_api_create_confirm (kmp_api_t * kmp , kmp_result_e result );
79
83
static void ws_pae_auth_kmp_api_create_indication (kmp_api_t * kmp , kmp_type_e type , kmp_addr_t * addr );
80
84
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 );
81
86
static void ws_pae_auth_kmp_api_finished (kmp_api_t * kmp );
82
87
83
88
static int8_t tasklet_id = -1 ;
84
89
static NS_LIST_DEFINE (pae_auth_list , pae_auth_t , link ) ;
85
90
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 )
87
92
{
88
93
if (!interface_ptr || !remote_addr || !gtks ) {
89
94
return -1 ;
@@ -104,13 +109,14 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
104
109
pae_auth -> timer = NULL ;
105
110
106
111
pae_auth -> gtks = gtks ;
112
+ pae_auth -> certs = certs ;
107
113
108
114
pae_auth -> kmp_service = kmp_service_create ();
109
115
if (!pae_auth -> kmp_service ) {
110
116
goto error ;
111
117
}
112
118
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 )) {
114
120
goto error ;
115
121
}
116
122
@@ -130,7 +136,11 @@ int8_t ws_pae_auth_init(protocol_interface_info_entry_t *interface_ptr, uint16_t
130
136
goto error ;
131
137
}
132
138
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 ) {
134
144
goto error ;
135
145
}
136
146
@@ -357,6 +367,18 @@ static void ws_pae_auth_kmp_service_addr_get(kmp_service_t *service, kmp_api_t *
357
367
}
358
368
}
359
369
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
+
360
382
static kmp_api_t * ws_pae_auth_kmp_incoming_ind (kmp_service_t * service , kmp_type_e type , const kmp_addr_t * addr )
361
383
{
362
384
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_
382
404
if (!supp_entry ) {
383
405
return 0 ;
384
406
}
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 );
386
408
} else {
387
409
// Updates relay address
388
410
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
494
516
return ;
495
517
}
496
518
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 );
501
521
if (!new_kmp ) {
502
522
return ;
503
523
}
504
524
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
+ }
537
+ }
538
+
539
+ kmp_api_create_request (new_kmp , type , supp_entry -> addr , & supp_entry -> sec_keys );
540
+ }
541
+
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 ;
508
549
}
509
550
510
- kmp_api_cb_register (new_kmp ,
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 ,
511
557
ws_pae_auth_kmp_api_create_confirm ,
512
558
ws_pae_auth_kmp_api_create_indication ,
513
559
ws_pae_auth_kmp_api_finished_indication ,
514
560
ws_pae_auth_kmp_api_finished );
515
561
516
- if (kmp_api_start (new_kmp ) < 0 ) {
517
- ws_pae_lib_kmp_list_delete (& supp_entry -> kmp_list , new_kmp );
518
- return ;
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 ;
519
567
}
520
568
521
- kmp_api_create_request ( new_kmp , type , supp_entry -> addr , & supp_entry -> sec_keys ) ;
569
+ return kmp ;
522
570
}
523
571
524
572
static void ws_pae_auth_kmp_api_finished (kmp_api_t * kmp )
0 commit comments