blob: 3f7256fa830ec8e9d5c8083c59cbf528730ca8c2 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * SSL client demonstration program
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000018 */
19
Bence Szépkútic662b362021-05-27 11:25:03 +020020#include "mbedtls/build_info.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000021
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000023#include "mbedtls/platform.h"
Rich Evansf90016a2015-01-19 14:26:37 +000024#else
Rich Evans18b78c72015-02-11 14:06:19 +000025#include <stdio.h>
Simon Butcherd3138c32016-04-27 01:26:50 +010026#include <stdlib.h>
Andres Amaya Garcia55172022018-04-29 20:53:53 +010027#define mbedtls_time time
28#define mbedtls_time_t time_t
29#define mbedtls_fprintf fprintf
30#define mbedtls_printf printf
Manuel Pégourié-Gonnard3ef6a6d2018-12-10 14:31:45 +010031#define mbedtls_exit exit
Andres Amaya Garcia7d429652018-04-30 22:42:33 +010032#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
Andres Amaya Garcia55172022018-04-29 20:53:53 +010033#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
34#endif /* MBEDTLS_PLATFORM_C */
Rich Evansf90016a2015-01-19 14:26:37 +000035
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010036#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
37 !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
38 !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
39 !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
40 !defined(MBEDTLS_X509_CRT_PARSE_C)
Rich Evans85b05ec2015-02-12 11:37:29 +000041int main( void )
Paul Bakker5690efc2011-05-26 13:16:06 +000042{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043 mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
44 "MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
45 "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
46 "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
Paul Bakkered27a042013-04-18 22:46:23 +020047 "not defined.\n");
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +020048 mbedtls_exit( 0 );
Paul Bakker5690efc2011-05-26 13:16:06 +000049}
50#else
Manuel Pégourié-Gonnard4b3e5ef2015-03-27 11:24:27 +010051
Andres AG788aa4a2016-09-14 14:32:09 +010052#include "mbedtls/net_sockets.h"
Manuel Pégourié-Gonnard4b3e5ef2015-03-27 11:24:27 +010053#include "mbedtls/debug.h"
54#include "mbedtls/ssl.h"
55#include "mbedtls/entropy.h"
56#include "mbedtls/ctr_drbg.h"
57#include "mbedtls/error.h"
Mateusz Starzyk1aec6462021-02-08 15:34:42 +010058#include "test/certs.h"
Manuel Pégourié-Gonnard4b3e5ef2015-03-27 11:24:27 +010059
60#include <string.h>
61
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +020062#define SERVER_PORT "4433"
Manuel Pégourié-Gonnard4b3e5ef2015-03-27 11:24:27 +010063#define SERVER_NAME "localhost"
64#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
65
66#define DEBUG_LEVEL 1
67
Simon Butcher63cb97e2018-12-06 17:43:31 +000068
Manuel Pégourié-Gonnard61ee3512015-06-23 17:35:03 +020069static void my_debug( void *ctx, int level,
70 const char *file, int line,
71 const char *str )
Paul Bakker9a97c5d2013-09-15 17:07:33 +020072{
Paul Bakkerc73079a2014-04-25 16:34:30 +020073 ((void) level);
74
Manuel Pégourié-Gonnard61ee3512015-06-23 17:35:03 +020075 mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
Paul Bakkerc73079a2014-04-25 16:34:30 +020076 fflush( (FILE *) ctx );
Paul Bakker9a97c5d2013-09-15 17:07:33 +020077}
78
Rich Evans85b05ec2015-02-12 11:37:29 +000079int main( void )
Paul Bakker5121ce52009-01-03 21:22:43 +000080{
Andres Amaya Garcia55172022018-04-29 20:53:53 +010081 int ret = 1, len;
82 int exit_code = MBEDTLS_EXIT_FAILURE;
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +020083 mbedtls_net_context server_fd;
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +020084 uint32_t flags;
Paul Bakker5121ce52009-01-03 21:22:43 +000085 unsigned char buf[1024];
Paul Bakkeref3f8c72013-06-24 13:01:08 +020086 const char *pers = "ssl_client1";
Paul Bakker508ad5a2011-12-04 17:09:26 +000087
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088 mbedtls_entropy_context entropy;
89 mbedtls_ctr_drbg_context ctr_drbg;
90 mbedtls_ssl_context ssl;
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +020091 mbedtls_ssl_config conf;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092 mbedtls_x509_crt cacert;
Paul Bakker5121ce52009-01-03 21:22:43 +000093
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094#if defined(MBEDTLS_DEBUG_C)
95 mbedtls_debug_set_threshold( DEBUG_LEVEL );
Paul Bakkerc73079a2014-04-25 16:34:30 +020096#endif
97
Paul Bakker5121ce52009-01-03 21:22:43 +000098 /*
99 * 0. Initialize the RNG and the session data
100 */
Manuel Pégourié-Gonnard5db64322015-06-30 15:40:39 +0200101 mbedtls_net_init( &server_fd );
Manuel Pégourié-Gonnard41d479e2015-04-29 00:48:22 +0200102 mbedtls_ssl_init( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200103 mbedtls_ssl_config_init( &conf );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104 mbedtls_x509_crt_init( &cacert );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200105 mbedtls_ctr_drbg_init( &ctr_drbg );
Paul Bakker5121ce52009-01-03 21:22:43 +0000106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107 mbedtls_printf( "\n . Seeding the random number generator..." );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000108 fflush( stdout );
109
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110 mbedtls_entropy_init( &entropy );
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200111 if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200112 (const unsigned char *) pers,
113 strlen( pers ) ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000114 {
Manuel Pégourié-Gonnardec160c02015-04-28 22:52:30 +0200115 mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000116 goto exit;
117 }
118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119 mbedtls_printf( " ok\n" );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000120
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 /*
Paul Bakker75242c32012-11-17 00:03:46 +0100122 * 0. Initialize certificates
123 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124 mbedtls_printf( " . Loading the CA root certificate ..." );
Paul Bakker75242c32012-11-17 00:03:46 +0100125 fflush( stdout );
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
128 mbedtls_test_cas_pem_len );
Paul Bakker75242c32012-11-17 00:03:46 +0100129 if( ret < 0 )
130 {
Kenneth Soerensen518d4352020-04-01 17:22:45 +0200131 mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", (unsigned int) -ret );
Paul Bakker75242c32012-11-17 00:03:46 +0100132 goto exit;
133 }
134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135 mbedtls_printf( " ok (%d skipped)\n", ret );
Paul Bakker75242c32012-11-17 00:03:46 +0100136
137 /*
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 * 1. Start the connection
139 */
Manuel Pégourié-Gonnardc0d74942015-06-23 12:30:57 +0200140 mbedtls_printf( " . Connecting to tcp/%s/%s...", SERVER_NAME, SERVER_PORT );
Paul Bakker5121ce52009-01-03 21:22:43 +0000141 fflush( stdout );
142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143 if( ( ret = mbedtls_net_connect( &server_fd, SERVER_NAME,
144 SERVER_PORT, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000145 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000147 goto exit;
148 }
149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 mbedtls_printf( " ok\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000151
152 /*
153 * 2. Setup stuff
154 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155 mbedtls_printf( " . Setting up the SSL/TLS structure..." );
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 fflush( stdout );
157
Manuel Pégourié-Gonnard419d5ae2015-05-04 19:32:36 +0200158 if( ( ret = mbedtls_ssl_config_defaults( &conf,
159 MBEDTLS_SSL_IS_CLIENT,
Manuel Pégourié-Gonnardb31c5f62015-06-17 13:53:47 +0200160 MBEDTLS_SSL_TRANSPORT_STREAM,
161 MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200162 {
163 mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
164 goto exit;
165 }
166
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167 mbedtls_printf( " ok\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000168
Manuel Pégourié-Gonnardfcf2fc22014-03-11 11:10:27 +0100169 /* OPTIONAL is not optimal for security,
170 * but makes interop easier in this simplified example */
Manuel Pégourié-Gonnard6729e792015-05-11 09:50:24 +0200171 mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
172 mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
Manuel Pégourié-Gonnard06939ce2015-05-11 11:25:46 +0200173 mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
174 mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
175
176 if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
177 {
178 mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
179 goto exit;
180 }
181
Paul Bakker23828162016-07-22 11:54:30 +0100182 if( ( ret = mbedtls_ssl_set_hostname( &ssl, SERVER_NAME ) ) != 0 )
Manuel Pégourié-Gonnardbc2b7712015-05-06 11:14:19 +0100183 {
184 mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
185 goto exit;
186 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000187
Manuel Pégourié-Gonnard1b511f92015-05-06 15:54:23 +0100188 mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000189
Paul Bakker5121ce52009-01-03 21:22:43 +0000190 /*
Paul Bakker75242c32012-11-17 00:03:46 +0100191 * 4. Handshake
192 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193 mbedtls_printf( " . Performing the SSL/TLS handshake..." );
Paul Bakker75242c32012-11-17 00:03:46 +0100194 fflush( stdout );
195
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196 while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
Paul Bakker75242c32012-11-17 00:03:46 +0100197 {
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100198 if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
Paul Bakker75242c32012-11-17 00:03:46 +0100199 {
Kenneth Soerensen518d4352020-04-01 17:22:45 +0200200 mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret );
Paul Bakker75242c32012-11-17 00:03:46 +0100201 goto exit;
202 }
203 }
204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205 mbedtls_printf( " ok\n" );
Paul Bakker75242c32012-11-17 00:03:46 +0100206
207 /*
208 * 5. Verify the server certificate
209 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 mbedtls_printf( " . Verifying peer X.509 certificate..." );
Paul Bakker75242c32012-11-17 00:03:46 +0100211
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +0100212 /* In real life, we probably want to bail out when ret != 0 */
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200213 if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
Paul Bakker75242c32012-11-17 00:03:46 +0100214 {
Hanno Becker612a2f12020-10-09 09:19:39 +0100215#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +0100216 char vrfy_buf[512];
Peter Kolbus9a969b62018-12-11 13:55:56 -0600217#endif
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +0100218
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 mbedtls_printf( " failed\n" );
Paul Bakker75242c32012-11-17 00:03:46 +0100220
Hanno Becker612a2f12020-10-09 09:19:39 +0100221#if !defined(MBEDTLS_X509_REMOVE_INFO)
Manuel Pégourié-Gonnarde6ef16f2015-05-11 19:54:43 +0200222 mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );
Paul Bakker75242c32012-11-17 00:03:46 +0100223
Manuel Pégourié-Gonnard89addc42015-04-20 10:56:18 +0100224 mbedtls_printf( "%s\n", vrfy_buf );
Peter Kolbus9a969b62018-12-11 13:55:56 -0600225#endif
Paul Bakker75242c32012-11-17 00:03:46 +0100226 }
227 else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228 mbedtls_printf( " ok\n" );
Paul Bakker75242c32012-11-17 00:03:46 +0100229
230 /*
Paul Bakker5121ce52009-01-03 21:22:43 +0000231 * 3. Write the GET request
232 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233 mbedtls_printf( " > Write to server:" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000234 fflush( stdout );
235
236 len = sprintf( (char *) buf, GET_REQUEST );
237
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238 while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000239 {
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100240 if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000241 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242 mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000243 goto exit;
244 }
245 }
246
247 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248 mbedtls_printf( " %d bytes written\n\n%s", len, (char *) buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000249
250 /*
251 * 7. Read the HTTP response
252 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253 mbedtls_printf( " < Read from server:" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000254 fflush( stdout );
255
256 do
257 {
258 len = sizeof( buf ) - 1;
259 memset( buf, 0, sizeof( buf ) );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260 ret = mbedtls_ssl_read( &ssl, buf, len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000261
Manuel Pégourié-Gonnard88369942015-05-06 16:19:31 +0100262 if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000263 continue;
264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265 if( ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY )
Paul Bakker5121ce52009-01-03 21:22:43 +0000266 break;
267
Paul Bakker61da7522011-11-11 10:28:58 +0000268 if( ret < 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000269 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270 mbedtls_printf( "failed\n ! mbedtls_ssl_read returned %d\n\n", ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000271 break;
272 }
273
Paul Bakker61da7522011-11-11 10:28:58 +0000274 if( ret == 0 )
275 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200276 mbedtls_printf( "\n\nEOF\n\n" );
Paul Bakker61da7522011-11-11 10:28:58 +0000277 break;
278 }
279
Paul Bakker5121ce52009-01-03 21:22:43 +0000280 len = ret;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281 mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000282 }
Paul Bakker61da7522011-11-11 10:28:58 +0000283 while( 1 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000284
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200285 mbedtls_ssl_close_notify( &ssl );
Paul Bakker5121ce52009-01-03 21:22:43 +0000286
Andres Amaya Garcia55172022018-04-29 20:53:53 +0100287 exit_code = MBEDTLS_EXIT_SUCCESS;
288
Paul Bakker5121ce52009-01-03 21:22:43 +0000289exit:
290
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291#ifdef MBEDTLS_ERROR_C
Andres Amaya Garcia55172022018-04-29 20:53:53 +0100292 if( exit_code != MBEDTLS_EXIT_SUCCESS )
Paul Bakkera3d195c2011-11-27 21:07:34 +0000293 {
294 char error_buf[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295 mbedtls_strerror( ret, error_buf, 100 );
296 mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000297 }
298#endif
299
Manuel Pégourié-Gonnard3d7d00a2015-06-30 15:55:03 +0200300 mbedtls_net_free( &server_fd );
Paul Bakker0c226102014-04-17 16:02:36 +0200301
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 mbedtls_x509_crt_free( &cacert );
303 mbedtls_ssl_free( &ssl );
Manuel Pégourié-Gonnarddef0bbe2015-05-04 14:56:36 +0200304 mbedtls_ssl_config_free( &conf );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305 mbedtls_ctr_drbg_free( &ctr_drbg );
306 mbedtls_entropy_free( &entropy );
Paul Bakker5121ce52009-01-03 21:22:43 +0000307
Paul Bakkercce9d772011-11-18 14:26:47 +0000308#if defined(_WIN32)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309 mbedtls_printf( " + Press Enter to exit this program.\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000310 fflush( stdout ); getchar();
311#endif
312
Krzysztof Stachowiak5e1b1952019-04-24 14:24:46 +0200313 mbedtls_exit( exit_code );
Paul Bakker5121ce52009-01-03 21:22:43 +0000314}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
316 MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
Mateusz Starzyk1aec6462021-02-08 15:34:42 +0100317 MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_X509_CRT_PARSE_C */