Skip to content

Commit 5b8e965

Browse files
author
Antti Kauppila
committed
Merge pull request #7 from ARMmbed/sec_changes
Sec changes
2 parents 4cb6322 + 90c1b34 commit 5b8e965

15 files changed

+370
-157
lines changed

source/coap_connection_handler.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define TRACE_GROUP "ThCH"
1616

1717
typedef struct internal_socket_s {
18-
thread_conn_handler_t *parent;
18+
coap_conn_handler_t *parent;
1919

2020
uint16_t listen_port;
2121
int8_t listen_socket;
@@ -79,8 +79,8 @@ static secure_session_t *secure_session_create(internal_socket_t *parent, uint8_
7979
return NULL;
8080
}
8181

82-
this->sec_handler = thread_security_create(parent->listen_socket, this->timer.id, address_ptr, port, &send_to_socket,
83-
&receive_from_socket, &start_timer, &timer_status);
82+
this->sec_handler = coap_security_create(parent->listen_socket, this->timer.id, address_ptr, port, ECJPAKE,
83+
&send_to_socket, &receive_from_socket, &start_timer, &timer_status);
8484
if( !this->sec_handler ){
8585
ns_dyn_mem_free(this);
8686
return NULL;
@@ -98,7 +98,7 @@ static void secure_session_delete(secure_session_t *this)
9898
if (this) {
9999
ns_list_remove(&secure_session_list, this);
100100
if( this->sec_handler ){
101-
thread_security_destroy(this->sec_handler);
101+
coap_security_destroy(this->sec_handler);
102102
this->sec_handler = NULL;
103103
}
104104
ns_dyn_mem_free(this);
@@ -318,6 +318,9 @@ static void timer_cb(int8_t timer_id, uint16_t slots)
318318
/* Intermediate expiry */
319319
sec->timer.state = TIMER_STATE_INT_EXPIRY;
320320
}
321+
//TODO: In case of DTLS and count == 1 || 4 we must call continue connecting of security so
322+
//that mbedtls can handle timeout logic: resending etc...
323+
//Not done, because timer should be refactored to be platform specific!
321324
}
322325
}
323326

@@ -395,7 +398,11 @@ static void secure_recv_sckt_msg(void *cb_res)
395398
uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64);
396399
uint8_t pw_len;
397400
if( sock->parent->_get_password_cb && 0 == sock->parent->_get_password_cb(sock->listen_socket, src_address.address, src_address.identifier, pw, &pw_len)){
398-
coap_security_handler_connect(session->sec_handler, true, pw, pw_len);
401+
//TODO: get_password_cb should support certs and PSK also
402+
coap_security_keys_t keys;
403+
keys._priv = pw;
404+
keys._priv_len = pw_len;
405+
coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys);
399406
//TODO: error handling
400407
}
401408
ns_dyn_mem_free(pw);
@@ -447,7 +454,7 @@ static void recv_sckt_msg(void *cb_res)
447454
}
448455
}
449456

450-
int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len)
457+
int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len)
451458
{
452459
if( !handler || !handler->socket ){
453460
return -1;
@@ -484,7 +491,11 @@ int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t
484491
uint8_t *pw = (uint8_t *)ns_dyn_mem_alloc(64);
485492
uint8_t pw_len;
486493
if( sock->parent->_get_password_cb && 0 == sock->parent->_get_password_cb(sock->listen_socket, address, port, pw, &pw_len)){
487-
coap_security_handler_connect(session->sec_handler, true, pw, pw_len);
494+
//TODO: get_password_cb should support certs and PSK also
495+
coap_security_keys_t keys;
496+
keys._priv = pw;
497+
keys._priv_len = pw_len;
498+
coap_security_handler_connect_non_blocking(session->sec_handler, true, DTLS, keys);
488499
//TODO: error handling
489500
ns_dyn_mem_free(pw);
490501
return 0;
@@ -540,7 +551,7 @@ int coap_connection_handler_virtual_recv(thread_conn_handler_t *handler, uint8_t
540551
return -1;
541552
}
542553

543-
thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
554+
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
544555
send_to_socket_cb *send_to_cb,
545556
get_pw_cb *pw_cb,
546557
security_done_cb *done_cb )
@@ -549,11 +560,11 @@ thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_fr
549560
return NULL;
550561
}
551562

552-
thread_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(thread_conn_handler_t));
563+
coap_conn_handler_t *handler = ns_dyn_mem_alloc(sizeof(coap_conn_handler_t));
553564
if(!handler){
554565
return NULL;
555566
}
556-
memset(handler, 0, sizeof(thread_conn_handler_t));
567+
memset(handler, 0, sizeof(coap_conn_handler_t));
557568
handler->socket = NULL;
558569
handler->_recv_cb = recv_from_cb;
559570
handler->_send_cb = send_to_cb;
@@ -565,7 +576,7 @@ thread_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_fr
565576
return handler;
566577
}
567578

