From d05ac5dfcedf0d004babe5ee8fc31d2801511d19 Mon Sep 17 00:00:00 2001 From: Xiaokang Qian Date: Thu, 15 Dec 2022 14:38:29 +0000 Subject: [PATCH] Add extern apis mbedtls_ticket_get_psk. Signed-off-by: Xiaokang Qian --- library/ssl_misc.h | 7 +++++++ library/ssl_tls13_generic.c | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 146dae0fb..baef741a2 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -2629,6 +2629,13 @@ static inline int mbedtls_ssl_tls13_cipher_suite_is_offered( return 0; } +#ifdef MBEDTLS_SSL_SESSION_TICKETS +int mbedtls_ssl_tls13_ticket_get_psk(mbedtls_ssl_context *ssl, + psa_algorithm_t *hash_alg, + const unsigned char **psk, + size_t *psk_len); +#endif + /** * \brief Validate cipher suite against config in SSL context. * diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index 513937e0e..3de164cd1 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1574,4 +1574,31 @@ int mbedtls_ssl_tls13_check_received_extension( return MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION; } +#ifdef MBEDTLS_SSL_SESSION_TICKETS +int mbedtls_ssl_tls13_ticket_get_psk(mbedtls_ssl_context *ssl, + psa_algorithm_t *hash_alg, + const unsigned char **psk, + size_t *psk_len) +{ + + mbedtls_ssl_session *session = ssl->session_negotiate; + const mbedtls_ssl_ciphersuite_t *ciphersuite_info = NULL; + + if (ssl->handshake->resume == 0 || session == NULL || + session->ticket == NULL) { + return -1; + } + + ciphersuite_info = mbedtls_ssl_ciphersuite_from_id(session->ciphersuite); + if (ciphersuite_info != NULL) { + *hash_alg = mbedtls_psa_translate_md(ciphersuite_info->mac); + } + + *psk = session->resumption_key; + *psk_len = session->resumption_key_len; + + return 0; +} +#endif /* MBEDTLS_SSL_SESSION_TICKETS */ + #endif /* MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_PROTO_TLS1_3 */