blob: 7813d41e31e1ed82d84feffa0fcee86879a5dc09 [file] [log] [blame]
Paul Bakker896ac222011-05-20 12:33:05 +00001/*
Paul Bakkercb79ae0b2011-05-20 12:44:16 +00002 * SSL server demonstration program using fork() for handling multiple clients
Paul Bakker896ac222011-05-20 12:33:05 +00003 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00004 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakker896ac222011-05-20 12:33:05 +00005 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00006 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker896ac222011-05-20 12:33:05 +00007 *
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é-Gonnardcef4ad22014-04-29 12:39:06 +020023#if !defined(POLARSSL_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000024#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020025#else
26#include POLARSSL_CONFIG_FILE
27#endif
Paul Bakker896ac222011-05-20 12:33:05 +000028
Rich Evansf90016a2015-01-19 14:26:37 +000029#if defined(POLARSSL_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000030#include "mbedtls/platform.h"
Rich Evansf90016a2015-01-19 14:26:37 +000031#else
Rich Evans18b78c72015-02-11 14:06:19 +000032#include <stdio.h>
Rich Evansf90016a2015-01-19 14:26:37 +000033#define polarssl_fprintf fprintf
Rich Evans18b78c72015-02-11 14:06:19 +000034#define polarssl_printf printf
Rich Evansf90016a2015-01-19 14:26:37 +000035#endif
36
Paul Bakkercce9d772011-11-18 14:26:47 +000037#if defined(_WIN32)
Paul Bakker896ac222011-05-20 12:33:05 +000038#include <windows.h>
39#endif
40
Manuel Pégourié-Gonnard013bffe2015-02-13 14:09:44 +000041#if defined(POLARSSL_BIGNUM_C) && defined(POLARSSL_CERTS_C) && \
42 defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_SSL_TLS_C) && \
43 defined(POLARSSL_SSL_SRV_C) && defined(POLARSSL_NET_C) && \
44 defined(POLARSSL_RSA_C) && defined(POLARSSL_CTR_DRBG_C) && \
45 defined(POLARSSL_X509_CRT_PARSE_C) && defined(POLARSSL_TIMING_C) && \
Rich Evans18b78c72015-02-11 14:06:19 +000046 defined(POLARSSL_FS_IO)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000047#include "mbedtls/entropy.h"
48#include "mbedtls/ctr_drbg.h"
49#include "mbedtls/certs.h"
50#include "mbedtls/x509.h"
51#include "mbedtls/ssl.h"
52#include "mbedtls/net.h"
53#include "mbedtls/timing.h"
Paul Bakker896ac222011-05-20 12:33:05 +000054
Rich Evans18b78c72015-02-11 14:06:19 +000055#include <string.h>
56#include <stdio.h>
57#include <signal.h>
58#endif
59
60#if !defined(_MSC_VER) || defined(EFIX64) || defined(EFI32)
61#include <unistd.h>
62#endif
63
Paul Bakker896ac222011-05-20 12:33:05 +000064#define HTTP_RESPONSE \
65 "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" \
Manuel Pégourié-Gonnard91699212015-01-22 16:26:39 +000066 "<h2>mbed TLS Test Server</h2>\r\n" \
Paul Bakker896ac222011-05-20 12:33:05 +000067 "<p>Successful connection using: %s</p>\r\n"
68
Paul Bakkerb892b132011-10-12 09:19:43 +000069#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
Paul Bakker508ad5a2011-12-04 17:09:26 +000070 !defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
Paul Bakkerb892b132011-10-12 09:19:43 +000071 !defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
Paul Bakkered27a042013-04-18 22:46:23 +020072 !defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
Manuel Pégourié-Gonnard013bffe2015-02-13 14:09:44 +000073 !defined(POLARSSL_X509_CRT_PARSE_C) || !defined(POLARSSL_TIMING_C) || \
Rich Evans18b78c72015-02-11 14:06:19 +000074 !defined(POLARSSL_FS_IO)
Paul Bakkercce9d772011-11-18 14:26:47 +000075int main( int argc, char *argv[] )
Paul Bakkerb892b132011-10-12 09:19:43 +000076{
Paul Bakkercce9d772011-11-18 14:26:47 +000077 ((void) argc);
78 ((void) argv);
79
Rich Evansf90016a2015-01-19 14:26:37 +000080 polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
Paul Bakkerb892b132011-10-12 09:19:43 +000081 "and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
Paul Bakker508ad5a2011-12-04 17:09:26 +000082 "POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
Paul Bakker36713e82013-09-17 13:25:29 +020083 "POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
Paul Bakkerfa9b1002013-07-03 15:31:03 +020084 "POLARSSL_TIMING_C not defined.\n");
Paul Bakkerb892b132011-10-12 09:19:43 +000085 return( 0 );
86}
Paul Bakkercce9d772011-11-18 14:26:47 +000087#elif defined(_WIN32)
Rich Evans85b05ec2015-02-12 11:37:29 +000088int main( void )
Paul Bakkerb892b132011-10-12 09:19:43 +000089{
Rich Evansf90016a2015-01-19 14:26:37 +000090 polarssl_printf("_WIN32 defined. This application requires fork() and signals "
Paul Bakkerb892b132011-10-12 09:19:43 +000091 "to work correctly.\n");
92 return( 0 );
93}
94#else
Paul Bakker896ac222011-05-20 12:33:05 +000095
96#define DEBUG_LEVEL 0
97
Paul Bakker3c5ef712013-06-25 16:37:45 +020098static void my_debug( void *ctx, int level, const char *str )
Paul Bakker896ac222011-05-20 12:33:05 +000099{
100 if( level < DEBUG_LEVEL )
101 {
Rich Evansf90016a2015-01-19 14:26:37 +0000102 polarssl_fprintf( (FILE *) ctx, "%s", str );
Paul Bakker896ac222011-05-20 12:33:05 +0000103 fflush( (FILE *) ctx );
104 }
105}
106
Rich Evans85b05ec2015-02-12 11:37:29 +0000107int main( void )
Paul Bakker896ac222011-05-20 12:33:05 +0000108{
109 int ret, len, cnt = 0, pid;
110 int listen_fd;
Manuel Pégourié-Gonnard68821da2013-09-16 12:34:33 +0200111 int client_fd = -1;
Paul Bakker896ac222011-05-20 12:33:05 +0000112 unsigned char buf[1024];
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200113 const char *pers = "ssl_fork_server";
Paul Bakker896ac222011-05-20 12:33:05 +0000114
Paul Bakker508ad5a2011-12-04 17:09:26 +0000115 entropy_context entropy;
116 ctr_drbg_context ctr_drbg;
Paul Bakker896ac222011-05-20 12:33:05 +0000117 ssl_context ssl;
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200118 x509_crt srvcert;
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200119 pk_context pkey;
Paul Bakker896ac222011-05-20 12:33:05 +0000120
Paul Bakker0c226102014-04-17 16:02:36 +0200121 memset( &ssl, 0, sizeof(ssl_context) );
122
123 entropy_init( &entropy );
124 pk_init( &pkey );
125 x509_crt_init( &srvcert );
126
Paul Bakker896ac222011-05-20 12:33:05 +0000127 signal( SIGCHLD, SIG_IGN );
128
129 /*
Paul Bakker508ad5a2011-12-04 17:09:26 +0000130 * 0. Initial seeding of the RNG
131 */
Rich Evansf90016a2015-01-19 14:26:37 +0000132 polarssl_printf( "\n . Initial seeding of the random generator..." );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000133 fflush( stdout );
134
Paul Bakker508ad5a2011-12-04 17:09:26 +0000135 if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200136 (const unsigned char *) pers,
137 strlen( pers ) ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000138 {
Rich Evansf90016a2015-01-19 14:26:37 +0000139 polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000140 goto exit;
141 }
142
Rich Evansf90016a2015-01-19 14:26:37 +0000143 polarssl_printf( " ok\n" );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000144
145 /*
Paul Bakker896ac222011-05-20 12:33:05 +0000146 * 1. Load the certificates and private RSA key
147 */
Rich Evansf90016a2015-01-19 14:26:37 +0000148 polarssl_printf( " . Loading the server cert. and key..." );
Paul Bakker896ac222011-05-20 12:33:05 +0000149 fflush( stdout );
150
Paul Bakker896ac222011-05-20 12:33:05 +0000151 /*
152 * This demonstration program uses embedded test certificates.
Paul Bakkerddf26b42013-09-18 13:46:23 +0200153 * Instead, you may want to use x509_crt_parse_file() to read the
154 * server and CA certificates, as well as pk_parse_keyfile().
Paul Bakker896ac222011-05-20 12:33:05 +0000155 */
Paul Bakkerddf26b42013-09-18 13:46:23 +0200156 ret = x509_crt_parse( &srvcert, (const unsigned char *) test_srv_crt,
157 strlen( test_srv_crt ) );
Paul Bakker896ac222011-05-20 12:33:05 +0000158 if( ret != 0 )
159 {
Rich Evansf90016a2015-01-19 14:26:37 +0000160 polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000161 goto exit;
162 }
163
Manuel Pégourié-Gonnard641de712013-09-25 13:23:33 +0200164 ret = x509_crt_parse( &srvcert, (const unsigned char *) test_ca_list,
165 strlen( test_ca_list ) );
Paul Bakker896ac222011-05-20 12:33:05 +0000166 if( ret != 0 )
167 {
Rich Evansf90016a2015-01-19 14:26:37 +0000168 polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000169 goto exit;
170 }
171
Paul Bakker1a7550a2013-09-15 13:01:22 +0200172 ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
Paul Bakker896ac222011-05-20 12:33:05 +0000173 strlen( test_srv_key ), NULL, 0 );
174 if( ret != 0 )
175 {
Rich Evansf90016a2015-01-19 14:26:37 +0000176 polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000177 goto exit;
178 }
179
Rich Evansf90016a2015-01-19 14:26:37 +0000180 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000181
182 /*
183 * 2. Setup the listening TCP socket
184 */
Rich Evansf90016a2015-01-19 14:26:37 +0000185 polarssl_printf( " . Bind on https://localhost:4433/ ..." );
Paul Bakker896ac222011-05-20 12:33:05 +0000186 fflush( stdout );
187
Manuel Pégourié-Gonnardf5a13122014-03-23 17:38:16 +0100188 if( ( ret = net_bind( &listen_fd, NULL, 4433, NET_PROTO_TCP ) ) != 0 )
Paul Bakker896ac222011-05-20 12:33:05 +0000189 {
Rich Evansf90016a2015-01-19 14:26:37 +0000190 polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000191 goto exit;
192 }
193
Rich Evansf90016a2015-01-19 14:26:37 +0000194 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000195
196 while( 1 )
197 {
198 /*
199 * 3. Wait until a client connects
200 */
201 client_fd = -1;
202 memset( &ssl, 0, sizeof( ssl ) );
203
Rich Evansf90016a2015-01-19 14:26:37 +0000204 polarssl_printf( " . Waiting for a remote connection ..." );
Paul Bakker896ac222011-05-20 12:33:05 +0000205 fflush( stdout );
206
207 if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
208 {
Rich Evansf90016a2015-01-19 14:26:37 +0000209 polarssl_printf( " failed\n ! net_accept returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000210 goto exit;
211 }
212
Rich Evansf90016a2015-01-19 14:26:37 +0000213 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000214
215 /*
216 * 3.5. Forking server thread
217 */
218
219 pid = fork();
220
Rich Evansf90016a2015-01-19 14:26:37 +0000221 polarssl_printf( " . Forking to handle connection ..." );
Paul Bakker896ac222011-05-20 12:33:05 +0000222 fflush( stdout );
223
224 if( pid < 0 )
225 {
Rich Evansf90016a2015-01-19 14:26:37 +0000226 polarssl_printf(" failed\n ! fork returned %d\n\n", pid );
Paul Bakker896ac222011-05-20 12:33:05 +0000227 goto exit;
228 }
229
Rich Evansf90016a2015-01-19 14:26:37 +0000230 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000231
232 if( pid != 0 )
233 {
Paul Bakker508ad5a2011-12-04 17:09:26 +0000234 if( ( ret = ctr_drbg_reseed( &ctr_drbg,
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200235 (const unsigned char *) "parent",
236 6 ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000237 {
Rich Evansf90016a2015-01-19 14:26:37 +0000238 polarssl_printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000239 goto exit;
240 }
241
Paul Bakker896ac222011-05-20 12:33:05 +0000242 close( client_fd );
243 continue;
244 }
245
246 close( listen_fd );
247
248 /*
249 * 4. Setup stuff
250 */
Rich Evansf90016a2015-01-19 14:26:37 +0000251 polarssl_printf( " . Setting up the SSL data...." );
Paul Bakker896ac222011-05-20 12:33:05 +0000252 fflush( stdout );
253
Paul Bakker508ad5a2011-12-04 17:09:26 +0000254 if( ( ret = ctr_drbg_reseed( &ctr_drbg,
Paul Bakkeref3f8c72013-06-24 13:01:08 +0200255 (const unsigned char *) "child",
256 5 ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000257 {
Rich Evansf90016a2015-01-19 14:26:37 +0000258 polarssl_printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000259 goto exit;
260 }
Paul Bakker0c226102014-04-17 16:02:36 +0200261
Paul Bakker896ac222011-05-20 12:33:05 +0000262 if( ( ret = ssl_init( &ssl ) ) != 0 )
263 {
Rich Evansf90016a2015-01-19 14:26:37 +0000264 polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000265 goto exit;
266 }
267
Rich Evansf90016a2015-01-19 14:26:37 +0000268 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000269
270 ssl_set_endpoint( &ssl, SSL_IS_SERVER );
271 ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
272
Manuel Pégourié-Gonnard448ea502015-01-12 11:40:14 +0100273 /* SSLv3 is deprecated, set minimum to TLS 1.0 */
274 ssl_set_min_version( &ssl, SSL_MAJOR_VERSION_3,
275 SSL_MINOR_VERSION_1 );
276
Paul Bakker508ad5a2011-12-04 17:09:26 +0000277 ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
Paul Bakker896ac222011-05-20 12:33:05 +0000278 ssl_set_dbg( &ssl, my_debug, stdout );
279 ssl_set_bio( &ssl, net_recv, &client_fd,
280 net_send, &client_fd );
Paul Bakker896ac222011-05-20 12:33:05 +0000281
Paul Bakker896ac222011-05-20 12:33:05 +0000282 ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
Manuel Pégourié-Gonnardc5fd3912014-07-08 14:05:52 +0200283 if( ( ret = ssl_set_own_cert( &ssl, &srvcert, &pkey ) ) != 0 )
284 {
Rich Evansf90016a2015-01-19 14:26:37 +0000285 polarssl_printf( " failed\n ! ssl_set_own_cert returned %d\n\n", ret );
Manuel Pégourié-Gonnardc5fd3912014-07-08 14:05:52 +0200286 goto exit;
287 }
Paul Bakker896ac222011-05-20 12:33:05 +0000288
289 /*
290 * 5. Handshake
291 */
Rich Evansf90016a2015-01-19 14:26:37 +0000292 polarssl_printf( " . Performing the SSL/TLS handshake..." );
Paul Bakker896ac222011-05-20 12:33:05 +0000293 fflush( stdout );
294
295 while( ( ret = ssl_handshake( &ssl ) ) != 0 )
296 {
297 if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
298 {
Rich Evansf90016a2015-01-19 14:26:37 +0000299 polarssl_printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000300 goto exit;
301 }
302 }
303
Rich Evansf90016a2015-01-19 14:26:37 +0000304 polarssl_printf( " ok\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000305
306 /*
307 * 6. Read the HTTP Request
308 */
Rich Evansf90016a2015-01-19 14:26:37 +0000309 polarssl_printf( " < Read from client:" );
Paul Bakker896ac222011-05-20 12:33:05 +0000310 fflush( stdout );
311
312 do
313 {
314 len = sizeof( buf ) - 1;
315 memset( buf, 0, sizeof( buf ) );
316 ret = ssl_read( &ssl, buf, len );
317
318 if( ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE )
319 continue;
320
321 if( ret <= 0 )
322 {
323 switch( ret )
324 {
325 case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
Rich Evansf90016a2015-01-19 14:26:37 +0000326 polarssl_printf( " connection was closed gracefully\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000327 break;
328
329 case POLARSSL_ERR_NET_CONN_RESET:
Rich Evansf90016a2015-01-19 14:26:37 +0000330 polarssl_printf( " connection was reset by peer\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000331 break;
332
333 default:
Rich Evansf90016a2015-01-19 14:26:37 +0000334 polarssl_printf( " ssl_read returned %d\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000335 break;
336 }
337
338 break;
339 }
340
341 len = ret;
Rich Evansf90016a2015-01-19 14:26:37 +0000342 polarssl_printf( " %d bytes read\n\n%s", len, (char *) buf );
Manuel Pégourié-Gonnard401caad2015-02-14 15:53:24 +0000343
344 if( ret > 0 )
345 break;
Paul Bakker896ac222011-05-20 12:33:05 +0000346 }
Manuel Pégourié-Gonnard401caad2015-02-14 15:53:24 +0000347 while( 1 );
Paul Bakker896ac222011-05-20 12:33:05 +0000348
349 /*
350 * 7. Write the 200 Response
351 */
Rich Evansf90016a2015-01-19 14:26:37 +0000352 polarssl_printf( " > Write to client:" );
Paul Bakker896ac222011-05-20 12:33:05 +0000353 fflush( stdout );
354
355 len = sprintf( (char *) buf, HTTP_RESPONSE,
356 ssl_get_ciphersuite( &ssl ) );
357
Paul Bakker030decd2014-04-17 16:03:23 +0200358 while( cnt++ < 100 )
Paul Bakker896ac222011-05-20 12:33:05 +0000359 {
360 while( ( ret = ssl_write( &ssl, buf, len ) ) <= 0 )
361 {
362 if( ret == POLARSSL_ERR_NET_CONN_RESET )
363 {
Rich Evansf90016a2015-01-19 14:26:37 +0000364 polarssl_printf( " failed\n ! peer closed the connection\n\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000365 goto exit;
366 }
367
368 if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
369 {
Rich Evansf90016a2015-01-19 14:26:37 +0000370 polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
Paul Bakker896ac222011-05-20 12:33:05 +0000371 goto exit;
372 }
373 }
374 len = ret;
Rich Evansf90016a2015-01-19 14:26:37 +0000375 polarssl_printf( " %d bytes written\n\n%s\n", len, (char *) buf );
Paul Bakker896ac222011-05-20 12:33:05 +0000376
377 m_sleep( 1000 );
378 }
379
380 ssl_close_notify( &ssl );
381 goto exit;
382 }
383
384exit:
385
Paul Bakker0c226102014-04-17 16:02:36 +0200386 if( client_fd != -1 )
387 net_close( client_fd );
388
Paul Bakker36713e82013-09-17 13:25:29 +0200389 x509_crt_free( &srvcert );
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200390 pk_free( &pkey );
Paul Bakker896ac222011-05-20 12:33:05 +0000391 ssl_free( &ssl );
Paul Bakkera317a982014-06-18 16:44:11 +0200392 ctr_drbg_free( &ctr_drbg );
Paul Bakker1ffefac2013-09-28 15:23:03 +0200393 entropy_free( &entropy );
Paul Bakker896ac222011-05-20 12:33:05 +0000394
Paul Bakkercce9d772011-11-18 14:26:47 +0000395#if defined(_WIN32)
Rich Evansf90016a2015-01-19 14:26:37 +0000396 polarssl_printf( " Press Enter to exit this program.\n" );
Paul Bakker896ac222011-05-20 12:33:05 +0000397 fflush( stdout ); getchar();
398#endif
399
400 return( ret );
401}
Paul Bakker508ad5a2011-12-04 17:09:26 +0000402#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_ENTROPY_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000403 POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
Paul Bakker508ad5a2011-12-04 17:09:26 +0000404 POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */