blob: 6221576d8e547b06f1cadd286404e89f3846bd29 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * SSL/TLS stress testing program
3 *
Paul Bakker68884e32013-01-07 18:20:04 +01004 * Copyright (C) 2006-2013, 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/certs.h"
Paul Bakker44618dd2013-07-04 10:34:10 +020041#if defined(POLARSSL_TIMING_C)
42#include "polarssl/timing.h"
43#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000044
Paul Bakker9a97c5d2013-09-15 17:07:33 +020045#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
46 !defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
47 !defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
48 !defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
49 !defined(POLARSSL_X509_PARSE_C)
50int main( int argc, char *argv[] )
51{
52 ((void) argc);
53 ((void) argv);
54
55 printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
56 "POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
57 "POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
58 "POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C and/or "
59 "POLARSSL_X509_PARSE_C not defined.\n");
60 return( 0 );
61}
62#else
63
Paul Bakker5121ce52009-01-03 21:22:43 +000064#define OPMODE_NONE 0
65#define OPMODE_CLIENT 1
66#define OPMODE_SERVER 2
67
68#define IOMODE_BLOCK 0
69#define IOMODE_NONBLOCK 1
70
71#define COMMAND_READ 1
72#define COMMAND_WRITE 2
73#define COMMAND_BOTH 3
74
75#define DFL_OPMODE OPMODE_NONE
76#define DFL_IOMODE IOMODE_BLOCK
77#define DFL_SERVER_NAME "localhost"
78#define DFL_SERVER_PORT 4433
79#define DFL_COMMAND COMMAND_READ
80#define DFL_BUFFER_SIZE 1024
81#define DFL_MAX_BYTES 0
82#define DFL_DEBUG_LEVEL 0
83#define DFL_CONN_TIMEOUT 0
84#define DFL_MAX_CONNECTIONS 0
85#define DFL_SESSION_REUSE 1
86#define DFL_SESSION_LIFETIME 86400
87#define DFL_FORCE_CIPHER 0
88
Paul Bakker5121ce52009-01-03 21:22:43 +000089int server_fd = -1;
90
91/*
92 * global options
93 */
94struct options
95{
96 int opmode; /* operation mode (client or server) */
97 int iomode; /* I/O mode (blocking or non-blocking) */
Paul Bakkeref3f8c72013-06-24 13:01:08 +020098 const char *server_name; /* hostname of the server (client only) */
Paul Bakker5121ce52009-01-03 21:22:43 +000099 int server_port; /* port on which the ssl service runs */
100 int command; /* what to do: read or write operation */
101 int buffer_size; /* size of the send/receive buffer */
102 int max_bytes; /* max. # of bytes before a reconnect */
103 int debug_level; /* level of debugging */
Paul Bakker44618dd2013-07-04 10:34:10 +0200104#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000105 int conn_timeout; /* max. delay before a reconnect */
Paul Bakker44618dd2013-07-04 10:34:10 +0200106#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 int max_connections; /* max. number of reconnections */
108 int session_reuse; /* flag to reuse the keying material */
109 int session_lifetime; /* if reached, session data is expired */
Paul Bakkere3166ce2011-01-27 17:40:50 +0000110 int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
Paul Bakker5121ce52009-01-03 21:22:43 +0000111};
112
113/*
114 * Although this PRNG has good statistical properties (eg. passes
115 * DIEHARD), it is not cryptographically secure.
116 */
Paul Bakker3c5ef712013-06-25 16:37:45 +0200117static unsigned long int lcppm5( unsigned long int *state )
Paul Bakker5121ce52009-01-03 21:22:43 +0000118{
119 unsigned long int u, v;
120
121 u = v = state[4] ^ 1;
122 state[u & 3] ^= u;
123 u ^= (v << 12) ^ (v >> 12);
124 u ^= v * state[0]; v >>= 8;
125 u ^= v * state[1]; v >>= 8;
126 u ^= v * state[2]; v >>= 8;
127 u ^= v * state[3];
128 u &= 0xFFFFFFFF;
129 state[4] = u;
130
131 return( u );
132}
133
Paul Bakker3c5ef712013-06-25 16:37:45 +0200134static void my_debug( void *ctx, int level, const char *str )
Paul Bakker5121ce52009-01-03 21:22:43 +0000135{
136 if( level < ((struct options *) ctx)->debug_level )
137 fprintf( stderr, "%s", str );
138}
139
140/*
141 * perform a single SSL connection
142 */
143static int ssl_test( struct options *opt )
144{
145 int ret, i;
146 int client_fd;
147 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 Bakkeref3f8c72013-06-24 13:01:08 +0200161 const char *pers = "ssl_test";
Paul Bakker508ad5a2011-12-04 17:09:26 +0000162
Paul Bakker44618dd2013-07-04 10:34:10 +0200163#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000164 struct hr_time t;
Paul Bakker44618dd2013-07-04 10:34:10 +0200165#endif
Paul Bakker508ad5a2011-12-04 17:09:26 +0000166 entropy_context entropy;
167 ctr_drbg_context ctr_drbg;
Paul Bakker5121ce52009-01-03 21:22:43 +0000168 ssl_context ssl;
Paul Bakker5121ce52009-01-03 21:22:43 +0000169 x509_cert srvcert;
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200170 pk_context pkey;
Paul Bakker5121ce52009-01-03 21:22:43 +0000171
172 ret = 1;
173
Paul Bakker508ad5a2011-12-04 17:09:26 +0000174 entropy_init( &entropy );
175 if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
Paul Bakkeref3f8c72013-06-24 13:01:08 +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 Bakker44618dd2013-07-04 10:34:10 +0200183#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000184 get_timer( &t, 1 );
Paul Bakker44618dd2013-07-04 10:34:10 +0200185#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000186
187 memset( read_state, 0, sizeof( read_state ) );
188 memset( write_state, 0, sizeof( write_state ) );
189
190 memset( &srvcert, 0, sizeof( x509_cert ) );
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200191 pk_init( &pkey );
Paul Bakker5121ce52009-01-03 21:22:43 +0000192
193 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 );
205 return( ret );
206 }
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 Bakkeref3f8c72013-06-24 13:01:08 +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 Bakkeref3f8c72013-06-24 13:01:08 +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 Bakker1a7550a2013-09-15 13:01:22 +0200233 ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
234 strlen( test_srv_key ), NULL, 0 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000235 if( ret != 0 )
236 {
Paul Bakker1a7550a2013-09-15 13:01:22 +0200237 printf( " ! pk_parse_key returned %d\n\n", ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000238 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 );
Paul Bakker40ea7de2009-05-03 10:18:48 +0000265 ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200266 ssl_set_own_cert( &ssl, &srvcert, &pkey );
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 }
268
269 ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
270
Paul Bakker508ad5a2011-12-04 17:09:26 +0000271 ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
Paul Bakker5121ce52009-01-03 21:22:43 +0000272 ssl_set_dbg( &ssl, my_debug, opt );
273 ssl_set_bio( &ssl, net_recv, &client_fd,
274 net_send, &client_fd );
275
Paul Bakker68884e32013-01-07 18:20:04 +0100276 if( opt->force_ciphersuite[0] != DFL_FORCE_CIPHER )
277 ssl_set_ciphersuites( &ssl, opt->force_ciphersuite );
Paul Bakker5121ce52009-01-03 21:22:43 +0000278
279 if( opt->iomode == IOMODE_NONBLOCK )
280 net_set_nonblock( client_fd );
281
282 read_buf = (unsigned char *) malloc( opt->buffer_size );
283 write_buf = (unsigned char *) malloc( opt->buffer_size );
284
285 if( read_buf == NULL || write_buf == NULL )
286 {
287 printf( " ! malloc(%d bytes) failed\n\n", opt->buffer_size );
288 goto exit;
289 }
290
291 nb_read = bytes_to_read = 0;
292 nb_written = bytes_to_write = 0;
293
294 while( 1 )
295 {
296 if( opt->command & COMMAND_WRITE )
297 {
298 if( bytes_to_write == 0 )
299 {
300 while( bytes_to_write == 0 )
301 bytes_to_write = rand() % opt->buffer_size;
302
303 for( i = 0; i < bytes_to_write; i++ )
304 write_buf[i] = (unsigned char) lcppm5( write_state );
305
306 offset_to_write = 0;
307 }
308
309 ret = ssl_write( &ssl, write_buf + offset_to_write,
310 bytes_to_write );
311
312 if( ret >= 0 )
313 {
314 nb_written += ret;
315 bytes_to_write -= ret;
316 offset_to_write += ret;
317 }
318
Paul Bakker40e46942009-01-03 21:51:57 +0000319 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
320 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000321 {
322 ret = 0;
323 goto exit;
324 }
325
Paul Bakker831a7552011-05-18 13:32:51 +0000326 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
327 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000328 {
329 printf( " ! ssl_write returned %d\n\n", ret );
330 break;
331 }
332 }
333
334 if( opt->command & COMMAND_READ )
335 {
336 if( bytes_to_read == 0 )
337 {
338 bytes_to_read = rand() % opt->buffer_size;
339 offset_to_read = 0;
340 }
341
342 ret = ssl_read( &ssl, read_buf + offset_to_read,
343 bytes_to_read );
344
345 if( ret >= 0 )
346 {
347 for( i = 0; i < ret; i++ )
348 {
349 if( read_buf[offset_to_read + i] !=
350 (unsigned char) lcppm5( read_state ) )
351 {
352 ret = 1;
353 printf( " ! plaintext mismatch\n\n" );
354 goto exit;
355 }
356 }
357
358 nb_read += ret;
359 bytes_to_read -= ret;
360 offset_to_read += ret;
361 }
362
Paul Bakker40e46942009-01-03 21:51:57 +0000363 if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
364 ret == POLARSSL_ERR_NET_CONN_RESET )
Paul Bakker5121ce52009-01-03 21:22:43 +0000365 {
366 ret = 0;
367 goto exit;
368 }
369
Paul Bakker831a7552011-05-18 13:32:51 +0000370 if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
371 ret != POLARSSL_ERR_NET_WANT_WRITE )
Paul Bakker5121ce52009-01-03 21:22:43 +0000372 {
373 printf( " ! ssl_read returned %d\n\n", ret );
374 break;
375 }
376 }
377
378 ret = 0;
379
380 if( opt->max_bytes != 0 &&
381 ( opt->max_bytes <= nb_read ||
382 opt->max_bytes <= nb_written ) )
383 break;
384
Paul Bakker44618dd2013-07-04 10:34:10 +0200385#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000386 if( opt->conn_timeout != 0 &&
387 opt->conn_timeout <= (int) get_timer( &t, 0 ) )
388 break;
Paul Bakker44618dd2013-07-04 10:34:10 +0200389#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000390 }
391
392exit:
393
394 fflush( stdout );
395
396 if( read_buf != NULL )
397 free( read_buf );
398
399 if( write_buf != NULL )
400 free( write_buf );
401
402 ssl_close_notify( &ssl );
403 x509_free( &srvcert );
Manuel Pégourié-Gonnardac755232013-08-19 14:10:16 +0200404 pk_free( &pkey );
Paul Bakker5121ce52009-01-03 21:22:43 +0000405 ssl_free( &ssl );
406 net_close( client_fd );
407
408 return( ret );
409}
410
Paul Bakker44618dd2013-07-04 10:34:10 +0200411#if defined(POLARSSL_TIMING_C)
412#define USAGE_TIMING \
413 " conn_timeout=%%d (ms) default: 0 (no timeout)\n"
414#else
415#define USAGE_TIMING ""
416#endif
417
Paul Bakker5121ce52009-01-03 21:22:43 +0000418#define USAGE \
419 "\n usage: ssl_test opmode=<> command=<>...\n" \
420 "\n acceptable parameters:\n" \
421 " opmode=client/server default: <none>\n" \
422 " iomode=block/nonblock default: block\n" \
423 " server_name=%%s default: localhost\n" \
424 " server_port=%%d default: 4433\n" \
425 " command=read/write/both default: read\n" \
426 " buffer_size=%%d (bytes) default: 1024\n" \
427 " max_bytes=%%d (bytes) default: 0 (no limit)\n" \
428 " debug_level=%%d default: 0 (disabled)\n" \
Paul Bakker44618dd2013-07-04 10:34:10 +0200429 USAGE_TIMING \
Paul Bakker5121ce52009-01-03 21:22:43 +0000430 " max_connections=%%d default: 0 (no limit)\n" \
431 " session_reuse=on/off default: on (enabled)\n" \
432 " session_lifetime=%%d (s) default: 86400\n" \
Paul Bakkere3166ce2011-01-27 17:40:50 +0000433 " force_ciphersuite=<name> default: all enabled\n" \
434 " acceptable ciphersuite names:\n"
Paul Bakker5121ce52009-01-03 21:22:43 +0000435
436int main( int argc, char *argv[] )
437{
438 int i, j, n;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000439 const int *list;
Paul Bakker5121ce52009-01-03 21:22:43 +0000440 int ret = 1;
441 int nb_conn;
442 char *p, *q;
443 struct options opt;
444
445 if( argc == 1 )
446 {
447 usage:
448 printf( USAGE );
Paul Bakker44618dd2013-07-04 10:34:10 +0200449
Paul Bakkere3166ce2011-01-27 17:40:50 +0000450 list = ssl_list_ciphersuites();
451 while( *list )
452 {
453 printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
454 list++;
455 }
456 printf("\n");
Paul Bakker5121ce52009-01-03 21:22:43 +0000457 goto exit;
458 }
459
460 opt.opmode = DFL_OPMODE;
461 opt.iomode = DFL_IOMODE;
462 opt.server_name = DFL_SERVER_NAME;
463 opt.server_port = DFL_SERVER_PORT;
464 opt.command = DFL_COMMAND;
465 opt.buffer_size = DFL_BUFFER_SIZE;
466 opt.max_bytes = DFL_MAX_BYTES;
467 opt.debug_level = DFL_DEBUG_LEVEL;
Paul Bakker44618dd2013-07-04 10:34:10 +0200468#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000469 opt.conn_timeout = DFL_CONN_TIMEOUT;
Paul Bakker44618dd2013-07-04 10:34:10 +0200470#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000471 opt.max_connections = DFL_MAX_CONNECTIONS;
472 opt.session_reuse = DFL_SESSION_REUSE;
473 opt.session_lifetime = DFL_SESSION_LIFETIME;
Paul Bakkere3166ce2011-01-27 17:40:50 +0000474 opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
Paul Bakker5121ce52009-01-03 21:22:43 +0000475
476 for( i = 1; i < argc; i++ )
477 {
478 n = strlen( argv[i] );
479
480 for( j = 0; j < n; j++ )
481 {
482 if( argv[i][j] >= 'A' && argv[i][j] <= 'Z' )
483 argv[i][j] |= 0x20;
484 }
485
486 p = argv[i];
487 if( ( q = strchr( p, '=' ) ) == NULL )
488 continue;
489 *q++ = '\0';
490
491 if( strcmp( p, "opmode" ) == 0 )
492 {
493 if( strcmp( q, "client" ) == 0 )
494 opt.opmode = OPMODE_CLIENT;
495 else
496 if( strcmp( q, "server" ) == 0 )
497 opt.opmode = OPMODE_SERVER;
498 else goto usage;
499 }
500
501 if( strcmp( p, "iomode" ) == 0 )
502 {
503 if( strcmp( q, "block" ) == 0 )
504 opt.iomode = IOMODE_BLOCK;
505 else
506 if( strcmp( q, "nonblock" ) == 0 )
507 opt.iomode = IOMODE_NONBLOCK;
508 else goto usage;
509 }
510
511 if( strcmp( p, "server_name" ) == 0 )
512 opt.server_name = q;
513
514 if( strcmp( p, "server_port" ) == 0 )
515 {
516 opt.server_port = atoi( q );
517 if( opt.server_port < 1 || opt.server_port > 65535 )
518 goto usage;
519 }
520
521 if( strcmp( p, "command" ) == 0 )
522 {
523 if( strcmp( q, "read" ) == 0 )
524 opt.command = COMMAND_READ;
525 else
526 if( strcmp( q, "write" ) == 0 )
527 opt.command = COMMAND_WRITE;
528 else
529 if( strcmp( q, "both" ) == 0 )
530 {
531 opt.iomode = IOMODE_NONBLOCK;
532 opt.command = COMMAND_BOTH;
533 }
534 else goto usage;
535 }
536
537 if( strcmp( p, "buffer_size" ) == 0 )
538 {
539 opt.buffer_size = atoi( q );
540 if( opt.buffer_size < 1 || opt.buffer_size > 1048576 )
541 goto usage;
542 }
543
544 if( strcmp( p, "max_bytes" ) == 0 )
545 opt.max_bytes = atoi( q );
546
547 if( strcmp( p, "debug_level" ) == 0 )
548 opt.debug_level = atoi( q );
Paul Bakker44618dd2013-07-04 10:34:10 +0200549#if defined(POLARSSL_TIMING_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000550 if( strcmp( p, "conn_timeout" ) == 0 )
551 opt.conn_timeout = atoi( q );
Paul Bakker44618dd2013-07-04 10:34:10 +0200552#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000553 if( strcmp( p, "max_connections" ) == 0 )
554 opt.max_connections = atoi( q );
555
556 if( strcmp( p, "session_reuse" ) == 0 )
557 {
558 if( strcmp( q, "on" ) == 0 )
559 opt.session_reuse = 1;
560 else
561 if( strcmp( q, "off" ) == 0 )
562 opt.session_reuse = 0;
563 else
564 goto usage;
565 }
566
567 if( strcmp( p, "session_lifetime" ) == 0 )
568 opt.session_lifetime = atoi( q );
569
Paul Bakkere3166ce2011-01-27 17:40:50 +0000570 if( strcmp( p, "force_ciphersuite" ) == 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000571 {
Paul Bakkere3166ce2011-01-27 17:40:50 +0000572 opt.force_ciphersuite[0] = -1;
Paul Bakker5121ce52009-01-03 21:22:43 +0000573
Paul Bakkere3166ce2011-01-27 17:40:50 +0000574 opt.force_ciphersuite[0] = ssl_get_ciphersuite_id( q );
Paul Bakker5121ce52009-01-03 21:22:43 +0000575
Paul Bakkere3166ce2011-01-27 17:40:50 +0000576 if( opt.force_ciphersuite[0] <= 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000577 goto usage;
578
Paul Bakkere3166ce2011-01-27 17:40:50 +0000579 opt.force_ciphersuite[1] = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000580 }
581 }
582
583 switch( opt.opmode )
584 {
585 case OPMODE_CLIENT:
586 break;
587
588 case OPMODE_SERVER:
589 break;
590
591 default:
592 goto usage;
593 }
594
595 nb_conn = 0;
596
597 do {
598 nb_conn++;
599 ret = ssl_test( &opt );
600 if( opt.max_connections != 0 &&
601 opt.max_connections <= nb_conn )
602 break;
603 }
604 while( ret == 0 );
605
606exit:
607
Paul Bakkercce9d772011-11-18 14:26:47 +0000608#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000609 printf( " Press Enter to exit this program.\n" );
610 fflush( stdout ); getchar();
611#endif
612
613 return( ret );
614}
Paul Bakker508ad5a2011-12-04 17:09:26 +0000615#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
Paul Bakker5690efc2011-05-26 13:16:06 +0000616 POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
Paul Bakker508ad5a2011-12-04 17:09:26 +0000617 POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */