blob: cacfe0f21e163fd92cfa468cf6699e56605f1c7c [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;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +020095 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096 mbedtls_x509_crt cacert;
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +020097
98 ((void) argc);
99 ((void) argv);
100
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101#if defined(MBEDTLS_DEBUG_C)
102 mbedtls_debug_set_threshold( DEBUG_LEVEL );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200103#endif
104
105 /*
106 * 0. Initialize the RNG and the session data
107 */
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200108 mbedtls_ssl_init( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200109 mbedtls_ssl_config_init( &conf );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110 mbedtls_x509_crt_init( &cacert );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200111 mbedtls_ctr_drbg_init( &ctr_drbg );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113 mbedtls_printf( "\n . Seeding the random number generator..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200114 fflush( stdout );
115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116 mbedtls_entropy_init( &entropy );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200117 if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200118 (const unsigned char *) pers,
119 strlen( pers ) ) ) != 0 )
120 {
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200121 mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200122 goto exit;
123 }
124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200126
127 /*
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200128 * 0. Load certificates
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200129 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 mbedtls_printf( " . Loading the CA root certificate ..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200131 fflush( stdout );
132
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133 ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
134 mbedtls_test_cas_pem_len );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200135 if( ret < 0 )
136 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137 mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200138 goto exit;
139 }
140
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141 mbedtls_printf( " ok (%d skipped)\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200142
143 /*
144 * 1. Start the connection
145 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 mbedtls_printf( " . Connecting to udp/%s/%4d...", SERVER_NAME,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200147 SERVER_PORT );
148 fflush( stdout );
149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 if( ( ret = mbedtls_net_connect( &server_fd, SERVER_ADDR,
151 SERVER_PORT, MBEDTLS_NET_PROTO_UDP ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200152 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153 mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200154 goto exit;
155 }
156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200157 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200158
159 /*
160 * 2. Setup stuff
161 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 mbedtls_printf( " . Setting up the DTLS structure..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200163 fflush( stdout );
164
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200165 if( ( ret = mbedtls_ssl_config_defaults( &conf ) ) != 0 )
166 {
167 mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
168 goto exit;
169 }
170
171 if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200172 {
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200173 mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200174 goto exit;
175 }
176
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200177 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200178
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179 mbedtls_ssl_set_endpoint( &ssl, MBEDTLS_SSL_IS_CLIENT );
180 mbedtls_ssl_set_transport( &ssl, MBEDTLS_SSL_TRANSPORT_DATAGRAM );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200181
182 /* OPTIONAL is usually a bad choice for security, but makes interop easier
183 * in this simplified example, in which the ca chain is hardcoded.
184 * Production code should set a proper ca chain and use REQUIRED. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185 mbedtls_ssl_set_authmode( &ssl, MBEDTLS_SSL_VERIFY_OPTIONAL );
186 mbedtls_ssl_set_ca_chain( &ssl, &cacert, NULL, SERVER_NAME );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200187
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188 mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
189 mbedtls_ssl_set_dbg( &ssl, my_debug, stdout );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200190
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191 mbedtls_ssl_set_bio_timeout( &ssl, &server_fd,
192 mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout,
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200193 READ_TIMEOUT_MS );
194
195 /*
196 * 4. Handshake
197 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198 mbedtls_printf( " . Performing the SSL/TLS handshake..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200199 fflush( stdout );
200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201 do ret = mbedtls_ssl_handshake( &ssl );
202 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
203 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200204
205 if( ret != 0 )
206 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200207 mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200208 goto exit;
209 }
210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200212
213 /*
214 * 5. Verify the server certificate
215 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216 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 */
221 if( ( ret = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200222 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223 mbedtls_printf( " failed\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200224
Manuel Pégourié-Gonnarde6028c92015-04-20 12:19:02 +0100225 if( ( ret & MBEDTLS_X509_BADCERT_EXPIRED ) != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 mbedtls_printf( " ! server certificate has expired\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 if( ( ret & MBEDTLS_X509_BADCERT_REVOKED ) != 0 )
229 mbedtls_printf( " ! server certificate has been revoked\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200231 if( ( ret & MBEDTLS_X509_BADCERT_CN_MISMATCH ) != 0 )
232 mbedtls_printf( " ! CN mismatch (expected CN=%s)\n", SERVER_NAME );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200233
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234 if( ( ret & MBEDTLS_X509_BADCERT_NOT_TRUSTED ) != 0 )
235 mbedtls_printf( " ! self-signed or not signed by a trusted CA\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200236
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200237 mbedtls_printf( "\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200238 }
239 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240 mbedtls_printf( " ok\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200241
242 /*
243 * 6. Write the echo request
244 */
245send_request:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246 mbedtls_printf( " > Write to server:" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200247 fflush( stdout );
248
249 len = sizeof( MESSAGE ) - 1;
250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251 do ret = mbedtls_ssl_write( &ssl, (unsigned char *) MESSAGE, len );
252 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
253 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200254
255 if( ret < 0 )
256 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257 mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200258 goto exit;
259 }
260
261 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262 mbedtls_printf( " %d bytes written\n\n%s\n\n", len, MESSAGE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200263
264 /*
265 * 7. Read the echo response
266 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267 mbedtls_printf( " < Read from server:" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200268 fflush( stdout );
269
270 len = sizeof( buf ) - 1;
271 memset( buf, 0, sizeof( buf ) );
272
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273 do ret = mbedtls_ssl_read( &ssl, buf, len );
274 while( ret == MBEDTLS_ERR_NET_WANT_READ ||
275 ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200276
277 if( ret <= 0 )
278 {
279 switch( ret )
280 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281 case MBEDTLS_ERR_NET_TIMEOUT:
282 mbedtls_printf( " timeout\n\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200283 if( retry_left-- > 0 )
284 goto send_request;
285 goto exit;
286
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200287 case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
288 mbedtls_printf( " connection was closed gracefully\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200289 ret = 0;
290 goto close_notify;
291
292 default:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293 mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n\n", -ret );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200294 goto exit;
295 }
296 }
297
298 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200299 mbedtls_printf( " %d bytes read\n\n%s\n\n", len, buf );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200300
301 /*
302 * 8. Done, cleanly close the connection
303 */
304close_notify:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305 mbedtls_printf( " . Closing the connection..." );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200306
307 /* No error checking, the connection might be closed already */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308 do ret = mbedtls_ssl_close_notify( &ssl );
309 while( ret == MBEDTLS_ERR_NET_WANT_WRITE );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200310 ret = 0;
311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312 mbedtls_printf( " done\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200313
314 /*
315 * 9. Final clean-ups and exit
316 */
317exit:
318
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319#ifdef MBEDTLS_ERROR_C
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200320 if( ret != 0 )
321 {
322 char error_buf[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323 mbedtls_strerror( ret, error_buf, 100 );
324 mbedtls_printf( "Last error was: %d - %s\n\n", ret, error_buf );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200325 }
326#endif
327
328 if( server_fd != -1 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 mbedtls_net_close( server_fd );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331 mbedtls_x509_crt_free( &cacert );
332 mbedtls_ssl_free( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200333 mbedtls_ssl_config_free( &conf );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200334 mbedtls_ctr_drbg_free( &ctr_drbg );
335 mbedtls_entropy_free( &entropy );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200336
337#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338 mbedtls_printf( " + Press Enter to exit this program.\n" );
Manuel Pégourié-Gonnarde63582a2014-10-14 11:47:21 +0200339 fflush( stdout ); getchar();
340#endif
341
342 /* Shell can not handle large exit numbers -> 1 for errors */
343 if( ret < 0 )
344 ret = 1;
345
346 return( ret );
347}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348#endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_PROTO_DTLS && MBEDTLS_NET_C &&
349 MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
350 MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C && MBEDTLS_CERTS_C &&
351 MBEDTLS_PEM_PARSE_C */