From 76a79ab4a2403e89753be402f5875a3a10e7b18f Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 3 May 2019 14:38:32 +0100 Subject: [PATCH] Don't allow calling CID API outside of DTLS --- library/ssl_tls.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index d139489a1e..d7291fec0e 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -128,6 +128,9 @@ int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl, unsigned char const *own_cid, size_t own_cid_len ) { + if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) + return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + ssl->negotiate_cid = enable; if( enable == MBEDTLS_SSL_CID_DISABLED ) { @@ -162,8 +165,11 @@ int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl, { *enabled = MBEDTLS_SSL_CID_DISABLED; - if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) + if( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM || + ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ) + { return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); + } /* We report MBEDTLS_SSL_CID_DISABLED in case the CID extensions * were used, but client and server requested the empty CID.