blob: 4f82283575eadc75981af1e75ad145e1f890b3b2 [file] [log] [blame]
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +02001/*
2 * Simple DTLS client demonstration program
3 *
4 * Copyright (C) 2014, Brainspark B.V.
5 *
Manuel Pégourié-Gonnarde4d48902015-03-06 13:40:52 +00006 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000024#include "mbedtls/config.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020025#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020027#endif
28
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/platform.h"
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000031#else
Manuel Pégourié-Gonnard4b3e5ef2015-03-27 11:24:27 +010032#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#define mbedtls_printf printf
34#define mbedtls_fprintf fprintf
Manuel Pégourié-Gonnardf2246782015-01-29 13:29:20 +000035#endif
36
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#if !defined(MBEDTLS_SSL_CLI_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
38 !defined(MBEDTLS_NET_C) || \
39 !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
40 !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_RSA_C) || \
41 !defined(MBEDTLS_CERTS_C)
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020042
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020043int main( int argc, char *argv[] )
44{
45 ((void) argc);
46 ((void) argv);
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048 mbedtls_printf( "MBEDTLS_SSL_CLI_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
49 "MBEDTLS_NET_C and/or "
50 "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
51 "MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_RSA_C and/or "
52 "MBEDTLS_CERTS_C and/or MBEDTLS_PEM_PARSE_C not defined.\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020053 return( 0 );
54}
55#else
56
57#include <string.h>
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020058
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000059#include "mbedtls/net.h"
60#include "mbedtls/debug.h"
61#include "mbedtls/ssl.h"
62#include "mbedtls/entropy.h"
63#include "mbedtls/ctr_drbg.h"
64#include "mbedtls/error.h"
65#include "mbedtls/certs.h"
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020066
67#define SERVER_PORT 4433
68#define SERVER_NAME "localhost"
69#define SERVER_ADDR "127.0.0.1" /* forces IPv4 */
70#define MESSAGE "Echo this"
71
72#define READ_TIMEOUT_MS 1000
73#define MAX_RETRY 5
74
75#define DEBUG_LEVEL 0
76
77static void my_debug( void *ctx, int level, const char *str )
78{
79 ((void) level);
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081 mbedtls_fprintf( (FILE *) ctx, "%s", str );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020082 fflush( (FILE *) ctx );
83}
84
85int main( int argc, char *argv[] )
86{
87 int ret, len, server_fd = -1;
88 unsigned char buf[1024];
89 const char *pers = "dtls_client";
90 int retry_left = MAX_RETRY;
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092 mbedtls_entropy_context entropy;
93 mbedtls_ctr_drbg_context ctr_drbg;
94 mbedtls_ssl_context ssl;
95 mbedtls_x509_crt cacert;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020096
97 ((void) argc);
98 ((void) argv);
99
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_DEBUG_C)
101 mbedtls_debug_set_threshold( DEBUG_LEVEL );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200102#endif
103
104 /*
105 * 0. Initialize the RNG and the session data
106 */
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200107 mbedtls_ssl_init( &ssl );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108 mbedtls_x509_crt_init( &cacert );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200109 mbedtls_ctr_drbg_init( &ctr_drbg );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111 mbedtls_printf( "\n . Seeding the random number generator..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200112 fflush( stdout );
113
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 mbedtls_entropy_init( &entropy );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200115 if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200116 (const unsigned char *) pers,
117 strlen( pers ) ) ) != 0 )
118 {
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200119 mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200120 goto exit;
121 }
122
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200124
125 /*
126 * 0. Initialize certificates
127 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128 mbedtls_printf( " . Loading the CA root certificate ..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200129 fflush( stdout );
130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
132 mbedtls_test_cas_pem_len );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200133 if( ret < 0 )
134 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135 mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200136 goto exit;
137 }
138
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 mbedtls_printf( " ok (%d skipped)\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200140
141 /*
142 * 1. Start the connection
143 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144 mbedtls_printf( " . Connecting to udp/%s/%4d...", SERVER_NAME,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200145 SERVER_PORT );
146 fflush( stdout );
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 if( ( ret = mbedtls_net_connect( &server_fd, SERVER_ADDR,
149 SERVER_PORT, MBEDTLS_NET_PROTO_UDP ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200150 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151 mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200152 goto exit;
153 }
154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200156
157 /*
158 * 2. Setup stuff
159 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160 mbedtls_printf( " . Setting up the DTLS structure..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200161 fflush( stdout );
162
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200163 if( ( ret = mbedtls_ssl_setup( &ssl ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200164 {
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200165 mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200166 goto exit;
167 }
168
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200169 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200170
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171 mbedtls_ssl_set_endpoint( &ssl, MBEDTLS_SSL_IS_CLIENT );
172 mbedtls_ssl_set_transport( &ssl, MBEDTLS_SSL_TRANSPORT_DATAGRAM );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200173
174 /* OPTIONAL is usually a bad choice for security, but makes interop easier
175 * in this simplified example, in which the ca chain is hardcoded.
176 * Production code should set a proper ca chain and use REQUIRED. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177 mbedtls_ssl_set_authmode( &ssl, MBEDTLS_SSL_VERIFY_OPTIONAL );
178 mbedtls_ssl_set_ca_chain( &ssl, &cacert, NULL, SERVER_NAME );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200179
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180 mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
181 mbedtls_ssl_set_dbg( &ssl, my_debug, stdout );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183 mbedtls_ssl_set_bio_timeout( &ssl, &server_fd,
184 mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200185 READ_TIMEOUT_MS );
186
187 /*
188 * 4. Handshake
189 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190 mbedtls_printf( " . Performing the SSL/TLS handshake..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200191 fflush( stdout );
192
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193 do ret = mbedtls_ssl_handshake( &ssl );
194 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
195 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200196
197 if( ret != 0 )
198 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199 mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200200 goto exit;
201 }
202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200204
205 /*
206 * 5. Verify the server certificate
207 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208 mbedtls_printf( " . Verifying peer X.509 certificate..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200209
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 /* In real life, we would have used MBEDTLS_SSL_VERIFY_REQUIRED so that the
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200211 * handshake would not succeed if the peer's cert is bad. Even if we used
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200212 * MBEDTLS_SSL_VERIFY_OPTIONAL, we would bail out here if ret != 0 */
213 if( ( ret = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200214 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215 mbedtls_printf( " failed\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200216
Manuel Pégourié-Gonnarde6028c92015-04-20 12:19:02 +0100217 if( ( ret & MBEDTLS_X509_BADCERT_EXPIRED ) != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 mbedtls_printf( " ! server certificate has expired\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200219
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220 if( ( ret & MBEDTLS_X509_BADCERT_REVOKED ) != 0 )
221 mbedtls_printf( " ! server certificate has been revoked\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200222
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223 if( ( ret & MBEDTLS_X509_BADCERT_CN_MISMATCH ) != 0 )
224 mbedtls_printf( " ! CN mismatch (expected CN=%s)\n", SERVER_NAME );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 if( ( ret & MBEDTLS_X509_BADCERT_NOT_TRUSTED ) != 0 )
227 mbedtls_printf( " ! self-signed or not signed by a trusted CA\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200228
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229 mbedtls_printf( "\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200230 }
231 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200233
234 /*
235 * 6. Write the echo request
236 */
237send_request:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238 mbedtls_printf( " > Write to server:" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200239 fflush( stdout );
240
241 len = sizeof( MESSAGE ) - 1;
242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243 do ret = mbedtls_ssl_write( &ssl, (unsigned char *) MESSAGE, len );
244 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
245 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200246
247 if( ret < 0 )
248 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249 mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200250 goto exit;
251 }
252
253 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254 mbedtls_printf( " %d bytes written\n\n%s\n\n", len, MESSAGE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200255
256 /*
257 * 7. Read the echo response
258 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259 mbedtls_printf( " < Read from server:" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200260 fflush( stdout );
261
262 len = sizeof( buf ) - 1;
263 memset( buf, 0, sizeof( buf ) );
264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265 do ret = mbedtls_ssl_read( &ssl, buf, len );
266 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
267 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200268
269 if( ret <= 0 )
270 {
271 switch( ret )
272 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 case MBEDTLS_ERR_NET_TIMEOUT:
274 mbedtls_printf( " timeout\n\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200275 if( retry_left-- > 0 )
276 goto send_request;
277 goto exit;
278
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
280 mbedtls_printf( " connection was closed gracefully\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200281 ret = 0;
282 goto close_notify;
283
284 default:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285 mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200286 goto exit;
287 }
288 }
289
290 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291 mbedtls_printf( " %d bytes read\n\n%s\n\n", len, buf );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200292
293 /*
294 * 8. Done, cleanly close the connection
295 */
296close_notify:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297 mbedtls_printf( " . Closing the connection..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200298
299 /* No error checking, the connection might be closed already */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300 do ret = mbedtls_ssl_close_notify( &ssl );
301 while( ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200302 ret = 0;
303
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304 mbedtls_printf( " done\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200305
306 /*
307 * 9. Final clean-ups and exit
308 */
309exit:
310
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200311#ifdef MBEDTLS_ERROR_C
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200312 if( ret != 0 )
313 {
314 char error_buf[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315 mbedtls_strerror( ret, error_buf, 100 );
316 mbedtls_printf( "Last error was: %d - %s\n\n", ret, error_buf );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200317 }
318#endif
319
320 if( server_fd != -1 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321 mbedtls_net_close( server_fd );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323 mbedtls_x509_crt_free( &cacert );
324 mbedtls_ssl_free( &ssl );
325 mbedtls_ctr_drbg_free( &ctr_drbg );
326 mbedtls_entropy_free( &entropy );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200327
328#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 mbedtls_printf( " + Press Enter to exit this program.\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200330 fflush( stdout ); getchar();
331#endif
332
333 /* Shell can not handle large exit numbers -> 1 for errors */
334 if( ret < 0 )
335 ret = 1;
336
337 return( ret );
338}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_PROTO_DTLS && MBEDTLS_NET_C &&
340 MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
341 MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C && MBEDTLS_CERTS_C &&
342 MBEDTLS_PEM_PARSE_C */