Skip to content

Commit eea83e5

Browse files
author
Arto Kinnunen
authored
Flag out entropy source addition (#53)
Middleware components are not allowed to add strong entropy sources. Preprocessor directive is used as some old applications might rely on having strong entropy source in coap-service.
1 parent 7d72eb4 commit eea83e5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

source/coap_security_handler.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,19 @@ static int get_timer( void *sec_obj );
7575
static int coap_security_handler_configure_keys( coap_security_t *sec, coap_security_keys_t keys );
7676

7777
int entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen );
78+
7879
//Point these back to M2MConnectionHandler!!!
7980
int f_send( void *ctx, const unsigned char *buf, size_t len );
8081
int f_recv(void *ctx, unsigned char *buf, size_t len);
8182

8283
static int coap_security_handler_init(coap_security_t *sec){
8384
const char *pers = "dtls_client";
85+
#ifdef COAP_SERVICE_PROVIDE_STRONG_ENTROPY_SOURCE
86+
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_STRONG;
87+
#else
88+
const int entropy_source_type = MBEDTLS_ENTROPY_SOURCE_WEAK;
89+
#endif
90+
8491
mbedtls_ssl_init( &sec->_ssl );
8592
mbedtls_ssl_config_init( &sec->_conf );
8693
mbedtls_ctr_drbg_init( &sec->_ctr_drbg );
@@ -97,10 +104,8 @@ static int coap_security_handler_init(coap_security_t *sec){
97104

98105
sec->_is_started = false;
99106

100-
//TODO: Must have at least 1 strong entropy source, otherwise DTLS will fail.
101-
//This is NOT strong even we say it is!
102107
if( mbedtls_entropy_add_source( &sec->_entropy, entropy_poll, NULL,
103-
128, 1 ) < 0 ){
108+
128, entropy_source_type ) < 0 ){
104109
return -1;
105110
}
106111

0 commit comments

Comments
 (0)