blob: 903b28d11a2650d2ed27b5ac58c52f49e929643b [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
Gilles Peskineae710c82024-09-04 16:07:56 +020012#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
13 !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_CLI_C) || \
14 !defined(MBEDTLS_TIMING_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
15 !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010016int main(void)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020017{
Gilles Peskineae710c82024-09-04 16:07:56 +020018 mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
19 "MBEDTLS_NET_C and/or MBEDTLS_SSL_CLI_C and/or "
20 "MBEDTLS_TIMING_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
21 "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
22 "not defined.\n");
Gilles Peskine449bd832023-01-11 14:50:10 +010023 mbedtls_exit(0);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020024}
25#else
26
27#include <string.h>
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020028
Andres AG788aa4a2016-09-14 14:32:09 +010029#include "mbedtls/net_sockets.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/debug.h"
31#include "mbedtls/ssl.h"
32#include "mbedtls/entropy.h"
33#include "mbedtls/ctr_drbg.h"
34#include "mbedtls/error.h"
Manuel Pégourié-Gonnard56273da2015-05-26 12:19:45 +020035#include "mbedtls/timing.h"
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010036#include "test/certs.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020037
Simon Butcher6fd96ad2018-05-12 18:23:32 +010038/* Uncomment out the following line to default to IPv4 and disable IPv6 */
39//#define FORCE_IPV4
40
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +020041#define SERVER_PORT "4433"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020042#define SERVER_NAME "localhost"
Simon Butcher6fd96ad2018-05-12 18:23:32 +010043
44#ifdef FORCE_IPV4
45#define SERVER_ADDR "127.0.0.1" /* Forces IPv4 */
46#else
47#define SERVER_ADDR "::1"
48#endif
49
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020050#define MESSAGE "Echo this"
51
52#define READ_TIMEOUT_MS 1000
53#define MAX_RETRY 5
54
55#define DEBUG_LEVEL 0
56
Simon Butcher63cb97e2018-12-06 17:43:31 +000057
Gilles Peskine449bd832023-01-11 14:50:10 +010058static void my_debug(void *ctx, int level,
59 const char *file, int line,
60 const char *str)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020061{
62 ((void) level);
63
Gilles Peskine449bd832023-01-11 14:50:10 +010064 mbedtls_fprintf((FILE *) ctx, "%s:%04d: %s", file, line, str);
65 fflush((FILE *) ctx);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020066}
67
Gilles Peskine449bd832023-01-11 14:50:10 +010068int main(int argc, char *argv[])
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020069{
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +020070 int ret, len;
71 mbedtls_net_context server_fd;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020072 uint32_t flags;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020073 unsigned char buf[1024];
74 const char *pers = "dtls_client";
75 int retry_left = MAX_RETRY;
76
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077 mbedtls_entropy_context entropy;
78 mbedtls_ctr_drbg_context ctr_drbg;
79 mbedtls_ssl_context ssl;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +020080 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081 mbedtls_x509_crt cacert;
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +020082 mbedtls_timing_delay_context timer;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020083
84 ((void) argc);
85 ((void) argv);
86
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_DEBUG_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010088 mbedtls_debug_set_threshold(DEBUG_LEVEL);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020089#endif
90
91 /*
92 * 0. Initialize the RNG and the session data
93 */
Gilles Peskine449bd832023-01-11 14:50:10 +010094 mbedtls_net_init(&server_fd);
95 mbedtls_ssl_init(&ssl);
96 mbedtls_ssl_config_init(&conf);
97 mbedtls_x509_crt_init(&cacert);
98 mbedtls_ctr_drbg_init(&ctr_drbg);
Przemek Stekiela0a1c1e2023-04-17 11:10:05 +020099 mbedtls_entropy_init(&entropy);
100
101#if defined(MBEDTLS_USE_PSA_CRYPTO)
102 psa_status_t status = psa_crypto_init();
103 if (status != PSA_SUCCESS) {
104 mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
105 (int) status);
106 ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
107 goto exit;
108 }
109#endif /* MBEDTLS_USE_PSA_CRYPTO */
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200110
Gilles Peskine449bd832023-01-11 14:50:10 +0100111 mbedtls_printf("\n . Seeding the random number generator...");
112 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200113
Gilles Peskine449bd832023-01-11 14:50:10 +0100114 if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
115 (const unsigned char *) pers,
116 strlen(pers))) != 0) {
117 mbedtls_printf(" failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200118 goto exit;
119 }
120
Gilles Peskine449bd832023-01-11 14:50:10 +0100121 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200122
123 /*
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200124 * 0. Load certificates
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200125 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100126 mbedtls_printf(" . Loading the CA root certificate ...");
127 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200128
Gilles Peskine449bd832023-01-11 14:50:10 +0100129 ret = mbedtls_x509_crt_parse(&cacert, (const unsigned char *) mbedtls_test_cas_pem,
130 mbedtls_test_cas_pem_len);
131 if (ret < 0) {
132 mbedtls_printf(" failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n",
133 (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200134 goto exit;
135 }
136
Gilles Peskine449bd832023-01-11 14:50:10 +0100137 mbedtls_printf(" ok (%d skipped)\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200138
139 /*
140 * 1. Start the connection
141 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100142 mbedtls_printf(" . Connecting to udp/%s/%s...", SERVER_NAME, SERVER_PORT);
143 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200144
Gilles Peskine449bd832023-01-11 14:50:10 +0100145 if ((ret = mbedtls_net_connect(&server_fd, SERVER_ADDR,
146 SERVER_PORT, MBEDTLS_NET_PROTO_UDP)) != 0) {
147 mbedtls_printf(" failed\n ! mbedtls_net_connect returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200148 goto exit;
149 }
150
Gilles Peskine449bd832023-01-11 14:50:10 +0100151 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200152
153 /*
154 * 2. Setup stuff
155 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100156 mbedtls_printf(" . Setting up the DTLS structure...");
157 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200158
Gilles Peskine449bd832023-01-11 14:50:10 +0100159 if ((ret = mbedtls_ssl_config_defaults(&conf,
160 MBEDTLS_SSL_IS_CLIENT,
161 MBEDTLS_SSL_TRANSPORT_DATAGRAM,
162 MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
163 mbedtls_printf(" failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret);
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200164 goto exit;
165 }
166
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200167 /* OPTIONAL is usually a bad choice for security, but makes interop easier
168 * in this simplified example, in which the ca chain is hardcoded.
169 * Production code should set a proper ca chain and use REQUIRED. */
Gilles Peskine449bd832023-01-11 14:50:10 +0100170 mbedtls_ssl_conf_authmode(&conf, MBEDTLS_SSL_VERIFY_OPTIONAL);
171 mbedtls_ssl_conf_ca_chain(&conf, &cacert, NULL);
172 mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &ctr_drbg);
173 mbedtls_ssl_conf_dbg(&conf, my_debug, stdout);
174 mbedtls_ssl_conf_read_timeout(&conf, READ_TIMEOUT_MS);
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200175
Gilles Peskine449bd832023-01-11 14:50:10 +0100176 if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0) {
177 mbedtls_printf(" failed\n ! mbedtls_ssl_setup returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200178 goto exit;
179 }
180
Gilles Peskine449bd832023-01-11 14:50:10 +0100181 if ((ret = mbedtls_ssl_set_hostname(&ssl, SERVER_NAME)) != 0) {
182 mbedtls_printf(" failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret);
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100183 goto exit;
184 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200185
Gilles Peskine449bd832023-01-11 14:50:10 +0100186 mbedtls_ssl_set_bio(&ssl, &server_fd,
187 mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200188
Gilles Peskine449bd832023-01-11 14:50:10 +0100189 mbedtls_ssl_set_timer_cb(&ssl, &timer, mbedtls_timing_set_delay,
190 mbedtls_timing_get_delay);
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +0200191
Gilles Peskine449bd832023-01-11 14:50:10 +0100192 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100193
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200194 /*
195 * 4. Handshake
196 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100197 mbedtls_printf(" . Performing the DTLS handshake...");
198 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200199
Gilles Peskine449bd832023-01-11 14:50:10 +0100200 do {
201 ret = mbedtls_ssl_handshake(&ssl);
202 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
203 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200204
Gilles Peskine449bd832023-01-11 14:50:10 +0100205 if (ret != 0) {
206 mbedtls_printf(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n",
207 (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200208 goto exit;
209 }
210
Gilles Peskine449bd832023-01-11 14:50:10 +0100211 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200212
213 /*
214 * 5. Verify the server certificate
215 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100216 mbedtls_printf(" . Verifying peer X.509 certificate...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 /* In real life, we would have used MBEDTLS_SSL_VERIFY_REQUIRED so that the
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200219 * handshake would not succeed if the peer's cert is bad. Even if we used
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220 * MBEDTLS_SSL_VERIFY_OPTIONAL, we would bail out here if ret != 0 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100221 if ((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0) {
Hanno Becker612a2f12020-10-09 09:19:39 +0100222#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200223 char vrfy_buf[512];
Peter Kolbus9a969b62018-12-11 13:55:56 -0600224#endif
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200225
Gilles Peskine449bd832023-01-11 14:50:10 +0100226 mbedtls_printf(" failed\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200227
Hanno Becker612a2f12020-10-09 09:19:39 +0100228#if !defined(MBEDTLS_X509_REMOVE_INFO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100229 mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200230
Gilles Peskine449bd832023-01-11 14:50:10 +0100231 mbedtls_printf("%s\n", vrfy_buf);
Peter Kolbus9a969b62018-12-11 13:55:56 -0600232#endif
Gilles Peskine449bd832023-01-11 14:50:10 +0100233 } else {
234 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200235 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200236
237 /*
238 * 6. Write the echo request
239 */
240send_request:
Gilles Peskine449bd832023-01-11 14:50:10 +0100241 mbedtls_printf(" > Write to server:");
242 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200243
Gilles Peskine449bd832023-01-11 14:50:10 +0100244 len = sizeof(MESSAGE) - 1;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200245
Gilles Peskine449bd832023-01-11 14:50:10 +0100246 do {
247 ret = mbedtls_ssl_write(&ssl, (unsigned char *) MESSAGE, len);
248 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
249 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200250
Gilles Peskine449bd832023-01-11 14:50:10 +0100251 if (ret < 0) {
252 mbedtls_printf(" failed\n ! mbedtls_ssl_write returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200253 goto exit;
254 }
255
256 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100257 mbedtls_printf(" %d bytes written\n\n%s\n\n", len, MESSAGE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200258
259 /*
260 * 7. Read the echo response
261 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100262 mbedtls_printf(" < Read from server:");
263 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200264
Gilles Peskine449bd832023-01-11 14:50:10 +0100265 len = sizeof(buf) - 1;
266 memset(buf, 0, sizeof(buf));
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200267
Gilles Peskine449bd832023-01-11 14:50:10 +0100268 do {
269 ret = mbedtls_ssl_read(&ssl, buf, len);
270 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
271 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200272
Gilles Peskine449bd832023-01-11 14:50:10 +0100273 if (ret <= 0) {
274 switch (ret) {
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100275 case MBEDTLS_ERR_SSL_TIMEOUT:
Gilles Peskine449bd832023-01-11 14:50:10 +0100276 mbedtls_printf(" timeout\n\n");
277 if (retry_left-- > 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200278 goto send_request;
Gilles Peskine449bd832023-01-11 14:50:10 +0100279 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200280 goto exit;
281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
Gilles Peskine449bd832023-01-11 14:50:10 +0100283 mbedtls_printf(" connection was closed gracefully\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200284 goto close_notify;
285
286 default:
Gilles Peskine449bd832023-01-11 14:50:10 +0100287 mbedtls_printf(" mbedtls_ssl_read returned -0x%x\n\n", (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200288 goto exit;
289 }
290 }
291
292 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100293 mbedtls_printf(" %d bytes read\n\n%s\n\n", len, buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200294
295 /*
296 * 8. Done, cleanly close the connection
297 */
298close_notify:
Gilles Peskine449bd832023-01-11 14:50:10 +0100299 mbedtls_printf(" . Closing the connection...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200300
301 /* No error checking, the connection might be closed already */
Gilles Peskine449bd832023-01-11 14:50:10 +0100302 do {
303 ret = mbedtls_ssl_close_notify(&ssl);
304 } while (ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200305 ret = 0;
306
Gilles Peskine449bd832023-01-11 14:50:10 +0100307 mbedtls_printf(" done\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200308
309 /*
310 * 9. Final clean-ups and exit
311 */
312exit:
313
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314#ifdef MBEDTLS_ERROR_C
Gilles Peskine449bd832023-01-11 14:50:10 +0100315 if (ret != 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200316 char error_buf[100];
Gilles Peskine449bd832023-01-11 14:50:10 +0100317 mbedtls_strerror(ret, error_buf, 100);
318 mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200319 }
320#endif
321
Gilles Peskine449bd832023-01-11 14:50:10 +0100322 mbedtls_net_free(&server_fd);
Gilles Peskine449bd832023-01-11 14:50:10 +0100323 mbedtls_x509_crt_free(&cacert);
324 mbedtls_ssl_free(&ssl);
325 mbedtls_ssl_config_free(&conf);
326 mbedtls_ctr_drbg_free(&ctr_drbg);
327 mbedtls_entropy_free(&entropy);
Przemek Stekiel758aef62023-04-19 13:47:43 +0200328#if defined(MBEDTLS_USE_PSA_CRYPTO)
Przemek Stekiela8c560a2023-04-19 10:15:26 +0200329 mbedtls_psa_crypto_free();
Przemek Stekiel758aef62023-04-19 13:47:43 +0200330#endif /* MBEDTLS_USE_PSA_CRYPTO */
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200331
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200332 /* Shell can not handle large exit numbers -> 1 for errors */
Gilles Peskine449bd832023-01-11 14:50:10 +0100333 if (ret < 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200334 ret = 1;
Gilles Peskine449bd832023-01-11 14:50:10 +0100335 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200336
Gilles Peskine449bd832023-01-11 14:50:10 +0100337 mbedtls_exit(ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200338}
Gilles Peskineae710c82024-09-04 16:07:56 +0200339
340#endif /* configuration allows running this program */