blob: 070d5347c80fe3dbc8efe3421203e493146df217 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * SSL server demonstration program
3 *
Paul Bakkercce9d772011-11-18 14:26:47 +00004 * Copyright (C) 2006-2011, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakker5121ce52009-01-03 21:22:43 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#ifndef _CRT_SECURE_NO_DEPRECATE
27#define _CRT_SECURE_NO_DEPRECATE 1
28#endif
29
Paul Bakkercce9d772011-11-18 14:26:47 +000030#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +000031#include <windows.h>
32#endif
33
34#include <string.h>
35#include <stdlib.h>
36#include <stdio.h>
37
Paul Bakker5690efc2011-05-26 13:16:06 +000038#include "polarssl/config.h"
39
Paul Bakker508ad5a2011-12-04 17:09:26 +000040#include "polarssl/entropy.h"
41#include "polarssl/ctr_drbg.h"
Paul Bakker40e46942009-01-03 21:51:57 +000042#include "polarssl/certs.h"
43#include "polarssl/x509.h"
44#include "polarssl/ssl.h"
45#include "polarssl/net.h"
Paul Bakkera3d195c2011-11-27 21:07:34 +000046#include "polarssl/error.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000047
Paul Bakker0a597072012-09-25 21:55:46 +000048#if defined(POLARSSL_SSL_CACHE_C)
49#include "polarssl/ssl_cache.h"
50#endif
51
Paul Bakker5121ce52009-01-03 21:22:43 +000052#define HTTP_RESPONSE \
53 "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" \
Paul Bakkereaca51d2010-08-16 12:00:14 +000054 "<h2>PolarSSL Test Server</h2>\r\n" \
55 "<p>Successful connection using: %s</p>\r\n"
Paul Bakker5121ce52009-01-03 21:22:43 +000056
57/*
Paul Bakker29b64762012-09-25 09:36:44 +000058 * Computing a "safe" DH prime can take a very
59 * long time. RFC 5114 provides precomputed and standardized
60 * values.
Paul Bakker5121ce52009-01-03 21:22:43 +000061 */
Paul Bakker29b64762012-09-25 09:36:44 +000062char *my_dhm_P = POLARSSL_DHM_RFC5114_MODP_1024_P;
63char *my_dhm_G = POLARSSL_DHM_RFC5114_MODP_1024_G;
Paul Bakker5121ce52009-01-03 21:22:43 +000064
65/*
66 * Sorted by order of preference
67 */
Paul Bakkere3166ce2011-01-27 17:40:50 +000068int my_ciphersuites[] =
Paul Bakker5121ce52009-01-03 21:22:43 +000069{
Paul Bakker10cd2252012-04-12 21:26:34 +000070#if defined(POLARSSL_DHM_C)
71#if defined(POLARSSL_AES_C)
72#if defined(POLARSSL_SHA2_C)
73 SSL_EDH_RSA_AES_256_SHA256,
74 SSL_EDH_RSA_AES_128_SHA256,
75#endif /* POLARSSL_SHA2_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000076 SSL_EDH_RSA_AES_256_SHA,
Paul Bakker77a43582010-06-15 21:32:46 +000077 SSL_EDH_RSA_AES_128_SHA,
Paul Bakkerca4ab492012-04-18 14:23:57 +000078#if defined(POLARSSL_GCM_C) && defined(POLARSSL_SHA4_C)
79 SSL_EDH_RSA_AES_256_GCM_SHA384,
80#endif
81#if defined(POLARSSL_GCM_C) && defined(POLARSSL_SHA2_C)
82 SSL_EDH_RSA_AES_128_GCM_SHA256,
83#endif
Paul Bakker10cd2252012-04-12 21:26:34 +000084#endif
85#if defined(POLARSSL_CAMELLIA_C)
86#if defined(POLARSSL_SHA2_C)
87 SSL_EDH_RSA_CAMELLIA_256_SHA256,
88 SSL_EDH_RSA_CAMELLIA_128_SHA256,
89#endif /* POLARSSL_SHA2_C */
90 SSL_EDH_RSA_CAMELLIA_256_SHA,
Paul Bakker77a43582010-06-15 21:32:46 +000091 SSL_EDH_RSA_CAMELLIA_128_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +000092#endif
93#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000094 SSL_EDH_RSA_DES_168_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +000095#endif
96#endif
97
98#if defined(POLARSSL_AES_C)
99#if defined(POLARSSL_SHA2_C)
100 SSL_RSA_AES_256_SHA256,
101#endif /* POLARSSL_SHA2_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 SSL_RSA_AES_256_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +0000103#endif
104#if defined(POLARSSL_CAMELLIA_C)
105#if defined(POLARSSL_SHA2_C)
106 SSL_RSA_CAMELLIA_256_SHA256,
107#endif /* POLARSSL_SHA2_C */
Paul Bakkerb5ef0ba2009-01-11 20:25:36 +0000108 SSL_RSA_CAMELLIA_256_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +0000109#endif
110#if defined(POLARSSL_AES_C)
111#if defined(POLARSSL_SHA2_C)
112 SSL_RSA_AES_128_SHA256,
113#endif /* POLARSSL_SHA2_C */
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 SSL_RSA_AES_128_SHA,
Paul Bakkerca4ab492012-04-18 14:23:57 +0000115#if defined(POLARSSL_GCM_C) && defined(POLARSSL_SHA4_C)
116 SSL_RSA_AES_256_GCM_SHA384,
117#endif
118#if defined(POLARSSL_GCM_C) && defined(POLARSSL_SHA2_C)
119 SSL_RSA_AES_128_GCM_SHA256,
120#endif
Paul Bakker10cd2252012-04-12 21:26:34 +0000121#endif
122#if defined(POLARSSL_CAMELLIA_C)
123#if defined(POLARSSL_SHA2_C)
124 SSL_RSA_CAMELLIA_128_SHA256,
125#endif /* POLARSSL_SHA2_C */
Paul Bakkerb5ef0ba2009-01-11 20:25:36 +0000126 SSL_RSA_CAMELLIA_128_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +0000127#endif
128#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 SSL_RSA_DES_168_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +0000130#endif
131#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 SSL_RSA_RC4_128_SHA,
133 SSL_RSA_RC4_128_MD5,
Paul Bakker10cd2252012-04-12 21:26:34 +0000134#endif
Paul Bakkerfab5c822012-02-06 16:45:10 +0000135#if defined(POLARSSL_ENABLE_WEAK_CIPHERSUITES)
Paul Bakker10cd2252012-04-12 21:26:34 +0000136#if defined(POLARSSL_DES_C)
Paul Bakkerfab5c822012-02-06 16:45:10 +0000137 SSL_EDH_RSA_DES_SHA,
138 SSL_RSA_DES_SHA,
Paul Bakker10cd2252012-04-12 21:26:34 +0000139#endif
Paul Bakkerfab5c822012-02-06 16:45:10 +0000140#if defined(POLARSSL_CIPHER_NULL_CIPHER)
141 SSL_RSA_NULL_MD5,
142 SSL_RSA_NULL_SHA,
143 SSL_RSA_NULL_SHA256,
144#endif
145#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000146 0
147};
148
Paul Bakker835b29e2012-08-23 08:31:59 +0000149#define DEBUG_LEVEL 0
Paul Bakker5121ce52009-01-03 21:22:43 +0000150
Paul Bakkerff60ee62010-03-16 21:09:09 +0000151void my_debug( void *ctx, int level, const char *str )
Paul Bakker5121ce52009-01-03 21:22:43 +0000152{
153 if( level < DEBUG_LEVEL )
154 {
155 fprintf( (FILE *) ctx, "%s", str );
156 fflush( (FILE *) ctx );
157 }
158}
159
Paul Bakker5690efc2011-05-26 13:16:06 +0000160#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
Paul Bakker508ad5a2011-12-04 17:09:26 +0000161 !defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
Paul Bakker5690efc2011-05-26 13:16:06 +0000162 !defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
Paul Bakker508ad5a2011-12-04 17:09:26 +0000163 !defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
Paul Bakkercce9d772011-11-18 14:26:47 +0000164int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +0000165{
Paul Bakkercce9d772011-11-18 14:26:47 +0000166 ((void) argc);
167 ((void) argv);
168
Paul Bakker508ad5a2011-12-04 17:09:26 +0000169 printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
Paul Bakker5690efc2011-05-26 13:16:06 +0000170 "and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
Paul Bakker508ad5a2011-12-04 17:09:26 +0000171 "POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
172 "POLARSSL_CTR_DRBG_C not defined.\n");
Paul Bakker5690efc2011-05-26 13:16:06 +0000173 return( 0 );
174}
175#else
Paul Bakkercce9d772011-11-18 14:26:47 +0000176int main( int argc, char *argv[] )
Paul Bakker5121ce52009-01-03 21:22:43 +0000177{
178 int ret, len;
179 int listen_fd;
Paul Bakker7eb013f2011-10-06 12:37:39 +0000180 int client_fd = -1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000181 unsigned char buf[1024];
Paul Bakker508ad5a2011-12-04 17:09:26 +0000182 char *pers = "ssl_server";
Paul Bakker5121ce52009-01-03 21:22:43 +0000183
Paul Bakker508ad5a2011-12-04 17:09:26 +0000184 entropy_context entropy;
185 ctr_drbg_context ctr_drbg;
Paul Bakker5121ce52009-01-03 21:22:43 +0000186 ssl_context ssl;
Paul Bakker5121ce52009-01-03 21:22:43 +0000187 x509_cert srvcert;
188 rsa_context rsa;
189
Paul Bakkercce9d772011-11-18 14:26:47 +0000190 ((void) argc);
191 ((void) argv);
192
Paul Bakker0a597072012-09-25 21:55:46 +0000193#if defined(POLARSSL_SSL_CACHE_C)
194 ssl_cache_context cache;
195
196 ssl_cache_init( &cache );
197#endif
Paul Bakkerfab5c822012-02-06 16:45:10 +0000198
Paul Bakker5121ce52009-01-03 21:22:43 +0000199 /*
200 * 1. Load the certificates and private RSA key
201 */
202 printf( "\n . Loading the server cert. and key..." );
203 fflush( stdout );
204
205 memset( &srvcert, 0, sizeof( x509_cert ) );
206
207 /*
208 * This demonstration program uses embedded test certificates.
209 * Instead, you may want to use x509parse_crtfile() to read the
210 * server and CA certificates, as well as x509parse_keyfile().
211 */
212 ret = x509parse_crt( &srvcert, (unsigned char *) test_srv_crt,
Paul Bakker69e095c2011-12-10 21:55:01 +0000213 strlen( test_srv_crt ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000214 if( ret != 0 )
215 {
216 printf( " failed\n ! x509parse_crt returned %d\n\n", ret );
217 goto exit;
218 }
219
220 ret = x509parse_crt( &srvcert, (unsigned char *) test_ca_crt,
Paul Bakker69e095c2011-12-10 21:55:01 +0000221 strlen( test_ca_crt ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000222 if( ret != 0 )
223 {
224 printf( " failed\n ! x509parse_crt returned %d\n\n", ret );
225 goto exit;
226 }
227
Paul Bakker91b41592011-05-05 12:01:31 +0000228 rsa_init( &rsa, RSA_PKCS_V15, 0 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000229 ret = x509parse_key( &rsa, (unsigned char *) test_srv_key,
230 strlen( test_srv_key ), NULL, 0 );
231 if( ret != 0 )
232 {
233 printf( " failed\n ! x509parse_key returned %d\n\n", ret );
234 goto exit;
235 }
236
237 printf( " ok\n" );
238
239 /*
240 * 2. Setup the listening TCP socket
241 */
242 printf( " . Bind on https://localhost:4433/ ..." );
243 fflush( stdout );
244
245 if( ( ret = net_bind( &listen_fd, NULL, 4433 ) ) != 0 )
246 {
247 printf( " failed\n ! net_bind returned %d\n\n", ret );
248 goto exit;
249 }
250
251 printf( " ok\n" );
252
253 /*
Paul Bakker508ad5a2011-12-04 17:09:26 +0000254 * 3. Seed the RNG
Paul Bakker5121ce52009-01-03 21:22:43 +0000255 */
Paul Bakker508ad5a2011-12-04 17:09:26 +0000256 printf( " . Seeding the random number generator..." );
Paul Bakker5121ce52009-01-03 21:22:43 +0000257 fflush( stdout );
258
Paul Bakker508ad5a2011-12-04 17:09:26 +0000259 entropy_init( &entropy );
260 if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
261 (unsigned char *) pers, strlen( pers ) ) ) != 0 )
262 {
263 printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
264 goto exit;
265 }
266
267 printf( " ok\n" );
268
269 /*
270 * 4. Setup stuff
271 */
272 printf( " . Setting up the SSL data...." );
273 fflush( stdout );
Paul Bakker5121ce52009-01-03 21:22:43 +0000274
275 if( ( ret = ssl_init( &ssl ) ) != 0 )
276 {
277 printf( " failed\n ! ssl_init returned %d\n\n", ret );
Paul Bakker7eb013f2011-10-06 12:37:39 +0000278 goto exit;
Paul Bakker5121ce52009-01-03 21:22:43 +0000279 }
280
Paul Bakker5121ce52009-01-03 21:22:43 +0000281 ssl_set_endpoint( &ssl, SSL_IS_SERVER );
282 ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
283
Paul Bakker508ad5a2011-12-04 17:09:26 +0000284 ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
Paul Bakker5121ce52009-01-03 21:22:43 +0000285 ssl_set_dbg( &ssl, my_debug, stdout );
Paul Bakker7eb013f2011-10-06 12:37:39 +0000286
Paul Bakker0a597072012-09-25 21:55:46 +0000287#if defined(POLARSSL_SSL_CACHE_C)
288 ssl_set_session_cache( &ssl, ssl_cache_get, &cache,
289 ssl_cache_set, &cache );
290#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000291
Paul Bakkere3166ce2011-01-27 17:40:50 +0000292 ssl_set_ciphersuites( &ssl, my_ciphersuites );
Paul Bakker5121ce52009-01-03 21:22:43 +0000293
Paul Bakker40ea7de2009-05-03 10:18:48 +0000294 ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000295 ssl_set_own_cert( &ssl, &srvcert, &rsa );
Paul Bakker48916f92012-09-16 19:57:18 +0000296#if defined(POLARSSL_DHM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000297 ssl_set_dh_param( &ssl, my_dhm_P, my_dhm_G );
Paul Bakker48916f92012-09-16 19:57:18 +0000298#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000299
Paul Bakker7eb013f2011-10-06 12:37:39 +0000300 printf( " ok\n" );
301
302reset:
Paul Bakkera3d195c2011-11-27 21:07:34 +0000303#ifdef POLARSSL_ERROR_C
304 if( ret != 0 )
305 {
306 char error_buf[100];
307 error_strerror( ret, error_buf, 100 );
308 printf("Last error was: %d - %s\n\n", ret, error_buf );
309 }
310#endif
311
Paul Bakker7eb013f2011-10-06 12:37:39 +0000312 if( client_fd != -1 )
313 net_close( client_fd );
314
315 ssl_session_reset( &ssl );
316
317 /*
318 * 3. Wait until a client connects
319 */
Paul Bakkercce9d772011-11-18 14:26:47 +0000320#if defined(_WIN32_WCE)
321 {
322 SHELLEXECUTEINFO sei;
323
324 ZeroMemory( &sei, sizeof( SHELLEXECUTEINFO ) );
325
326 sei.cbSize = sizeof( SHELLEXECUTEINFO );
327 sei.fMask = 0;
328 sei.hwnd = 0;
329 sei.lpVerb = _T( "open" );
330 sei.lpFile = _T( "https://localhost:4433/" );
331 sei.lpParameters = NULL;
332 sei.lpDirectory = NULL;
333 sei.nShow = SW_SHOWNORMAL;
334
335 ShellExecuteEx( &sei );
336 }
337#elif defined(_WIN32)
Paul Bakker7eb013f2011-10-06 12:37:39 +0000338 ShellExecute( NULL, "open", "https://localhost:4433/",
339 NULL, NULL, SW_SHOWNORMAL );
340#endif
341
342 client_fd = -1;
343
344 printf( " . Waiting for a remote connection ..." );
345 fflush( stdout );
346
347 if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
348 {
349 printf( " failed\n ! net_accept returned %d\n\n", ret );
350 goto exit;
351 }
352
353 ssl_set_bio( &ssl, net_recv, &client_fd,
354 net_send, &client_fd );
355
356 printf( " ok\n" );
357
Paul Bakker5121ce52009-01-03 21:22:43 +0000358 /*
359 * 5. Handshake
360 */
361 printf( " . Performing the SSL/TLS handshake..." );
362 fflush( stdout );
363
364 while( ( ret = ssl_handshake( &ssl ) ) != 0 )
365 {
Paul Bakker831a7552011-05-18 13:32:51 +0000366 if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000367 {
368 printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
Paul Bakker7eb013f2011-10-06 12:37:39 +0000369 goto reset;
Paul Bakker5121ce52009-01-03 21:22:43 +0000370 }
371 }
372
373 printf( " ok\n" );
374
375 /*
376 * 6. Read the HTTP Request
377 */
378 printf( " < Read from client:" );
379 fflush( stdout );
380
381 do
382 {
383 len = sizeof( buf ) - 1;
384 memset( buf, 0, sizeof( buf ) );
385 ret = ssl_read( &ssl, buf, len );
386
Paul Bakker831a7552011-05-18 13:32:51 +0000387 if( ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000388 continue;
389
390 if( ret <= 0 )
391 {
392 switch( ret )
393 {
Paul Bakker40e46942009-01-03 21:51:57 +0000394 case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
Paul Bakker5121ce52009-01-03 21:22:43 +0000395 printf( " connection was closed gracefully\n" );
396 break;
397
Paul Bakker40e46942009-01-03 21:51:57 +0000398 case POLARSSL_ERR_NET_CONN_RESET:
Paul Bakker5121ce52009-01-03 21:22:43 +0000399 printf( " connection was reset by peer\n" );
400 break;
401
402 default:
Paul Bakker6f3578c2012-04-16 06:46:01 +0000403 printf( " ssl_read returned -0x%x\n", -ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000404 break;
405 }
406
407 break;
408 }
409
410 len = ret;
411 printf( " %d bytes read\n\n%s", len, (char *) buf );
Paul Bakker48916f92012-09-16 19:57:18 +0000412
413 if( ret > 0 )
414 break;
Paul Bakker5121ce52009-01-03 21:22:43 +0000415 }
Paul Bakker48916f92012-09-16 19:57:18 +0000416 while( 1 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000417
418 /*
419 * 7. Write the 200 Response
420 */
421 printf( " > Write to client:" );
422 fflush( stdout );
423
424 len = sprintf( (char *) buf, HTTP_RESPONSE,
Paul Bakkere3166ce2011-01-27 17:40:50 +0000425 ssl_get_ciphersuite( &ssl ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000426
427 while( ( ret = ssl_write( &ssl, buf, len ) ) <= 0 )
428 {
Paul Bakker40e46942009-01-03 21:51:57 +0000429 if( ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000430 {
431 printf( " failed\n ! peer closed the connection\n\n" );
Paul Bakker7eb013f2011-10-06 12:37:39 +0000432 goto reset;
Paul Bakker5121ce52009-01-03 21:22:43 +0000433 }
434
Paul Bakker831a7552011-05-18 13:32:51 +0000435 if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000436 {
437 printf( " failed\n ! ssl_write returned %d\n\n", ret );
438 goto exit;
439 }
440 }
441
442 len = ret;
443 printf( " %d bytes written\n\n%s\n", len, (char *) buf );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000444
Paul Bakkera3d195c2011-11-27 21:07:34 +0000445 ret = 0;
Paul Bakker7eb013f2011-10-06 12:37:39 +0000446 goto reset;
Paul Bakker5121ce52009-01-03 21:22:43 +0000447
448exit:
449
Paul Bakkera3d195c2011-11-27 21:07:34 +0000450#ifdef POLARSSL_ERROR_C
451 if( ret != 0 )
452 {
453 char error_buf[100];
454 error_strerror( ret, error_buf, 100 );
455 printf("Last error was: %d - %s\n\n", ret, error_buf );
456 }
457#endif
458
Paul Bakker5121ce52009-01-03 21:22:43 +0000459 net_close( client_fd );
460 x509_free( &srvcert );
461 rsa_free( &rsa );
462 ssl_free( &ssl );
Paul Bakker0a597072012-09-25 21:55:46 +0000463#if defined(POLARSSL_SSL_CACHE_C)
464 ssl_cache_free( &cache );
465#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000466
Paul Bakkercce9d772011-11-18 14:26:47 +0000467#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000468 printf( " Press Enter to exit this program.\n" );
469 fflush( stdout ); getchar();
470#endif
471
472 return( ret );
473}
Paul Bakker508ad5a2011-12-04 17:09:26 +0000474#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_ENTROPY_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000475 POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
Paul Bakker508ad5a2011-12-04 17:09:26 +0000476 POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */