From 8897c070756e66b9b01441ea282470ae4f958714 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 12 Aug 2022 13:56:53 +0800 Subject: [PATCH] Add server only guards for psk callback Signed-off-by: Jerry Yu --- include/mbedtls/ssl.h | 4 ++++ library/ssl_tls.c | 3 +++ tests/suites/test_suite_ssl.function | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index eda6bc2f2..5a02182c0 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -1390,10 +1390,12 @@ struct mbedtls_ssl_config #endif #if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED) +#if defined(MBEDTLS_SSL_SRV_C) /** Callback to retrieve PSK key from identity */ int (*MBEDTLS_PRIVATE(f_psk))(void *, mbedtls_ssl_context *, const unsigned char *, size_t); void *MBEDTLS_PRIVATE(p_psk); /*!< context for PSK callback */ #endif +#endif #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) /** Callback to create & write a cookie for ClientHello verification */ @@ -3415,6 +3417,7 @@ int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl, mbedtls_svc_key_id_t psk ); #endif /* MBEDTLS_USE_PSA_CRYPTO */ +#if defined(MBEDTLS_SSL_SRV_C) /** * \brief Set the PSK callback (server-side only). * @@ -3457,6 +3460,7 @@ void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf, int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_psk ); +#endif /* MBEDTLS_SSL_SRV_C */ #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index f0615ea7d..616df07de 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -1795,6 +1795,7 @@ int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl, } #endif /* MBEDTLS_USE_PSA_CRYPTO */ +#if defined(MBEDTLS_SSL_SRV_C) void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf, int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), @@ -1803,6 +1804,8 @@ void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf, conf->f_psk = f_psk; conf->p_psk = p_psk; } +#endif /* MBEDTLS_SSL_SRV_C */ + #endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */ #if defined(MBEDTLS_USE_PSA_CRYPTO) diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index f24d1a493..7b5743ece 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -2184,8 +2184,9 @@ void perform_handshake( handshake_test_options *options ) options->psk_str->len, (const unsigned char *) psk_identity, strlen( psk_identity ) ) == 0 ); - +#if defined(MBEDTLS_SSL_SRV_C) mbedtls_ssl_conf_psk_cb( &server.conf, psk_dummy_callback, NULL ); +#endif } #endif #if defined(MBEDTLS_SSL_RENEGOTIATION)