blob: 3c6352b33f99999642cff0a0a0f442d83e632d84 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * SSL/TLS stress testing program
3 *
Paul Bakker530927b2015-02-13 14:24:10 +01004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakker5121ce52009-01-03 21:22:43 +00008 * 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
23#ifndef _CRT_SECURE_NO_DEPRECATE
24#define _CRT_SECURE_NO_DEPRECATE 1
25#endif
26
27#include <string.h>
28#include <stdlib.h>
29#include <stdio.h>
30
Paul Bakker5690efc2011-05-26 13:16:06 +000031#include "polarssl/config.h"
32
Paul Bakker40e46942009-01-03 21:51:57 +000033#include "polarssl/net.h"
34#include "polarssl/ssl.h"
Paul Bakker508ad5a2011-12-04 17:09:26 +000035#include "polarssl/entropy.h"
36#include "polarssl/ctr_drbg.h"
Paul Bakker40e46942009-01-03 21:51:57 +000037#include "polarssl/timing.h"
38#include "polarssl/certs.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000039
40#define OPMODE_NONE 0
41#define OPMODE_CLIENT 1
42#define OPMODE_SERVER 2
43
44#define IOMODE_BLOCK 0
45#define IOMODE_NONBLOCK 1
46
47#define COMMAND_READ 1
48#define COMMAND_WRITE 2
49#define COMMAND_BOTH 3
50
51#define DFL_OPMODE OPMODE_NONE
52#define DFL_IOMODE IOMODE_BLOCK
53#define DFL_SERVER_NAME "localhost"
54#define DFL_SERVER_PORT 4433
55#define DFL_COMMAND COMMAND_READ
56#define DFL_BUFFER_SIZE 1024
57#define DFL_MAX_BYTES 0
58#define DFL_DEBUG_LEVEL 0
59#define DFL_CONN_TIMEOUT 0
60#define DFL_MAX_CONNECTIONS 0
61#define DFL_SESSION_REUSE 1
62#define DFL_SESSION_LIFETIME 86400
63#define DFL_FORCE_CIPHER 0
64
65/*
66 * server-specific data
67 */
Paul Bakkere0225e42013-06-06 12:52:24 +020068const char *dhm_G = "4";
69const char *dhm_P =
Paul Bakker5121ce52009-01-03 21:22:43 +000070"E4004C1F94182000103D883A448B3F802CE4B44A83301270002C20D0321CFD00" \
71"11CCEF784C26A400F43DFB901BCA7538F2C6B176001CF5A0FD16D2C48B1D0C1C" \
72"F6AC8E1DA6BCC3B4E1F96B0564965300FFA1D0B601EB2800F489AA512C4B248C" \
73"01F76949A60BB7F00A40B1EAB64BDD48E8A700D60B7F1200FA8E77B0A979DABF";
74
75int server_fd = -1;
76
77/*
78 * global options
79 */
80struct options
81{
82 int opmode; /* operation mode (client or server) */
83 int iomode; /* I/O mode (blocking or non-blocking) */
Paul Bakkere0225e42013-06-06 12:52:24 +020084 const char *server_name; /* hostname of the server (client only) */
Paul Bakker5121ce52009-01-03 21:22:43 +000085 int server_port; /* port on which the ssl service runs */
86 int command; /* what to do: read or write operation */
87 int buffer_size; /* size of the send/receive buffer */
88 int max_bytes; /* max. # of bytes before a reconnect */
89 int debug_level; /* level of debugging */
90 int conn_timeout; /* max. delay before a reconnect */
91 int max_connections; /* max. number of reconnections */
92 int session_reuse; /* flag to reuse the keying material */
93 int session_lifetime; /* if reached, session data is expired */
Paul Bakkere3166ce2011-01-27 17:40:50 +000094 int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
Paul Bakker5121ce52009-01-03 21:22:43 +000095};
96
97/*
98 * Although this PRNG has good statistical properties (eg. passes
99 * DIEHARD), it is not cryptographically secure.
100 */
101unsigned long int lcppm5( unsigned long int *state )
102{
103 unsigned long int u, v;
104
105 u = v = state[4] ^ 1;
106 state[u & 3] ^= u;
107 u ^= (v << 12) ^ (v >> 12);
108 u ^= v * state[0]; v >>= 8;
109 u ^= v * state[1]; v >>= 8;
110 u ^= v * state[2]; v >>= 8;
111 u ^= v * state[3];
112 u &= 0xFFFFFFFF;
113 state[4] = u;
114
115 return( u );
116}
117
Paul Bakkerff60ee62010-03-16 21:09:09 +0000118void my_debug( void *ctx, int level, const char *str )
Paul Bakker5121ce52009-01-03 21:22:43 +0000119{
120 if( level < ((struct options *) ctx)->debug_level )
121 fprintf( stderr, "%s", str );
122}
123
Paul Bakker508ad5a2011-12-04 17:09:26 +0000124#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
Paul Bakker5690efc2011-05-26 13:16:06 +0000125 !defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
126 !defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
Paul Bakker508ad5a2011-12-04 17:09:26 +0000127 !defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
Paul Bakkercce9d772011-11-18 14:26:47 +0000128int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +0000129{
Paul Bakkercce9d772011-11-18 14:26:47 +0000130 ((void) argc);
131 ((void) argv);
132
Paul Bakker508ad5a2011-12-04 17:09:26 +0000133 printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
Paul Bakker5690efc2011-05-26 13:16:06 +0000134 "POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
135 "POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
Paul Bakker508ad5a2011-12-04 17:09:26 +0000136 "POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
Paul Bakker5690efc2011-05-26 13:16:06 +0000137 return( 0 );
138}
139#else
Paul Bakker5121ce52009-01-03 21:22:43 +0000140/*
141 * perform a single SSL connection
142 */
143static int ssl_test( struct options *opt )
144{
Alfred Klomp18596212014-07-14 22:10:14 +0200145 int ret = 1, i;
146 int client_fd = -1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000147 int bytes_to_read;
148 int bytes_to_write;
Paul Bakker026c03b2009-03-28 17:53:03 +0000149 int offset_to_read = 0;
150 int offset_to_write = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000151
152 long int nb_read;
153 long int nb_written;
154
155 unsigned long read_state[5];
156 unsigned long write_state[5];
157
Paul Bakker026c03b2009-03-28 17:53:03 +0000158 unsigned char *read_buf = NULL;
159 unsigned char *write_buf = NULL;
Paul Bakker5121ce52009-01-03 21:22:43 +0000160
Paul Bakkere0225e42013-06-06 12:52:24 +0200161 const char *pers = "ssl_test";
Paul Bakker508ad5a2011-12-04 17:09:26 +0000162
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 struct hr_time t;
Paul Bakker508ad5a2011-12-04 17:09:26 +0000164 entropy_context entropy;
165 ctr_drbg_context ctr_drbg;
Paul Bakker5121ce52009-01-03 21:22:43 +0000166 ssl_context ssl;
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 x509_cert srvcert;
168 rsa_context rsa;
169
Paul Bakker39148402014-04-17 16:02:36 +0200170 memset( &ssl, 0, sizeof(ssl_context) );
Paul Bakker508ad5a2011-12-04 17:09:26 +0000171 entropy_init( &entropy );
Paul Bakker39148402014-04-17 16:02:36 +0200172 memset( &srvcert, 0, sizeof( x509_cert ) );
173 memset( &rsa, 0, sizeof( rsa_context ) );
174
Paul Bakker508ad5a2011-12-04 17:09:26 +0000175 if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
Paul Bakkere0225e42013-06-06 12:52:24 +0200176 (const unsigned char *) pers,
177 strlen( pers ) ) ) != 0 )
Paul Bakker508ad5a2011-12-04 17:09:26 +0000178 {
179 printf( " ! ctr_drbg_init returned %d\n", ret );
180 goto exit;
181 }
182
Paul Bakker5121ce52009-01-03 21:22:43 +0000183 get_timer( &t, 1 );
184
185 memset( read_state, 0, sizeof( read_state ) );
186 memset( write_state, 0, sizeof( write_state ) );
187
Paul Bakker5121ce52009-01-03 21:22:43 +0000188 if( opt->opmode == OPMODE_CLIENT )
189 {
190 if( ( ret = net_connect( &client_fd, opt->server_name,
191 opt->server_port ) ) != 0 )
192 {
193 printf( " ! net_connect returned %d\n\n", ret );
194 return( ret );
195 }
196
197 if( ( ret = ssl_init( &ssl ) ) != 0 )
198 {
199 printf( " ! ssl_init returned %d\n\n", ret );
Paul Bakker39148402014-04-17 16:02:36 +0200200 goto exit;
Paul Bakker5121ce52009-01-03 21:22:43 +0000201 }
202
203 ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
204 }
205
206 if( opt->opmode == OPMODE_SERVER )
207 {
Paul Bakker5690efc2011-05-26 13:16:06 +0000208#if !defined(POLARSSL_CERTS_C)
209 printf("POLARSSL_CERTS_C not defined.\n");
210 goto exit;
211#else
Paul Bakkere0225e42013-06-06 12:52:24 +0200212 ret = x509parse_crt( &srvcert, (const 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( " ! x509parse_crt returned %d\n\n", ret );
217 goto exit;
218 }
219
Paul Bakkere0225e42013-06-06 12:52:24 +0200220 ret = x509parse_crt( &srvcert, (const 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( " ! x509parse_crt returned %d\n\n", ret );
225 goto exit;
226 }
227
Paul Bakkere0225e42013-06-06 12:52:24 +0200228 ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
Paul Bakker5121ce52009-01-03 21:22:43 +0000229 strlen( test_srv_key ), NULL, 0 );
230 if( ret != 0 )
231 {
232 printf( " ! x509parse_key returned %d\n\n", ret );
233 goto exit;
234 }
Paul Bakker5690efc2011-05-26 13:16:06 +0000235#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000236
237 if( server_fd < 0 )
238 {
239 if( ( ret = net_bind( &server_fd, NULL,
240 opt->server_port ) ) != 0 )
241 {
242 printf( " ! net_bind returned %d\n\n", ret );
243 return( ret );
244 }
245 }
246
247 if( ( ret = net_accept( server_fd, &client_fd, NULL ) ) != 0 )
248 {
249 printf( " ! net_accept returned %d\n\n", ret );
250 return( ret );
251 }
252
253 if( ( ret = ssl_init( &ssl ) ) != 0 )
254 {
255 printf( " ! ssl_init returned %d\n\n", ret );
256 return( ret );
257 }
258
259 ssl_set_endpoint( &ssl, SSL_IS_SERVER );
260 ssl_set_dh_param( &ssl, dhm_P, dhm_G );
Paul Bakker40ea7de2009-05-03 10:18:48 +0000261 ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 ssl_set_own_cert( &ssl, &srvcert, &rsa );
263 }
264
265 ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
266
Paul Bakker508ad5a2011-12-04 17:09:26 +0000267 ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
Paul Bakker5121ce52009-01-03 21:22:43 +0000268 ssl_set_dbg( &ssl, my_debug, opt );
269 ssl_set_bio( &ssl, net_recv, &client_fd,
270 net_send, &client_fd );
271
Paul Bakkere3166ce2011-01-27 17:40:50 +0000272 if( opt->force_ciphersuite[0] == DFL_FORCE_CIPHER )
273 ssl_set_ciphersuites( &ssl, ssl_default_ciphersuites );
274 else ssl_set_ciphersuites( &ssl, opt->force_ciphersuite );
Paul Bakker5121ce52009-01-03 21:22:43 +0000275
276 if( opt->iomode == IOMODE_NONBLOCK )
Paul Bakker993f02c2014-04-17 16:00:59 +0200277 {
278 if( ( ret = net_set_nonblock( client_fd ) ) != 0 )
279 {
280 printf( " ! net_set_nonblock returned %d\n\n", ret );
281 return( ret );
282 }
283 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000284
285 read_buf = (unsigned char *) malloc( opt->buffer_size );
286 write_buf = (unsigned char *) malloc( opt->buffer_size );
287
288 if( read_buf == NULL || write_buf == NULL )
289 {
290 printf( " ! malloc(%d bytes) failed\n\n", opt->buffer_size );
291 goto exit;
292 }
293
294 nb_read = bytes_to_read = 0;
295 nb_written = bytes_to_write = 0;
296
297 while( 1 )
298 {
299 if( opt->command & COMMAND_WRITE )
300 {
301 if( bytes_to_write == 0 )
302 {
303 while( bytes_to_write == 0 )
304 bytes_to_write = rand() % opt->buffer_size;
305
306 for( i = 0; i < bytes_to_write; i++ )
307 write_buf[i] = (unsigned char) lcppm5( write_state );
308
309 offset_to_write = 0;
310 }
311
312 ret = ssl_write( &ssl, write_buf + offset_to_write,
313 bytes_to_write );
314
315 if( ret >= 0 )
316 {
317 nb_written += ret;
318 bytes_to_write -= ret;
319 offset_to_write += ret;
320 }
321
Paul Bakker40e46942009-01-03 21:51:57 +0000322 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
323 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000324 {
325 ret = 0;
326 goto exit;
327 }
328
Paul Bakker831a7552011-05-18 13:32:51 +0000329 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
330 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000331 {
332 printf( " ! ssl_write returned %d\n\n", ret );
333 break;
334 }
335 }
336
337 if( opt->command & COMMAND_READ )
338 {
339 if( bytes_to_read == 0 )
340 {
341 bytes_to_read = rand() % opt->buffer_size;
342 offset_to_read = 0;
343 }
344
345 ret = ssl_read( &ssl, read_buf + offset_to_read,
346 bytes_to_read );
347
348 if( ret >= 0 )
349 {
350 for( i = 0; i < ret; i++ )
351 {
352 if( read_buf[offset_to_read + i] !=
353 (unsigned char) lcppm5( read_state ) )
354 {
355 ret = 1;
356 printf( " ! plaintext mismatch\n\n" );
357 goto exit;
358 }
359 }
360
361 nb_read += ret;
362 bytes_to_read -= ret;
363 offset_to_read += ret;
364 }
365
Paul Bakker40e46942009-01-03 21:51:57 +0000366 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
367 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000368 {
369 ret = 0;
370 goto exit;
371 }
372
Paul Bakker831a7552011-05-18 13:32:51 +0000373 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
374 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000375 {
376 printf( " ! ssl_read returned %d\n\n", ret );
377 break;
378 }
379 }
380
381 ret = 0;
382
383 if( opt->max_bytes != 0 &&
384 ( opt->max_bytes <= nb_read ||
385 opt->max_bytes <= nb_written ) )
386 break;
387
388 if( opt->conn_timeout != 0 &&
389 opt->conn_timeout <= (int) get_timer( &t, 0 ) )
390 break;
391 }
392
393exit:
394
395 fflush( stdout );
396
397 if( read_buf != NULL )
398 free( read_buf );
399
400 if( write_buf != NULL )
401 free( write_buf );
402
403 ssl_close_notify( &ssl );
404 x509_free( &srvcert );
405 rsa_free( &rsa );
406 ssl_free( &ssl );
Paul Bakker39148402014-04-17 16:02:36 +0200407
408 if( client_fd != -1 )
409 net_close( client_fd );
Paul Bakker5121ce52009-01-03 21:22:43 +0000410
411 return( ret );
412}
413
414#define USAGE \
415 "\n usage: ssl_test opmode=<> command=<>...\n" \
416 "\n acceptable parameters:\n" \
417 " opmode=client/server default: <none>\n" \
418 " iomode=block/nonblock default: block\n" \
419 " server_name=%%s default: localhost\n" \
420 " server_port=%%d default: 4433\n" \
421 " command=read/write/both default: read\n" \
422 " buffer_size=%%d (bytes) default: 1024\n" \
423 " max_bytes=%%d (bytes) default: 0 (no limit)\n" \
424 " debug_level=%%d default: 0 (disabled)\n" \
425 " conn_timeout=%%d (ms) default: 0 (no timeout)\n" \
426 " max_connections=%%d default: 0 (no limit)\n" \
427 " session_reuse=on/off default: on (enabled)\n" \
428 " session_lifetime=%%d (s) default: 86400\n" \
Paul Bakkere3166ce2011-01-27 17:40:50 +0000429 " force_ciphersuite=<name> default: all enabled\n" \
430 " acceptable ciphersuite names:\n"
Paul Bakker5121ce52009-01-03 21:22:43 +0000431
432int main( int argc, char *argv[] )
433{
Paul Bakker256a4af2013-11-30 15:13:02 +0100434 int i;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000435 const int *list;
Paul Bakker5121ce52009-01-03 21:22:43 +0000436 int ret = 1;
437 int nb_conn;
438 char *p, *q;
439 struct options opt;
440
441 if( argc == 1 )
442 {
443 usage:
444 printf( USAGE );
Paul Bakkere3166ce2011-01-27 17:40:50 +0000445
446 list = ssl_list_ciphersuites();
447 while( *list )
448 {
449 printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
450 list++;
451 }
452 printf("\n");
Paul Bakker5121ce52009-01-03 21:22:43 +0000453 goto exit;
454 }
455
456 opt.opmode = DFL_OPMODE;
457 opt.iomode = DFL_IOMODE;
458 opt.server_name = DFL_SERVER_NAME;
459 opt.server_port = DFL_SERVER_PORT;
460 opt.command = DFL_COMMAND;
461 opt.buffer_size = DFL_BUFFER_SIZE;
462 opt.max_bytes = DFL_MAX_BYTES;
463 opt.debug_level = DFL_DEBUG_LEVEL;
464 opt.conn_timeout = DFL_CONN_TIMEOUT;
465 opt.max_connections = DFL_MAX_CONNECTIONS;
466 opt.session_reuse = DFL_SESSION_REUSE;
467 opt.session_lifetime = DFL_SESSION_LIFETIME;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000468 opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
Paul Bakker5121ce52009-01-03 21:22:43 +0000469
470 for( i = 1; i < argc; i++ )
471 {
Paul Bakker5121ce52009-01-03 21:22:43 +0000472 p = argv[i];
473 if( ( q = strchr( p, '=' ) ) == NULL )
474 continue;
475 *q++ = '\0';
476
477 if( strcmp( p, "opmode" ) == 0 )
478 {
479 if( strcmp( q, "client" ) == 0 )
480 opt.opmode = OPMODE_CLIENT;
481 else
482 if( strcmp( q, "server" ) == 0 )
483 opt.opmode = OPMODE_SERVER;
484 else goto usage;
485 }
486
487 if( strcmp( p, "iomode" ) == 0 )
488 {
489 if( strcmp( q, "block" ) == 0 )
490 opt.iomode = IOMODE_BLOCK;
491 else
492 if( strcmp( q, "nonblock" ) == 0 )
493 opt.iomode = IOMODE_NONBLOCK;
494 else goto usage;
495 }
496
497 if( strcmp( p, "server_name" ) == 0 )
498 opt.server_name = q;
499
500 if( strcmp( p, "server_port" ) == 0 )
501 {
502 opt.server_port = atoi( q );
503 if( opt.server_port < 1 || opt.server_port > 65535 )
504 goto usage;
505 }
506
507 if( strcmp( p, "command" ) == 0 )
508 {
509 if( strcmp( q, "read" ) == 0 )
510 opt.command = COMMAND_READ;
511 else
512 if( strcmp( q, "write" ) == 0 )
513 opt.command = COMMAND_WRITE;
514 else
515 if( strcmp( q, "both" ) == 0 )
516 {
517 opt.iomode = IOMODE_NONBLOCK;
518 opt.command = COMMAND_BOTH;
519 }
520 else goto usage;
521 }
522
523 if( strcmp( p, "buffer_size" ) == 0 )
524 {
525 opt.buffer_size = atoi( q );
526 if( opt.buffer_size < 1 || opt.buffer_size > 1048576 )
527 goto usage;
528 }
529
530 if( strcmp( p, "max_bytes" ) == 0 )
531 opt.max_bytes = atoi( q );
532
533 if( strcmp( p, "debug_level" ) == 0 )
534 opt.debug_level = atoi( q );
535
536 if( strcmp( p, "conn_timeout" ) == 0 )
537 opt.conn_timeout = atoi( q );
538
539 if( strcmp( p, "max_connections" ) == 0 )
540 opt.max_connections = atoi( q );
541
542 if( strcmp( p, "session_reuse" ) == 0 )
543 {
544 if( strcmp( q, "on" ) == 0 )
545 opt.session_reuse = 1;
546 else
547 if( strcmp( q, "off" ) == 0 )
548 opt.session_reuse = 0;
549 else
550 goto usage;
551 }
552
553 if( strcmp( p, "session_lifetime" ) == 0 )
554 opt.session_lifetime = atoi( q );
555
Paul Bakkere3166ce2011-01-27 17:40:50 +0000556 if( strcmp( p, "force_ciphersuite" ) == 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000557 {
Paul Bakkere3166ce2011-01-27 17:40:50 +0000558 opt.force_ciphersuite[0] = -1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000559
Paul Bakkere3166ce2011-01-27 17:40:50 +0000560 opt.force_ciphersuite[0] = ssl_get_ciphersuite_id( q );
Paul Bakker5121ce52009-01-03 21:22:43 +0000561
Paul Bakkere3166ce2011-01-27 17:40:50 +0000562 if( opt.force_ciphersuite[0] <= 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000563 goto usage;
564
Paul Bakkere3166ce2011-01-27 17:40:50 +0000565 opt.force_ciphersuite[1] = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000566 }
567 }
568
569 switch( opt.opmode )
570 {
571 case OPMODE_CLIENT:
572 break;
573
574 case OPMODE_SERVER:
575 break;
576
577 default:
578 goto usage;
579 }
580
581 nb_conn = 0;
582
583 do {
584 nb_conn++;
585 ret = ssl_test( &opt );
586 if( opt.max_connections != 0 &&
587 opt.max_connections <= nb_conn )
588 break;
589 }
590 while( ret == 0 );
591
592exit:
593
Paul Bakkercce9d772011-11-18 14:26:47 +0000594#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000595 printf( " Press Enter to exit this program.\n" );
596 fflush( stdout ); getchar();
597#endif
598
599 return( ret );
600}
Paul Bakker508ad5a2011-12-04 17:09:26 +0000601#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000602 POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
Paul Bakker508ad5a2011-12-04 17:09:26 +0000603 POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */