From e88d190f2e6d7e40ee1fcd3dff1e94b275bcd5a4 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Mon, 4 Apr 2022 11:25:23 +0200 Subject: [PATCH] Set ecdh_psa_privkey_is_external to 1 right after setting ecdh_psa_privkey in ssl_get_ecdh_params_from_cert() Signed-off-by: Neil Armstrong --- library/ssl_tls12_server.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/ssl_tls12_server.c b/library/ssl_tls12_server.c index e1e4b8a79..514d81e4e 100644 --- a/library/ssl_tls12_server.c +++ b/library/ssl_tls12_server.c @@ -2883,19 +2883,22 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl ) ssl->handshake->ecdh_psa_privkey = *( (mbedtls_svc_key_id_t*) pk->pk_ctx ); + /* Key should not be destroyed in the TLS library */ + ssl->handshake->ecdh_psa_privkey_is_external = 1; + status = psa_get_key_attributes( ssl->handshake->ecdh_psa_privkey, &key_attributes ); if( status != PSA_SUCCESS) + { + ssl->handshake->ecdh_psa_privkey = MBEDTLS_SVC_KEY_ID_INIT; return( psa_ssl_status_to_mbedtls( status ) ); + } ssl->handshake->ecdh_psa_type = psa_get_key_type( &key_attributes ); ssl->handshake->ecdh_bits = psa_get_key_bits( &key_attributes ); psa_reset_key_attributes( &key_attributes ); - /* Key should not be destroyed in the TLS library */ - ssl->handshake->ecdh_psa_privkey_is_external = 1; - ret = 0; break; case MBEDTLS_PK_ECKEY: