Skip to content

Commit f861157

Browse files
Teppo JärvelinArto Kinnunen
authored andcommitted
Prepare for upcoming MbedTLS changes
1 parent e5e0c13 commit f861157

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

source/coap_security_handler.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,23 @@ struct coap_security_s {
6868

6969
};
7070

71+
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
7172
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
7273
const int ECJPAKE_SUITES[] = {
7374
MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8,
7475
0
7576
};
7677
#endif
7778

79+
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
7880
static const int PSK_SUITES[] = {
7981
MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256,
8082
MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8,
8183
MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8,
8284
0
8385
};
86+
#endif /* defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) */
87+
#endif /* !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) */
8488

8589
#define TRACE_GROUP "CsSh"
8690

@@ -332,7 +336,9 @@ static int coap_security_handler_configure_keys(coap_security_t *sec, coap_secur
332336
if (0 != mbedtls_ssl_conf_psk(&sec->_conf, keys._priv_key, keys._priv_key_len, keys._cert, keys._cert_len)) {
333337
break;
334338
}
339+
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
335340
mbedtls_ssl_conf_ciphersuites(&sec->_conf, PSK_SUITES);
341+
#endif /* !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) */
336342
ret = 0;
337343
#endif
338344
break;
@@ -342,7 +348,9 @@ static int coap_security_handler_configure_keys(coap_security_t *sec, coap_secur
342348
if (mbedtls_ssl_set_hs_ecjpake_password(&sec->_ssl, keys._key, keys._key_len) != 0) {
343349
return -1;
344350
}
351+
#if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE)
345352
mbedtls_ssl_conf_ciphersuites(&sec->_conf, ECJPAKE_SUITES);
353+
#endif /* !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) */
346354

347355
//NOTE: If thread starts supporting PSK in other modes, then this will be needed!
348356
mbedtls_ssl_conf_export_keys_cb(&sec->_conf,
@@ -394,11 +402,23 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
394402
return -1;
395403
}
396404

405+
// Defines MBEDTLS_SSL_CONF_RECV/SEND/RECV_TIMEOUT define global functions which should be the same for all
406+
// callers of mbedtls_ssl_set_bio_ctx and there should be only one ssl context. If these rules don't apply,
407+
// these defines can't be used.
408+
#if !defined(MBEDTLS_SSL_CONF_RECV) && !defined(MBEDTLS_SSL_CONF_SEND) && !defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT)
397409
mbedtls_ssl_set_bio(&sec->_ssl, sec,
398410
f_send, f_recv, NULL);
411+
#else
412+
mbedtls_ssl_set_bio_ctx(&sec->_ssl, sec);
413+
#endif /* !defined(MBEDTLS_SSL_CONF_RECV) && !defined(MBEDTLS_SSL_CONF_SEND) && !defined(MBEDTLS_SSL_CONF_RECV_TIMEOUT) */
399414

415+
// Defines MBEDTLS_SSL_CONF_SET_TIMER/GET_TIMER define global functions which should be the same for all
416+
// callers of mbedtls_ssl_set_timer_cb and there should be only one ssl context. If these rules don't apply,
417+
// these defines can't be used.
418+
#if !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER)
400419
mbedtls_ssl_set_timer_cb(&sec->_ssl, sec, set_timer,
401420
get_timer);
421+
#endif /* !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER) */
402422

403423
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
404424
//TODO: Figure out better way!!!
@@ -420,8 +440,13 @@ int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_ser
420440
&sec->_cookie);
421441
#endif
422442

443+
#if !defined(MBEDTLS_SSL_CONF_MIN_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MIN_MAJOR_VER)
423444
mbedtls_ssl_conf_min_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
445+
#endif /* !defined(MBEDTLS_SSL_CONF_MIN_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MIN_MAJOR_VER) */
446+
447+
#if !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER)
424448
mbedtls_ssl_conf_max_version(&sec->_conf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3);
449+
#endif /* !defined(MBEDTLS_SSL_CONF_MAX_MINOR_VER) || !defined(MBEDTLS_SSL_CONF_MAX_MAJOR_VER) */
425450

426451
sec->_is_started = true;
427452

0 commit comments

Comments
 (0)