blob: 3e38e66e59510a9814d384de6d9d03bf57c22163 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * SSL/TLS stress testing 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
30#include <string.h>
31#include <stdlib.h>
32#include <stdio.h>
33
Paul Bakker5690efc2011-05-26 13:16:06 +000034#include "polarssl/config.h"
35
Paul Bakker40e46942009-01-03 21:51:57 +000036#include "polarssl/net.h"
37#include "polarssl/ssl.h"
Paul Bakker508ad5a2011-12-04 17:09:26 +000038#include "polarssl/entropy.h"
39#include "polarssl/ctr_drbg.h"
Paul Bakker40e46942009-01-03 21:51:57 +000040#include "polarssl/timing.h"
41#include "polarssl/certs.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000042
43#define OPMODE_NONE 0
44#define OPMODE_CLIENT 1
45#define OPMODE_SERVER 2
46
47#define IOMODE_BLOCK 0
48#define IOMODE_NONBLOCK 1
49
50#define COMMAND_READ 1
51#define COMMAND_WRITE 2
52#define COMMAND_BOTH 3
53
54#define DFL_OPMODE OPMODE_NONE
55#define DFL_IOMODE IOMODE_BLOCK
56#define DFL_SERVER_NAME "localhost"
57#define DFL_SERVER_PORT 4433
58#define DFL_COMMAND COMMAND_READ
59#define DFL_BUFFER_SIZE 1024
60#define DFL_MAX_BYTES 0
61#define DFL_DEBUG_LEVEL 0
62#define DFL_CONN_TIMEOUT 0
63#define DFL_MAX_CONNECTIONS 0
64#define DFL_SESSION_REUSE 1
65#define DFL_SESSION_LIFETIME 86400
66#define DFL_FORCE_CIPHER 0
67
68/*
69 * server-specific data
70 */
Paul Bakkere0225e42013-06-06 12:52:24 +020071const char *dhm_G = "4";
72const char *dhm_P =
Paul Bakker5121ce52009-01-03 21:22:43 +000073"E4004C1F94182000103D883A448B3F802CE4B44A83301270002C20D0321CFD00" \
74"11CCEF784C26A400F43DFB901BCA7538F2C6B176001CF5A0FD16D2C48B1D0C1C" \
75"F6AC8E1DA6BCC3B4E1F96B0564965300FFA1D0B601EB2800F489AA512C4B248C" \
76"01F76949A60BB7F00A40B1EAB64BDD48E8A700D60B7F1200FA8E77B0A979DABF";
77
78int server_fd = -1;
79
80/*
81 * global options
82 */
83struct options
84{
85 int opmode; /* operation mode (client or server) */
86 int iomode; /* I/O mode (blocking or non-blocking) */
Paul Bakkere0225e42013-06-06 12:52:24 +020087 const char *server_name; /* hostname of the server (client only) */
Paul Bakker5121ce52009-01-03 21:22:43 +000088 int server_port; /* port on which the ssl service runs */
89 int command; /* what to do: read or write operation */
90 int buffer_size; /* size of the send/receive buffer */
91 int max_bytes; /* max. # of bytes before a reconnect */
92 int debug_level; /* level of debugging */
93 int conn_timeout; /* max. delay before a reconnect */
94 int max_connections; /* max. number of reconnections */
95 int session_reuse; /* flag to reuse the keying material */
96 int session_lifetime; /* if reached, session data is expired */
Paul Bakkere3166ce2011-01-27 17:40:50 +000097 int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
Paul Bakker5121ce52009-01-03 21:22:43 +000098};
99
100/*
101 * Although this PRNG has good statistical properties (eg. passes
102 * DIEHARD), it is not cryptographically secure.
103 */
104unsigned long int lcppm5( unsigned long int *state )
105{
106 unsigned long int u, v;
107
108 u = v = state[4] ^ 1;
109 state[u & 3] ^= u;
110 u ^= (v << 12) ^ (v >> 12);
111 u ^= v * state[0]; v >>= 8;
112 u ^= v * state[1]; v >>= 8;
113 u ^= v * state[2]; v >>= 8;
114 u ^= v * state[3];
115 u &= 0xFFFFFFFF;
116 state[4] = u;
117
118 return( u );
119}
120
Paul Bakkerff60ee62010-03-16 21:09:09 +0000121void my_debug( void *ctx, int level, const char *str )
Paul Bakker5121ce52009-01-03 21:22:43 +0000122{
123 if( level < ((struct options *) ctx)->debug_level )
124 fprintf( stderr, "%s", str );
125}
126
Paul Bakker508ad5a2011-12-04 17:09:26 +0000127#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
Paul Bakker5690efc2011-05-26 13:16:06 +0000128 !defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
129 !defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
Paul Bakker508ad5a2011-12-04 17:09:26 +0000130 !defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
Paul Bakkercce9d772011-11-18 14:26:47 +0000131int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +0000132{
Paul Bakkercce9d772011-11-18 14:26:47 +0000133 ((void) argc);
134 ((void) argv);
135
Paul Bakker508ad5a2011-12-04 17:09:26 +0000136 printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
Paul Bakker5690efc2011-05-26 13:16:06 +0000137 "POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
138 "POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
Paul Bakker508ad5a2011-12-04 17:09:26 +0000139 "POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
Paul Bakker5690efc2011-05-26 13:16:06 +0000140 return( 0 );
141}
142#else
Paul Bakker5121ce52009-01-03 21:22:43 +0000143/*
144 * perform a single SSL connection
145 */
146static int ssl_test( struct options *opt )
147{
148 int ret, i;
149 int client_fd;
150 int bytes_to_read;
151 int bytes_to_write;
Paul Bakker026c03b2009-03-28 17:53:03 +0000152 int offset_to_read = 0;
153 int offset_to_write = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000154
155 long int nb_read;
156 long int nb_written;
157
158 unsigned long read_state[5];
159 unsigned long write_state[5];
160
Paul Bakker026c03b2009-03-28 17:53:03 +0000161 unsigned char *read_buf = NULL;
162 unsigned char *write_buf = NULL;
Paul Bakker5121ce52009-01-03 21:22:43 +0000163
Paul Bakkere0225e42013-06-06 12:52:24 +0200164 const char *pers = "ssl_test";
Paul Bakker508ad5a2011-12-04 17:09:26 +0000165
Paul Bakker5121ce52009-01-03 21:22:43 +0000166 struct hr_time t;
Paul Bakker508ad5a2011-12-04 17:09:26 +0000167 entropy_context entropy;
168 ctr_drbg_context ctr_drbg;
Paul Bakker5121ce52009-01-03 21:22:43 +0000169 ssl_context ssl;
Paul Bakker5121ce52009-01-03 21:22:43 +0000170 x509_cert srvcert;
171 rsa_context rsa;
172
173 ret = 1;
174
Paul Bakker39148402014-04-17 16:02:36 +0200175 memset( &ssl, 0, sizeof(ssl_context) );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000176 entropy_init( &entropy );
Paul Bakker39148402014-04-17 16:02:36 +0200177 memset( &srvcert, 0, sizeof( x509_cert ) );
178 memset( &rsa, 0, sizeof( rsa_context ) );
179
Paul Bakker508ad5a2011-12-04 17:09:26 +0000180 if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
Paul Bakkere0225e42013-06-06 12:52:24 +0200181 (const unsigned char *) pers,
182 strlen( pers ) ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000183 {
184 printf( " ! ctr_drbg_init returned %d\n", ret );
185 goto exit;
186 }
187
Paul Bakker5121ce52009-01-03 21:22:43 +0000188 get_timer( &t, 1 );
189
190 memset( read_state, 0, sizeof( read_state ) );
191 memset( write_state, 0, sizeof( write_state ) );
192
Paul Bakker5121ce52009-01-03 21:22:43 +0000193 if( opt->opmode == OPMODE_CLIENT )
194 {
195 if( ( ret = net_connect( &client_fd, opt->server_name,
196 opt->server_port ) ) != 0 )
197 {
198 printf( " ! net_connect returned %d\n\n", ret );
199 return( ret );
200 }
201
202 if( ( ret = ssl_init( &ssl ) ) != 0 )
203 {
204 printf( " ! ssl_init returned %d\n\n", ret );
Paul Bakker39148402014-04-17 16:02:36 +0200205 goto exit;
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 }
207
208 ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
209 }
210
211 if( opt->opmode == OPMODE_SERVER )
212 {
Paul Bakker5690efc2011-05-26 13:16:06 +0000213#if !defined(POLARSSL_CERTS_C)
214 printf("POLARSSL_CERTS_C not defined.\n");
215 goto exit;
216#else
Paul Bakkere0225e42013-06-06 12:52:24 +0200217 ret = x509parse_crt( &srvcert, (const unsigned char *) test_srv_crt,
Paul Bakker69e095c2011-12-10 21:55:01 +0000218 strlen( test_srv_crt ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000219 if( ret != 0 )
220 {
221 printf( " ! x509parse_crt returned %d\n\n", ret );
222 goto exit;
223 }
224
Paul Bakkere0225e42013-06-06 12:52:24 +0200225 ret = x509parse_crt( &srvcert, (const unsigned char *) test_ca_crt,
Paul Bakker69e095c2011-12-10 21:55:01 +0000226 strlen( test_ca_crt ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000227 if( ret != 0 )
228 {
229 printf( " ! x509parse_crt returned %d\n\n", ret );
230 goto exit;
231 }
232
Paul Bakkere0225e42013-06-06 12:52:24 +0200233 ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
Paul Bakker5121ce52009-01-03 21:22:43 +0000234 strlen( test_srv_key ), NULL, 0 );
235 if( ret != 0 )
236 {
237 printf( " ! x509parse_key returned %d\n\n", ret );
238 goto exit;
239 }
Paul Bakker5690efc2011-05-26 13:16:06 +0000240#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000241
242 if( server_fd < 0 )
243 {
244 if( ( ret = net_bind( &server_fd, NULL,
245 opt->server_port ) ) != 0 )
246 {
247 printf( " ! net_bind returned %d\n\n", ret );
248 return( ret );
249 }
250 }
251
252 if( ( ret = net_accept( server_fd, &client_fd, NULL ) ) != 0 )
253 {
254 printf( " ! net_accept returned %d\n\n", ret );
255 return( ret );
256 }
257
258 if( ( ret = ssl_init( &ssl ) ) != 0 )
259 {
260 printf( " ! ssl_init returned %d\n\n", ret );
261 return( ret );
262 }
263
264 ssl_set_endpoint( &ssl, SSL_IS_SERVER );
265 ssl_set_dh_param( &ssl, dhm_P, dhm_G );
Paul Bakker40ea7de2009-05-03 10:18:48 +0000266 ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 ssl_set_own_cert( &ssl, &srvcert, &rsa );
268 }
269
270 ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
271
Paul Bakker508ad5a2011-12-04 17:09:26 +0000272 ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
Paul Bakker5121ce52009-01-03 21:22:43 +0000273 ssl_set_dbg( &ssl, my_debug, opt );
274 ssl_set_bio( &ssl, net_recv, &client_fd,
275 net_send, &client_fd );
276
Paul Bakkere3166ce2011-01-27 17:40:50 +0000277 if( opt->force_ciphersuite[0] == DFL_FORCE_CIPHER )
278 ssl_set_ciphersuites( &ssl, ssl_default_ciphersuites );
279 else ssl_set_ciphersuites( &ssl, opt->force_ciphersuite );
Paul Bakker5121ce52009-01-03 21:22:43 +0000280
281 if( opt->iomode == IOMODE_NONBLOCK )
Paul Bakker993f02c2014-04-17 16:00:59 +0200282 {
283 if( ( ret = net_set_nonblock( client_fd ) ) != 0 )
284 {
285 printf( " ! net_set_nonblock returned %d\n\n", ret );
286 return( ret );
287 }
288 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000289
290 read_buf = (unsigned char *) malloc( opt->buffer_size );
291 write_buf = (unsigned char *) malloc( opt->buffer_size );
292
293 if( read_buf == NULL || write_buf == NULL )
294 {
295 printf( " ! malloc(%d bytes) failed\n\n", opt->buffer_size );
296 goto exit;
297 }
298
299 nb_read = bytes_to_read = 0;
300 nb_written = bytes_to_write = 0;
301
302 while( 1 )
303 {
304 if( opt->command & COMMAND_WRITE )
305 {
306 if( bytes_to_write == 0 )
307 {
308 while( bytes_to_write == 0 )
309 bytes_to_write = rand() % opt->buffer_size;
310
311 for( i = 0; i < bytes_to_write; i++ )
312 write_buf[i] = (unsigned char) lcppm5( write_state );
313
314 offset_to_write = 0;
315 }
316
317 ret = ssl_write( &ssl, write_buf + offset_to_write,
318 bytes_to_write );
319
320 if( ret >= 0 )
321 {
322 nb_written += ret;
323 bytes_to_write -= ret;
324 offset_to_write += ret;
325 }
326
Paul Bakker40e46942009-01-03 21:51:57 +0000327 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
328 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000329 {
330 ret = 0;
331 goto exit;
332 }
333
Paul Bakker831a7552011-05-18 13:32:51 +0000334 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
335 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000336 {
337 printf( " ! ssl_write returned %d\n\n", ret );
338 break;
339 }
340 }
341
342 if( opt->command & COMMAND_READ )
343 {
344 if( bytes_to_read == 0 )
345 {
346 bytes_to_read = rand() % opt->buffer_size;
347 offset_to_read = 0;
348 }
349
350 ret = ssl_read( &ssl, read_buf + offset_to_read,
351 bytes_to_read );
352
353 if( ret >= 0 )
354 {
355 for( i = 0; i < ret; i++ )
356 {
357 if( read_buf[offset_to_read + i] !=
358 (unsigned char) lcppm5( read_state ) )
359 {
360 ret = 1;
361 printf( " ! plaintext mismatch\n\n" );
362 goto exit;
363 }
364 }
365
366 nb_read += ret;
367 bytes_to_read -= ret;
368 offset_to_read += ret;
369 }
370
Paul Bakker40e46942009-01-03 21:51:57 +0000371 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
372 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000373 {
374 ret = 0;
375 goto exit;
376 }
377
Paul Bakker831a7552011-05-18 13:32:51 +0000378 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
379 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000380 {
381 printf( " ! ssl_read returned %d\n\n", ret );
382 break;
383 }
384 }
385
386 ret = 0;
387
388 if( opt->max_bytes != 0 &&
389 ( opt->max_bytes <= nb_read ||
390 opt->max_bytes <= nb_written ) )
391 break;
392
393 if( opt->conn_timeout != 0 &&
394 opt->conn_timeout <= (int) get_timer( &t, 0 ) )
395 break;
396 }
397
398exit:
399
400 fflush( stdout );
401
402 if( read_buf != NULL )
403 free( read_buf );
404
405 if( write_buf != NULL )
406 free( write_buf );
407
408 ssl_close_notify( &ssl );
409 x509_free( &srvcert );
410 rsa_free( &rsa );
411 ssl_free( &ssl );
Paul Bakker39148402014-04-17 16:02:36 +0200412
413 if( client_fd != -1 )
414 net_close( client_fd );
Paul Bakker5121ce52009-01-03 21:22:43 +0000415
416 return( ret );
417}
418
419#define USAGE \
420 "\n usage: ssl_test opmode=<> command=<>...\n" \
421 "\n acceptable parameters:\n" \
422 " opmode=client/server default: <none>\n" \
423 " iomode=block/nonblock default: block\n" \
424 " server_name=%%s default: localhost\n" \
425 " server_port=%%d default: 4433\n" \
426 " command=read/write/both default: read\n" \
427 " buffer_size=%%d (bytes) default: 1024\n" \
428 " max_bytes=%%d (bytes) default: 0 (no limit)\n" \
429 " debug_level=%%d default: 0 (disabled)\n" \
430 " conn_timeout=%%d (ms) default: 0 (no timeout)\n" \
431 " max_connections=%%d default: 0 (no limit)\n" \
432 " session_reuse=on/off default: on (enabled)\n" \
433 " session_lifetime=%%d (s) default: 86400\n" \
Paul Bakkere3166ce2011-01-27 17:40:50 +0000434 " force_ciphersuite=<name> default: all enabled\n" \
435 " acceptable ciphersuite names:\n"
Paul Bakker5121ce52009-01-03 21:22:43 +0000436
437int main( int argc, char *argv[] )
438{
Paul Bakker256a4af2013-11-30 15:13:02 +0100439 int i;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000440 const int *list;
Paul Bakker5121ce52009-01-03 21:22:43 +0000441 int ret = 1;
442 int nb_conn;
443 char *p, *q;
444 struct options opt;
445
446 if( argc == 1 )
447 {
448 usage:
449 printf( USAGE );
Paul Bakkere3166ce2011-01-27 17:40:50 +0000450
451 list = ssl_list_ciphersuites();
452 while( *list )
453 {
454 printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
455 list++;
456 }
457 printf("\n");
Paul Bakker5121ce52009-01-03 21:22:43 +0000458 goto exit;
459 }
460
461 opt.opmode = DFL_OPMODE;
462 opt.iomode = DFL_IOMODE;
463 opt.server_name = DFL_SERVER_NAME;
464 opt.server_port = DFL_SERVER_PORT;
465 opt.command = DFL_COMMAND;
466 opt.buffer_size = DFL_BUFFER_SIZE;
467 opt.max_bytes = DFL_MAX_BYTES;
468 opt.debug_level = DFL_DEBUG_LEVEL;
469 opt.conn_timeout = DFL_CONN_TIMEOUT;
470 opt.max_connections = DFL_MAX_CONNECTIONS;
471 opt.session_reuse = DFL_SESSION_REUSE;
472 opt.session_lifetime = DFL_SESSION_LIFETIME;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000473 opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
Paul Bakker5121ce52009-01-03 21:22:43 +0000474
475 for( i = 1; i < argc; i++ )
476 {
Paul Bakker5121ce52009-01-03 21:22:43 +0000477 p = argv[i];
478 if( ( q = strchr( p, '=' ) ) == NULL )
479 continue;
480 *q++ = '\0';
481
482 if( strcmp( p, "opmode" ) == 0 )
483 {
484 if( strcmp( q, "client" ) == 0 )
485 opt.opmode = OPMODE_CLIENT;
486 else
487 if( strcmp( q, "server" ) == 0 )
488 opt.opmode = OPMODE_SERVER;
489 else goto usage;
490 }
491
492 if( strcmp( p, "iomode" ) == 0 )
493 {
494 if( strcmp( q, "block" ) == 0 )
495 opt.iomode = IOMODE_BLOCK;
496 else
497 if( strcmp( q, "nonblock" ) == 0 )
498 opt.iomode = IOMODE_NONBLOCK;
499 else goto usage;
500 }
501
502 if( strcmp( p, "server_name" ) == 0 )
503 opt.server_name = q;
504
505 if( strcmp( p, "server_port" ) == 0 )
506 {
507 opt.server_port = atoi( q );
508 if( opt.server_port < 1 || opt.server_port > 65535 )
509 goto usage;
510 }
511
512 if( strcmp( p, "command" ) == 0 )
513 {
514 if( strcmp( q, "read" ) == 0 )
515 opt.command = COMMAND_READ;
516 else
517 if( strcmp( q, "write" ) == 0 )
518 opt.command = COMMAND_WRITE;
519 else
520 if( strcmp( q, "both" ) == 0 )
521 {
522 opt.iomode = IOMODE_NONBLOCK;
523 opt.command = COMMAND_BOTH;
524 }
525 else goto usage;
526 }
527
528 if( strcmp( p, "buffer_size" ) == 0 )
529 {
530 opt.buffer_size = atoi( q );
531 if( opt.buffer_size < 1 || opt.buffer_size > 1048576 )
532 goto usage;
533 }
534
535 if( strcmp( p, "max_bytes" ) == 0 )
536 opt.max_bytes = atoi( q );
537
538 if( strcmp( p, "debug_level" ) == 0 )
539 opt.debug_level = atoi( q );
540
541 if( strcmp( p, "conn_timeout" ) == 0 )
542 opt.conn_timeout = atoi( q );
543
544 if( strcmp( p, "max_connections" ) == 0 )
545 opt.max_connections = atoi( q );
546
547 if( strcmp( p, "session_reuse" ) == 0 )
548 {
549 if( strcmp( q, "on" ) == 0 )
550 opt.session_reuse = 1;
551 else
552 if( strcmp( q, "off" ) == 0 )
553 opt.session_reuse = 0;
554 else
555 goto usage;
556 }
557
558 if( strcmp( p, "session_lifetime" ) == 0 )
559 opt.session_lifetime = atoi( q );
560
Paul Bakkere3166ce2011-01-27 17:40:50 +0000561 if( strcmp( p, "force_ciphersuite" ) == 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000562 {
Paul Bakkere3166ce2011-01-27 17:40:50 +0000563 opt.force_ciphersuite[0] = -1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000564
Paul Bakkere3166ce2011-01-27 17:40:50 +0000565 opt.force_ciphersuite[0] = ssl_get_ciphersuite_id( q );
Paul Bakker5121ce52009-01-03 21:22:43 +0000566
Paul Bakkere3166ce2011-01-27 17:40:50 +0000567 if( opt.force_ciphersuite[0] <= 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000568 goto usage;
569
Paul Bakkere3166ce2011-01-27 17:40:50 +0000570 opt.force_ciphersuite[1] = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000571 }
572 }
573
574 switch( opt.opmode )
575 {
576 case OPMODE_CLIENT:
577 break;
578
579 case OPMODE_SERVER:
580 break;
581
582 default:
583 goto usage;
584 }
585
586 nb_conn = 0;
587
588 do {
589 nb_conn++;
590 ret = ssl_test( &opt );
591 if( opt.max_connections != 0 &&
592 opt.max_connections <= nb_conn )
593 break;
594 }
595 while( ret == 0 );
596
597exit:
598
Paul Bakkercce9d772011-11-18 14:26:47 +0000599#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000600 printf( " Press Enter to exit this program.\n" );
601 fflush( stdout ); getchar();
602#endif
603
604 return( ret );
605}
Paul Bakker508ad5a2011-12-04 17:09:26 +0000606#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000607 POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
Paul Bakker508ad5a2011-12-04 17:09:26 +0000608 POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */