blob: 26eb20d49fd6e27f19b911c54abefb03401339c1 [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
Felix Conway998760a2025-03-24 11:37:33 +00008#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
9
Bence Szépkútic662b362021-05-27 11:25:03 +020010#include "mbedtls/build_info.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020011
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000012#include "mbedtls/platform.h"
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000013
Gilles Peskineae710c82024-09-04 16:07:56 +020014#if !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
15 !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_CLI_C) || \
16 !defined(MBEDTLS_TIMING_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
17 !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010018int main(void)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020019{
Gilles Peskineae710c82024-09-04 16:07:56 +020020 mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
21 "MBEDTLS_NET_C and/or MBEDTLS_SSL_CLI_C and/or "
22 "MBEDTLS_TIMING_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
23 "MBEDTLS_PEM_PARSE_C and/or MBEDTLS_X509_CRT_PARSE_C "
24 "not defined.\n");
Gilles Peskine449bd832023-01-11 14:50:10 +010025 mbedtls_exit(0);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020026}
27#else
28
29#include <string.h>
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020030
Andres AG788aa4a2016-09-14 14:32:09 +010031#include "mbedtls/net_sockets.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000032#include "mbedtls/debug.h"
33#include "mbedtls/ssl.h"
34#include "mbedtls/entropy.h"
35#include "mbedtls/ctr_drbg.h"
36#include "mbedtls/error.h"
Manuel Pégourié-Gonnard56273da2015-05-26 12:19:45 +020037#include "mbedtls/timing.h"
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010038#include "test/certs.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020039
Simon Butcher6fd96ad2018-05-12 18:23:32 +010040/* Uncomment out the following line to default to IPv4 and disable IPv6 */
41//#define FORCE_IPV4
42
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +020043#define SERVER_PORT "4433"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020044#define SERVER_NAME "localhost"
Simon Butcher6fd96ad2018-05-12 18:23:32 +010045
46#ifdef FORCE_IPV4
47#define SERVER_ADDR "127.0.0.1" /* Forces IPv4 */
48#else
Gilles Peskine6e3de212024-09-05 14:51:58 +020049#define SERVER_ADDR SERVER_NAME
Simon Butcher6fd96ad2018-05-12 18:23:32 +010050#endif
51
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020052#define MESSAGE "Echo this"
53
54#define READ_TIMEOUT_MS 1000
55#define MAX_RETRY 5
56
57#define DEBUG_LEVEL 0
58
Simon Butcher63cb97e2018-12-06 17:43:31 +000059
Gilles Peskine449bd832023-01-11 14:50:10 +010060static void my_debug(void *ctx, int level,
61 const char *file, int line,
62 const char *str)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020063{
64 ((void) level);
65
Gilles Peskine449bd832023-01-11 14:50:10 +010066 mbedtls_fprintf((FILE *) ctx, "%s:%04d: %s", file, line, str);
67 fflush((FILE *) ctx);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020068}
69
Gilles Peskine449bd832023-01-11 14:50:10 +010070int main(int argc, char *argv[])
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020071{
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +020072 int ret, len;
73 mbedtls_net_context server_fd;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020074 uint32_t flags;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020075 unsigned char buf[1024];
76 const char *pers = "dtls_client";
77 int retry_left = MAX_RETRY;
78
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079 mbedtls_entropy_context entropy;
80 mbedtls_ctr_drbg_context ctr_drbg;
81 mbedtls_ssl_context ssl;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +020082 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083 mbedtls_x509_crt cacert;
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +020084 mbedtls_timing_delay_context timer;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020085
86 ((void) argc);
87 ((void) argv);
88
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#if defined(MBEDTLS_DEBUG_C)
Gilles Peskine449bd832023-01-11 14:50:10 +010090 mbedtls_debug_set_threshold(DEBUG_LEVEL);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020091#endif
92
93 /*
94 * 0. Initialize the RNG and the session data
95 */
Gilles Peskine449bd832023-01-11 14:50:10 +010096 mbedtls_net_init(&server_fd);
97 mbedtls_ssl_init(&ssl);
98 mbedtls_ssl_config_init(&conf);
99 mbedtls_x509_crt_init(&cacert);
100 mbedtls_ctr_drbg_init(&ctr_drbg);
Przemek Stekiela0a1c1e2023-04-17 11:10:05 +0200101 mbedtls_entropy_init(&entropy);
102
Przemek Stekiela0a1c1e2023-04-17 11:10:05 +0200103 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 }
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);
Gilles Peskine449bd832023-01-11 14:50:10 +0100172 mbedtls_ssl_conf_dbg(&conf, my_debug, stdout);
173 mbedtls_ssl_conf_read_timeout(&conf, READ_TIMEOUT_MS);
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200174
Gilles Peskine449bd832023-01-11 14:50:10 +0100175 if ((ret = mbedtls_ssl_setup(&ssl, &conf)) != 0) {
176 mbedtls_printf(" failed\n ! mbedtls_ssl_setup returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200177 goto exit;
178 }
179
Gilles Peskine449bd832023-01-11 14:50:10 +0100180 if ((ret = mbedtls_ssl_set_hostname(&ssl, SERVER_NAME)) != 0) {
181 mbedtls_printf(" failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret);
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100182 goto exit;
183 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200184
Gilles Peskine449bd832023-01-11 14:50:10 +0100185 mbedtls_ssl_set_bio(&ssl, &server_fd,
186 mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200187
Gilles Peskine449bd832023-01-11 14:50:10 +0100188 mbedtls_ssl_set_timer_cb(&ssl, &timer, mbedtls_timing_set_delay,
189 mbedtls_timing_get_delay);
Manuel Pégourié-Gonnarde3c41ad2015-05-13 10:04:32 +0200190
Gilles Peskine449bd832023-01-11 14:50:10 +0100191 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100192
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200193 /*
194 * 4. Handshake
195 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100196 mbedtls_printf(" . Performing the DTLS handshake...");
197 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200198
Gilles Peskine449bd832023-01-11 14:50:10 +0100199 do {
200 ret = mbedtls_ssl_handshake(&ssl);
201 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
202 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200203
Gilles Peskine449bd832023-01-11 14:50:10 +0100204 if (ret != 0) {
205 mbedtls_printf(" failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n",
206 (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200207 goto exit;
208 }
209
Gilles Peskine449bd832023-01-11 14:50:10 +0100210 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200211
212 /*
213 * 5. Verify the server certificate
214 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100215 mbedtls_printf(" . Verifying peer X.509 certificate...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200216
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217 /* In real life, we would have used MBEDTLS_SSL_VERIFY_REQUIRED so that the
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200218 * handshake would not succeed if the peer's cert is bad. Even if we used
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 * MBEDTLS_SSL_VERIFY_OPTIONAL, we would bail out here if ret != 0 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100220 if ((flags = mbedtls_ssl_get_verify_result(&ssl)) != 0) {
Hanno Becker612a2f12020-10-09 09:19:39 +0100221#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200222 char vrfy_buf[512];
Peter Kolbus9a969b62018-12-11 13:55:56 -0600223#endif
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200224
Gilles Peskine449bd832023-01-11 14:50:10 +0100225 mbedtls_printf(" failed\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200226
Hanno Becker612a2f12020-10-09 09:19:39 +0100227#if !defined(MBEDTLS_X509_REMOVE_INFO)
Gilles Peskine449bd832023-01-11 14:50:10 +0100228 mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), " ! ", flags);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200229
Gilles Peskine449bd832023-01-11 14:50:10 +0100230 mbedtls_printf("%s\n", vrfy_buf);
Peter Kolbus9a969b62018-12-11 13:55:56 -0600231#endif
Gilles Peskine449bd832023-01-11 14:50:10 +0100232 } else {
233 mbedtls_printf(" ok\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200234 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200235
236 /*
237 * 6. Write the echo request
238 */
239send_request:
Gilles Peskine449bd832023-01-11 14:50:10 +0100240 mbedtls_printf(" > Write to server:");
241 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200242
Gilles Peskine449bd832023-01-11 14:50:10 +0100243 len = sizeof(MESSAGE) - 1;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200244
Gilles Peskine449bd832023-01-11 14:50:10 +0100245 do {
246 ret = mbedtls_ssl_write(&ssl, (unsigned char *) MESSAGE, len);
247 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
248 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200249
Gilles Peskine449bd832023-01-11 14:50:10 +0100250 if (ret < 0) {
251 mbedtls_printf(" failed\n ! mbedtls_ssl_write returned %d\n\n", ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200252 goto exit;
253 }
254
255 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100256 mbedtls_printf(" %d bytes written\n\n%s\n\n", len, MESSAGE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200257
258 /*
259 * 7. Read the echo response
260 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100261 mbedtls_printf(" < Read from server:");
262 fflush(stdout);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200263
Gilles Peskine449bd832023-01-11 14:50:10 +0100264 len = sizeof(buf) - 1;
265 memset(buf, 0, sizeof(buf));
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200266
Gilles Peskine449bd832023-01-11 14:50:10 +0100267 do {
268 ret = mbedtls_ssl_read(&ssl, buf, len);
269 } while (ret == MBEDTLS_ERR_SSL_WANT_READ ||
270 ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200271
Gilles Peskine449bd832023-01-11 14:50:10 +0100272 if (ret <= 0) {
273 switch (ret) {
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100274 case MBEDTLS_ERR_SSL_TIMEOUT:
Gilles Peskine449bd832023-01-11 14:50:10 +0100275 mbedtls_printf(" timeout\n\n");
276 if (retry_left-- > 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200277 goto send_request;
Gilles Peskine449bd832023-01-11 14:50:10 +0100278 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200279 goto exit;
280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
Gilles Peskine449bd832023-01-11 14:50:10 +0100282 mbedtls_printf(" connection was closed gracefully\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200283 goto close_notify;
284
285 default:
Gilles Peskine449bd832023-01-11 14:50:10 +0100286 mbedtls_printf(" mbedtls_ssl_read returned -0x%x\n\n", (unsigned int) -ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200287 goto exit;
288 }
289 }
290
291 len = ret;
Gilles Peskine449bd832023-01-11 14:50:10 +0100292 mbedtls_printf(" %d bytes read\n\n%s\n\n", len, buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200293
294 /*
295 * 8. Done, cleanly close the connection
296 */
297close_notify:
Gilles Peskine449bd832023-01-11 14:50:10 +0100298 mbedtls_printf(" . Closing the connection...");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200299
300 /* No error checking, the connection might be closed already */
Gilles Peskine449bd832023-01-11 14:50:10 +0100301 do {
302 ret = mbedtls_ssl_close_notify(&ssl);
303 } while (ret == MBEDTLS_ERR_SSL_WANT_WRITE);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200304 ret = 0;
305
Gilles Peskine449bd832023-01-11 14:50:10 +0100306 mbedtls_printf(" done\n");
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200307
308 /*
309 * 9. Final clean-ups and exit
310 */
311exit:
312
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313#ifdef MBEDTLS_ERROR_C
Gilles Peskine449bd832023-01-11 14:50:10 +0100314 if (ret != 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200315 char error_buf[100];
Gilles Peskine449bd832023-01-11 14:50:10 +0100316 mbedtls_strerror(ret, error_buf, 100);
317 mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200318 }
319#endif
320
Gilles Peskine449bd832023-01-11 14:50:10 +0100321 mbedtls_net_free(&server_fd);
Gilles Peskine449bd832023-01-11 14:50:10 +0100322 mbedtls_x509_crt_free(&cacert);
323 mbedtls_ssl_free(&ssl);
324 mbedtls_ssl_config_free(&conf);
325 mbedtls_ctr_drbg_free(&ctr_drbg);
326 mbedtls_entropy_free(&entropy);
Przemek Stekiela8c560a2023-04-19 10:15:26 +0200327 mbedtls_psa_crypto_free();
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200328
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200329 /* Shell can not handle large exit numbers -> 1 for errors */
Gilles Peskine449bd832023-01-11 14:50:10 +0100330 if (ret < 0) {
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200331 ret = 1;
Gilles Peskine449bd832023-01-11 14:50:10 +0100332 }
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200333
Gilles Peskine449bd832023-01-11 14:50:10 +0100334 mbedtls_exit(ret);
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200335}
Gilles Peskineae710c82024-09-04 16:07:56 +0200336
337#endif /* configuration allows running this program */