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);
7477static int8_t ws_pae_auth_timer_stop (pae_auth_t * pae_auth );
7578static bool ws_pae_auth_timer_running (pae_auth_t * pae_auth );
7679static 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 );
7781static kmp_api_t * ws_pae_auth_kmp_incoming_ind (kmp_service_t * service , kmp_type_e type , const kmp_addr_t * addr );
7882static void ws_pae_auth_kmp_api_create_confirm (kmp_api_t * kmp , kmp_result_e result );
7983static void ws_pae_auth_kmp_api_create_indication (kmp_api_t * kmp , kmp_type_e type , kmp_addr_t * addr );
8084static 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 );
8186static void ws_pae_auth_kmp_api_finished (kmp_api_t * kmp );
8287
8388static int8_t tasklet_id = -1 ;
8489static 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+
360382static 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
524572static void ws_pae_auth_kmp_api_finished (kmp_api_t * kmp )
0 commit comments