blob: ddb3c34b915d9f5b07a46d9f6536f4b76eadb521 [file] [log] [blame]
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +02001/*
2 * Simple DTLS client demonstration program
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +02006 */
7
Bence Szépkútic662b362021-05-27 11:25:03 +02008#include "mbedtls/build_info.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +02009
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000010#include "mbedtls/platform.h"
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000011
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020012#if !defined(MBEDTLS_SSL_CLI_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +020013 !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_TIMING_C) || \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014 !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
15 !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_RSA_C) || \
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010016 !defined(MBEDTLS_PEM_PARSE_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010017int main(void)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020018{
Gilles Peskine449bd832023-01-11 14:50:10 +010019 mbedtls_printf("MBEDTLS_SSL_CLI_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
20 "MBEDTLS_NET_C and/or MBEDTLS_TIMING_C and/or "
21 "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
22 "MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_RSA_C and/or "
23 "MBEDTLS_PEM_PARSE_C not defined.\n");
24 mbedtls_exit(0);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020025}
26#else
27
28#include <string.h>
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020029
Andres AG788aa4a2016-09-14 14:32:09 +010030#include "mbedtls/net_sockets.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000031#include "mbedtls/debug.h"
32#include "mbedtls/ssl.h"
33#include "mbedtls/entropy.h"
34#include "mbedtls/ctr_drbg.h"
35#include "mbedtls/error.h"
Manuel Pégourié-Gonnard56273da2015-05-26 12:19:45 +020036#include "mbedtls/timing.h"
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010037#include "test/certs.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020038
Simon Butcher6fd96ad2018-05-12 18:23:32 +010039/* Uncomment out the following line to default to IPv4 and disable IPv6 */
40//#define FORCE_IPV4
41
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +020042#define SERVER_PORT "4433"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020043#define SERVER_NAME "localhost"
Simon Butcher6fd96ad2018-05-12 18:23:32 +010044
45#ifdef FORCE_IPV4
46#define SERVER_ADDR "127.0.0.1" /* Forces IPv4 */
47#else
48#define SERVER_ADDR "::1"
49#endif
50
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020051#define MESSAGE "Echo this"
52
53#define READ_TIMEOUT_MS 1000
54#define MAX_RETRY 5
55
56#define DEBUG_LEVEL 0
57
Simon Butcher63cb97e2018-12-06 17:43:31 +000058
Gilles Peskine449bd832023-01-11 14:50:10 +010059static void my_debug(void *ctx, int level,
60 const char *file, int line,
61 const char *str)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020062{
63 ((void) level);
64
Gilles Peskine449bd832023-01-11 14:50:10 +010065 mbedtls_fprintf((FILE *) ctx, "%s:%04d: %s", file, line, str);
66 fflush((FILE *) ctx);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020067}
68
Gilles Peskine449bd832023-01-11 14:50:10 +010069int main(int argc, char *argv[])
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020070{
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +020071 int ret, len;
72 mbedtls_net_context server_fd;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020073 uint32_t flags;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020074 unsigned char buf[1024];
75 const char *pers = "dtls_client";
76 int retry_left = MAX_RETRY;
77
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078 mbedtls_entropy_context entropy;
79 mbedtls_ctr_drbg_context ctr_drbg;
80 mbedtls_ssl_context ssl;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +020081 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082 mbedtls_x509_crt cacert;
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +020083 mbedtls_timing_delay_context timer;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020084
85 ((void) argc);
86 ((void) argv);
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_DEBUG_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010089 mbedtls_debug_set_threshold(DEBUG_LEVEL);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020090#endif
91
92 /*
93 * 0. Initialize the RNG and the session data
94 */
Gilles Peskine449bd832023-01-11 14:50:10 +010095 mbedtls_net_init(&server_fd);
96 mbedtls_ssl_init(&ssl);
97 mbedtls_ssl_config_init(&conf);
98 mbedtls_x509_crt_init(&cacert);
99 mbedtls_ctr_drbg_init(&ctr_drbg);
Przemek Stekiela0a1c1e2023-04-17 11:10:05 +0200100 mbedtls_entropy_init(&entropy);
101
102#if defined(MBEDTLS_USE_PSA_CRYPTO)
103 psa_status_t status = psa_crypto_init();
104 if (status != PSA_SUCCESS) {
105 mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
106 (int) status);
107 ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
108 goto exit;
109 }
110#endif /* MBEDTLS_USE_PSA_CRYPTO */
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200111
Gilles Peskine449bd832023-01-11 14:50:10 +0100112 mbedtls_printf("\n . Seeding the random number generator...");
113 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200114
Gilles Peskine449bd832023-01-11 14:50:10 +0100115 if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
116 (const unsigned char *) pers,
117 strlen(pers))) != 0) {
118 mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200119 goto exit;
120 }
121
Gilles Peskine449bd832023-01-11 14:50:10 +0100122 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200123
124 /*
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200125 * 0. Load certificates
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200126 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100127 mbedtls_printf(" . Loading the CA root certificate ...");
128 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200129
Gilles Peskine449bd832023-01-11 14:50:10 +0100130 ret = mbedtls_x509_crt_parse(&cacert, (const unsigned char *) mbedtls_test_cas_pem,
131 mbedtls_test_cas_pem_len);
132 if (ret < 0) {
133 mbedtls_printf(" failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n",
134 (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200135 goto exit;
136 }
137
Gilles Peskine449bd832023-01-11 14:50:10 +0100138 mbedtls_printf(" ok (%d skipped)\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200139
140 /*
141 * 1. Start the connection
142 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100143 mbedtls_printf(" . Connecting to udp/%s/%s...", SERVER_NAME, SERVER_PORT);
144 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200145
Gilles Peskine449bd832023-01-11 14:50:10 +0100146 if ((ret = mbedtls_net_connect(&server_fd, SERVER_ADDR,
147 SERVER_PORT, MBEDTLS_NET_PROTO_UDP)) != 0) {
148 mbedtls_printf(" failed\n ! mbedtls_net_connect returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200149 goto exit;
150 }
151
Gilles Peskine449bd832023-01-11 14:50:10 +0100152 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200153
154 /*
155 * 2. Setup stuff
156 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100157 mbedtls_printf(" . Setting up the DTLS structure...");
158 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200159
Gilles Peskine449bd832023-01-11 14:50:10 +0100160 if ((ret = mbedtls_ssl_config_defaults(&conf,
161 MBEDTLS_SSL_IS_CLIENT,
162 MBEDTLS_SSL_TRANSPORT_DATAGRAM,
163 MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
164 mbedtls_printf(" failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret);
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200165 goto exit;
166 }
167
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200168 /* OPTIONAL is usually a bad choice for security, but makes interop easier
169 * in this simplified example, in which the ca chain is hardcoded.
170 * Production code should set a proper ca chain and use REQUIRED. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100171 mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
172 mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL);
173 mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
174 mbedtls_ssl_conf_dbg(&conf, my_debug, stdout);
175 mbedtls_ssl_conf_read_timeout(&conf, READ_TIMEOUT_MS);
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200176
Gilles Peskine449bd832023-01-11 14:50:10 +0100177 if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0) {
178 mbedtls_printf(" failed\n ! mbedtls_ssl_setup returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200179 goto exit;
180 }
181
Gilles Peskine449bd832023-01-11 14:50:10 +0100182 if ((ret = mbedtls_ssl_set_hostname(&ssl, SERVER_NAME)) != 0) {
183 mbedtls_printf(" failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret);
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100184 goto exit;
185 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200186
Gilles Peskine449bd832023-01-11 14:50:10 +0100187 mbedtls_ssl_set_bio(&ssl, &server_fd,
188 mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200189
Gilles Peskine449bd832023-01-11 14:50:10 +0100190 mbedtls_ssl_set_timer_cb(&ssl, &timer, mbedtls_timing_set_delay,
191 mbedtls_timing_get_delay);
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +0200192
Gilles Peskine449bd832023-01-11 14:50:10 +0100193 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100194
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200195 /*
196 * 4. Handshake
197 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100198 mbedtls_printf(" . Performing the DTLS handshake...");
199 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200200
Gilles Peskine449bd832023-01-11 14:50:10 +0100201 do {
202 ret = mbedtls_ssl_handshake(&ssl);
203 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
204 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200205
Gilles Peskine449bd832023-01-11 14:50:10 +0100206 if (ret != 0) {
207 mbedtls_printf(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n",
208 (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200209 goto exit;
210 }
211
Gilles Peskine449bd832023-01-11 14:50:10 +0100212 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200213
214 /*
215 * 5. Verify the server certificate
216 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100217 mbedtls_printf(" . Verifying peer X.509 certificate...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200218
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 /* In real life, we would have used MBEDTLS_SSL_VERIFY_REQUIRED so that the
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200220 * handshake would not succeed if the peer's cert is bad. Even if we used
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221 * MBEDTLS_SSL_VERIFY_OPTIONAL, we would bail out here if ret != 0 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100222 if ((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0) {
Hanno Becker612a2f12020-10-09 09:19:39 +0100223#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200224 char vrfy_buf[512];
Peter Kolbus9a969b62018-12-11 13:55:56 -0600225#endif
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200226
Gilles Peskine449bd832023-01-11 14:50:10 +0100227 mbedtls_printf(" failed\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200228
Hanno Becker612a2f12020-10-09 09:19:39 +0100229#if !defined(MBEDTLS_X509_REMOVE_INFO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100230 mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200231
Gilles Peskine449bd832023-01-11 14:50:10 +0100232 mbedtls_printf("%s\n", vrfy_buf);
Peter Kolbus9a969b62018-12-11 13:55:56 -0600233#endif
Gilles Peskine449bd832023-01-11 14:50:10 +0100234 } else {
235 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200236 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200237
238 /*
239 * 6. Write the echo request
240 */
241send_request:
Gilles Peskine449bd832023-01-11 14:50:10 +0100242 mbedtls_printf(" > Write to server:");
243 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200244
Gilles Peskine449bd832023-01-11 14:50:10 +0100245 len = sizeof(MESSAGE) - 1;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200246
Gilles Peskine449bd832023-01-11 14:50:10 +0100247 do {
248 ret = mbedtls_ssl_write(&ssl, (unsigned char *) MESSAGE, len);
249 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
250 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200251
Gilles Peskine449bd832023-01-11 14:50:10 +0100252 if (ret < 0) {
253 mbedtls_printf(" failed\n ! mbedtls_ssl_write returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200254 goto exit;
255 }
256
257 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100258 mbedtls_printf(" %d bytes written\n\n%s\n\n", len, MESSAGE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200259
260 /*
261 * 7. Read the echo response
262 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100263 mbedtls_printf(" < Read from server:");
264 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200265
Gilles Peskine449bd832023-01-11 14:50:10 +0100266 len = sizeof(buf) - 1;
267 memset(buf, 0, sizeof(buf));
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200268
Gilles Peskine449bd832023-01-11 14:50:10 +0100269 do {
270 ret = mbedtls_ssl_read(&ssl, buf, len);
271 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
272 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200273
Gilles Peskine449bd832023-01-11 14:50:10 +0100274 if (ret <= 0) {
275 switch (ret) {
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100276 case MBEDTLS_ERR_SSL_TIMEOUT:
Gilles Peskine449bd832023-01-11 14:50:10 +0100277 mbedtls_printf(" timeout\n\n");
278 if (retry_left-- > 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200279 goto send_request;
Gilles Peskine449bd832023-01-11 14:50:10 +0100280 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200281 goto exit;
282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
Gilles Peskine449bd832023-01-11 14:50:10 +0100284 mbedtls_printf(" connection was closed gracefully\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200285 goto close_notify;
286
287 default:
Gilles Peskine449bd832023-01-11 14:50:10 +0100288 mbedtls_printf(" mbedtls_ssl_read returned -0x%x\n\n", (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200289 goto exit;
290 }
291 }
292
293 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100294 mbedtls_printf(" %d bytes read\n\n%s\n\n", len, buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200295
296 /*
297 * 8. Done, cleanly close the connection
298 */
299close_notify:
Gilles Peskine449bd832023-01-11 14:50:10 +0100300 mbedtls_printf(" . Closing the connection...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200301
302 /* No error checking, the connection might be closed already */
Gilles Peskine449bd832023-01-11 14:50:10 +0100303 do {
304 ret = mbedtls_ssl_close_notify(&ssl);
305 } while (ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200306 ret = 0;
307
Gilles Peskine449bd832023-01-11 14:50:10 +0100308 mbedtls_printf(" done\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200309
310 /*
311 * 9. Final clean-ups and exit
312 */
313exit:
314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#ifdef MBEDTLS_ERROR_C
Gilles Peskine449bd832023-01-11 14:50:10 +0100316 if (ret != 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200317 char error_buf[100];
Gilles Peskine449bd832023-01-11 14:50:10 +0100318 mbedtls_strerror(ret, error_buf, 100);
319 mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200320 }
321#endif
322
Gilles Peskine449bd832023-01-11 14:50:10 +0100323 mbedtls_net_free(&server_fd);
Gilles Peskine449bd832023-01-11 14:50:10 +0100324 mbedtls_x509_crt_free(&cacert);
325 mbedtls_ssl_free(&ssl);
326 mbedtls_ssl_config_free(&conf);
327 mbedtls_ctr_drbg_free(&ctr_drbg);
328 mbedtls_entropy_free(&entropy);
Przemek Stekiel758aef62023-04-19 13:47:43 +0200329#if defined(MBEDTLS_USE_PSA_CRYPTO)
Przemek Stekiela8c560a2023-04-19 10:15:26 +0200330 mbedtls_psa_crypto_free();
Przemek Stekiel758aef62023-04-19 13:47:43 +0200331#endif /* MBEDTLS_USE_PSA_CRYPTO */
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200332
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200333 /* Shell can not handle large exit numbers -> 1 for errors */
Gilles Peskine449bd832023-01-11 14:50:10 +0100334 if (ret < 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200335 ret = 1;
Gilles Peskine449bd832023-01-11 14:50:10 +0100336 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200337
Gilles Peskine449bd832023-01-11 14:50:10 +0100338 mbedtls_exit(ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200339}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_PROTO_DTLS && MBEDTLS_NET_C &&
Tom Cosgrove1797b052022-12-04 17:19:59 +0000341 MBEDTLS_TIMING_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
Mateusz Starzyk1aec6462021-02-08 15:34:42 +0100342 MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C && MBEDTLS_PEM_PARSE_C */