568-
void connection_handler_destroy(thread_conn_handler_t *handler)
579+
void connection_handler_destroy(coap_conn_handler_t *handler)
569580
{
570581
if(handler){
571582
if( handler->socket && handler->socket->is_secure){
@@ -575,7 +586,7 @@ void connection_handler_destroy(thread_conn_handler_t *handler)
575586

576587
while(session != NULL ){
577588
if( session && handler->socket->usage_counter == 1){ //Last connection
578-
thread_security_send_close_alert( session->sec_handler );
589+
coap_security_send_close_alert( session->sec_handler );
579590
}
580591

581592
if( session){
@@ -590,20 +601,20 @@ void connection_handler_destroy(thread_conn_handler_t *handler)
590601
}
591602
}
592603

593-
void connection_handler_close_secure_connection( thread_conn_handler_t *handler, ns_address_t *dest_addr )
604+
void connection_handler_close_secure_connection( coap_conn_handler_t *handler, ns_address_t *dest_addr )
594605
{
595606
if(handler){
596607
if( handler->socket && handler->socket->is_secure){
597608
secure_session_t *session = secure_session_find( handler->socket, dest_addr->address,
598609
dest_addr->identifier);
599610
if( session ){
600-
thread_security_send_close_alert( session->sec_handler );
611+
coap_security_send_close_alert( session->sec_handler );
601612
}
602613
}
603614
}
604615
}
605616

606-
int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool is_real_socket, bool bypassSec)
617+
int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool is_real_socket, bool bypassSec)
607618
{
608619
if( !handler ){
609620
return -1;
@@ -632,7 +643,7 @@ int coap_connection_handler_open_connection(thread_conn_handler_t *handler, uint
632643
return 0;
633644
}
634645

635-
int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address_t *dest_addr, uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec)
646+
int coap_connection_handler_send_data(coap_conn_handler_t *handler, ns_address_t *dest_addr, uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec)
636647
{
637648
if( !handler || !handler->socket || !dest_addr){
638649
return -1;
@@ -658,7 +669,11 @@ int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address
658669
}
659670
uint8_t pw_len;
660671
if( handler->_get_password_cb && 0 == handler->_get_password_cb(handler->socket->listen_socket, dest_addr->address, dest_addr->identifier, pw, &pw_len)){
661-
coap_security_handler_connect(session->sec_handler, false, pw, pw_len);
672+
//TODO: get_password_cb should support certs and PSK also
673+
coap_security_keys_t keys;
674+
keys._priv = pw;
675+
keys._priv_len = pw_len;
676+
coap_security_handler_connect_non_blocking(session->sec_handler, false, DTLS, keys);
662677
ns_dyn_mem_free(pw);
663678
return -2;
664679
}else{
@@ -687,7 +702,7 @@ int coap_connection_handler_send_data(thread_conn_handler_t *handler, ns_address
687702
}
688703
}
689704

690-
bool coap_connection_handler_socket_belongs_to(thread_conn_handler_t *handler, int8_t socket_id)
705+
bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int8_t socket_id)
691706
{
692707
if( !handler || !handler->socket){
693708
return false;

0 commit comments

Comments
 (0)