2009-01-03 21:22:43 +00:00
|
|
|
/*
|
|
|
|
* SSL/TLS stress testing program
|
|
|
|
*
|
2013-01-07 17:20:04 +00:00
|
|
|
* Copyright (C) 2006-2013, Brainspark B.V.
|
2010-07-18 20:36:00 +00:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
2010-07-18 10:13:04 +00:00
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
2010-07-18 20:36:00 +00:00
|
|
|
*
|
2009-07-28 17:23:11 +00:00
|
|
|
* All rights reserved.
|
2009-01-04 16:27:10 +00:00
|
|
|
*
|
2009-01-03 21:22:43 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-09-20 11:30:43 +00:00
|
|
|
#include "polarssl/config.h"
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-01-03 21:51:57 +00:00
|
|
|
#include "polarssl/net.h"
|
|
|
|
#include "polarssl/ssl.h"
|
2011-12-04 17:09:26 +00:00
|
|
|
#include "polarssl/entropy.h"
|
|
|
|
#include "polarssl/ctr_drbg.h"
|
2009-01-03 21:51:57 +00:00
|
|
|
#include "polarssl/certs.h"
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
|
|
|
#include "polarssl/timing.h"
|
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
|
2013-09-15 15:07:33 +00:00
|
|
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
|
|
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
|
|
|
|
!defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
|
|
|
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C) || \
|
2013-09-17 11:25:29 +00:00
|
|
|
!defined(POLARSSL_X509_CRT_PARSE_C)
|
2013-09-15 15:07:33 +00:00
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
((void) argc);
|
|
|
|
((void) argv);
|
|
|
|
|
|
|
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
|
|
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
|
|
|
"POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
|
|
|
|
"POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C and/or "
|
2013-09-17 11:25:29 +00:00
|
|
|
"POLARSSL_X509_CRT_PARSE_C not defined.\n");
|
2013-09-15 15:07:33 +00:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
2009-01-03 21:22:43 +00:00
|
|
|
#define OPMODE_NONE 0
|
|
|
|
#define OPMODE_CLIENT 1
|
|
|
|
#define OPMODE_SERVER 2
|
|
|
|
|
|
|
|
#define IOMODE_BLOCK 0
|
|
|
|
#define IOMODE_NONBLOCK 1
|
|
|
|
|
|
|
|
#define COMMAND_READ 1
|
|
|
|
#define COMMAND_WRITE 2
|
|
|
|
#define COMMAND_BOTH 3
|
|
|
|
|
|
|
|
#define DFL_OPMODE OPMODE_NONE
|
|
|
|
#define DFL_IOMODE IOMODE_BLOCK
|
|
|
|
#define DFL_SERVER_NAME "localhost"
|
|
|
|
#define DFL_SERVER_PORT 4433
|
|
|
|
#define DFL_COMMAND COMMAND_READ
|
|
|
|
#define DFL_BUFFER_SIZE 1024
|
|
|
|
#define DFL_MAX_BYTES 0
|
|
|
|
#define DFL_DEBUG_LEVEL 0
|
|
|
|
#define DFL_CONN_TIMEOUT 0
|
|
|
|
#define DFL_MAX_CONNECTIONS 0
|
|
|
|
#define DFL_SESSION_REUSE 1
|
|
|
|
#define DFL_SESSION_LIFETIME 86400
|
|
|
|
#define DFL_FORCE_CIPHER 0
|
|
|
|
|
|
|
|
int server_fd = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global options
|
|
|
|
*/
|
|
|
|
struct options
|
|
|
|
{
|
|
|
|
int opmode; /* operation mode (client or server) */
|
|
|
|
int iomode; /* I/O mode (blocking or non-blocking) */
|
2013-06-24 11:01:08 +00:00
|
|
|
const char *server_name; /* hostname of the server (client only) */
|
2009-01-03 21:22:43 +00:00
|
|
|
int server_port; /* port on which the ssl service runs */
|
|
|
|
int command; /* what to do: read or write operation */
|
|
|
|
int buffer_size; /* size of the send/receive buffer */
|
|
|
|
int max_bytes; /* max. # of bytes before a reconnect */
|
|
|
|
int debug_level; /* level of debugging */
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
int conn_timeout; /* max. delay before a reconnect */
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
int max_connections; /* max. number of reconnections */
|
|
|
|
int session_reuse; /* flag to reuse the keying material */
|
|
|
|
int session_lifetime; /* if reached, session data is expired */
|
2011-01-27 17:40:50 +00:00
|
|
|
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
2009-01-03 21:22:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Although this PRNG has good statistical properties (eg. passes
|
|
|
|
* DIEHARD), it is not cryptographically secure.
|
|
|
|
*/
|
2013-06-25 14:37:45 +00:00
|
|
|
static unsigned long int lcppm5( unsigned long int *state )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
unsigned long int u, v;
|
|
|
|
|
|
|
|
u = v = state[4] ^ 1;
|
|
|
|
state[u & 3] ^= u;
|
|
|
|
u ^= (v << 12) ^ (v >> 12);
|
|
|
|
u ^= v * state[0]; v >>= 8;
|
|
|
|
u ^= v * state[1]; v >>= 8;
|
|
|
|
u ^= v * state[2]; v >>= 8;
|
|
|
|
u ^= v * state[3];
|
|
|
|
u &= 0xFFFFFFFF;
|
|
|
|
state[4] = u;
|
|
|
|
|
|
|
|
return( u );
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:37:45 +00:00
|
|
|
static void my_debug( void *ctx, int level, const char *str )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
if( level < ((struct options *) ctx)->debug_level )
|
|
|
|
fprintf( stderr, "%s", str );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* perform a single SSL connection
|
|
|
|
*/
|
|
|
|
static int ssl_test( struct options *opt )
|
|
|
|
{
|
|
|
|
int ret, i;
|
2013-09-16 10:34:33 +00:00
|
|
|
int client_fd = -1;
|
2009-01-03 21:22:43 +00:00
|
|
|
int bytes_to_read;
|
|
|
|
int bytes_to_write;
|
2009-03-28 17:53:03 +00:00
|
|
|
int offset_to_read = 0;
|
|
|
|
int offset_to_write = 0;
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
long int nb_read;
|
|
|
|
long int nb_written;
|
|
|
|
|
|
|
|
unsigned long read_state[5];
|
|
|
|
unsigned long write_state[5];
|
|
|
|
|
2009-03-28 17:53:03 +00:00
|
|
|
unsigned char *read_buf = NULL;
|
|
|
|
unsigned char *write_buf = NULL;
|
2009-01-03 21:22:43 +00:00
|
|
|
|
2013-06-24 11:01:08 +00:00
|
|
|
const char *pers = "ssl_test";
|
2011-12-04 17:09:26 +00:00
|
|
|
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
struct hr_time t;
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2011-12-04 17:09:26 +00:00
|
|
|
entropy_context entropy;
|
|
|
|
ctr_drbg_context ctr_drbg;
|
2009-01-03 21:22:43 +00:00
|
|
|
ssl_context ssl;
|
2013-09-18 12:13:26 +00:00
|
|
|
x509_crt srvcert;
|
2013-08-19 12:10:16 +00:00
|
|
|
pk_context pkey;
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
2011-12-04 17:09:26 +00:00
|
|
|
entropy_init( &entropy );
|
|
|
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
2013-06-24 11:01:08 +00:00
|
|
|
(const unsigned char *) pers,
|
|
|
|
strlen( pers ) ) ) != 0 )
|
2011-12-04 17:09:26 +00:00
|
|
|
{
|
|
|
|
printf( " ! ctr_drbg_init returned %d\n", ret );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
get_timer( &t, 1 );
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
memset( read_state, 0, sizeof( read_state ) );
|
|
|
|
memset( write_state, 0, sizeof( write_state ) );
|
|
|
|
|
2013-09-18 09:58:25 +00:00
|
|
|
x509_crt_init( &srvcert );
|
2013-08-19 12:10:16 +00:00
|
|
|
pk_init( &pkey );
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
if( opt->opmode == OPMODE_CLIENT )
|
|
|
|
{
|
|
|
|
if( ( ret = net_connect( &client_fd, opt->server_name,
|
|
|
|
opt->server_port ) ) != 0 )
|
|
|
|
{
|
|
|
|
printf( " ! net_connect returned %d\n\n", ret );
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
|
|
|
{
|
|
|
|
printf( " ! ssl_init returned %d\n\n", ret );
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( opt->opmode == OPMODE_SERVER )
|
|
|
|
{
|
2011-05-26 13:16:06 +00:00
|
|
|
#if !defined(POLARSSL_CERTS_C)
|
|
|
|
printf("POLARSSL_CERTS_C not defined.\n");
|
|
|
|
goto exit;
|
|
|
|
#else
|
2013-09-18 11:46:23 +00:00
|
|
|
ret = x509_crt_parse( &srvcert, (const unsigned char *) test_srv_crt,
|
|
|
|
strlen( test_srv_crt ) );
|
2009-01-03 21:22:43 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2013-09-18 11:46:23 +00:00
|
|
|
printf( " ! x509_crt_parse returned %d\n\n", ret );
|
2009-01-03 21:22:43 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-09-25 11:23:33 +00:00
|
|
|
ret = x509_crt_parse( &srvcert, (const unsigned char *) test_ca_list,
|
|
|
|
strlen( test_ca_list ) );
|
2009-01-03 21:22:43 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2013-09-18 11:46:23 +00:00
|
|
|
printf( " ! x509_crt_parse returned %d\n\n", ret );
|
2009-01-03 21:22:43 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2013-09-15 11:01:22 +00:00
|
|
|
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
|
|
|
|
strlen( test_srv_key ), NULL, 0 );
|
2009-01-03 21:22:43 +00:00
|
|
|
if( ret != 0 )
|
|
|
|
{
|
2013-09-15 11:01:22 +00:00
|
|
|
printf( " ! pk_parse_key returned %d\n\n", ret );
|
2009-01-03 21:22:43 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2011-05-26 13:16:06 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
if( server_fd < 0 )
|
|
|
|
{
|
|
|
|
if( ( ret = net_bind( &server_fd, NULL,
|
|
|
|
opt->server_port ) ) != 0 )
|
|
|
|
{
|
|
|
|
printf( " ! net_bind returned %d\n\n", ret );
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( ret = net_accept( server_fd, &client_fd, NULL ) ) != 0 )
|
|
|
|
{
|
|
|
|
printf( " ! net_accept returned %d\n\n", ret );
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
|
|
|
{
|
|
|
|
printf( " ! ssl_init returned %d\n\n", ret );
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
2009-05-03 10:18:48 +00:00
|
|
|
ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
|
2013-08-19 12:10:16 +00:00
|
|
|
ssl_set_own_cert( &ssl, &srvcert, &pkey );
|
2009-01-03 21:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
|
|
|
|
2011-12-04 17:09:26 +00:00
|
|
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
2009-01-03 21:22:43 +00:00
|
|
|
ssl_set_dbg( &ssl, my_debug, opt );
|
|
|
|
ssl_set_bio( &ssl, net_recv, &client_fd,
|
|
|
|
net_send, &client_fd );
|
|
|
|
|
2013-01-07 17:20:04 +00:00
|
|
|
if( opt->force_ciphersuite[0] != DFL_FORCE_CIPHER )
|
|
|
|
ssl_set_ciphersuites( &ssl, opt->force_ciphersuite );
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
if( opt->iomode == IOMODE_NONBLOCK )
|
|
|
|
net_set_nonblock( client_fd );
|
|
|
|
|
|
|
|
read_buf = (unsigned char *) malloc( opt->buffer_size );
|
|
|
|
write_buf = (unsigned char *) malloc( opt->buffer_size );
|
|
|
|
|
|
|
|
if( read_buf == NULL || write_buf == NULL )
|
|
|
|
{
|
|
|
|
printf( " ! malloc(%d bytes) failed\n\n", opt->buffer_size );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_read = bytes_to_read = 0;
|
|
|
|
nb_written = bytes_to_write = 0;
|
|
|
|
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
if( opt->command & COMMAND_WRITE )
|
|
|
|
{
|
|
|
|
if( bytes_to_write == 0 )
|
|
|
|
{
|
|
|
|
while( bytes_to_write == 0 )
|
|
|
|
bytes_to_write = rand() % opt->buffer_size;
|
|
|
|
|
|
|
|
for( i = 0; i < bytes_to_write; i++ )
|
|
|
|
write_buf[i] = (unsigned char) lcppm5( write_state );
|
|
|
|
|
|
|
|
offset_to_write = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssl_write( &ssl, write_buf + offset_to_write,
|
|
|
|
bytes_to_write );
|
|
|
|
|
|
|
|
if( ret >= 0 )
|
|
|
|
{
|
|
|
|
nb_written += ret;
|
|
|
|
bytes_to_write -= ret;
|
|
|
|
offset_to_write += ret;
|
|
|
|
}
|
|
|
|
|
2009-01-03 21:51:57 +00:00
|
|
|
if( ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
|
|
|
|
ret == POLARSSL_ERR_NET_CONN_RESET )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-05-18 13:32:51 +00:00
|
|
|
if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
|
|
|
|
ret != POLARSSL_ERR_NET_WANT_WRITE )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
printf( " ! ssl_write returned %d\n\n", ret );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( opt->command & COMMAND_READ )
|
|
|
|
{
|
2013-09-26 11:32:19 +00:00
|
|
|
while( bytes_to_read == 0 )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
bytes_to_read = rand() % opt->buffer_size;
|
|
|
|
offset_to_read = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ssl_read( &ssl, read_buf + offset_to_read,
|
|
|
|
bytes_to_read );
|
|
|
|
|
2013-09-26 11:32:19 +00:00
|
|
|
if( ret > 0 )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
for( i = 0; i < ret; i++ )
|
|
|
|
{
|
|
|
|
if( read_buf[offset_to_read + i] !=
|
|
|
|
(unsigned char) lcppm5( read_state ) )
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
printf( " ! plaintext mismatch\n\n" );
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_read += ret;
|
|
|
|
bytes_to_read -= ret;
|
|
|
|
offset_to_read += ret;
|
|
|
|
}
|
|
|
|
|
2013-09-26 11:32:19 +00:00
|
|
|
if( ret == 0 ||
|
|
|
|
ret == POLARSSL_ERR_SSL_CONN_EOF ||
|
|
|
|
ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY ||
|
2009-01-03 21:51:57 +00:00
|
|
|
ret == POLARSSL_ERR_NET_CONN_RESET )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-05-18 13:32:51 +00:00
|
|
|
if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
|
|
|
|
ret != POLARSSL_ERR_NET_WANT_WRITE )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
|
|
|
printf( " ! ssl_read returned %d\n\n", ret );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if( opt->max_bytes != 0 &&
|
|
|
|
( opt->max_bytes <= nb_read ||
|
|
|
|
opt->max_bytes <= nb_written ) )
|
|
|
|
break;
|
|
|
|
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
if( opt->conn_timeout != 0 &&
|
|
|
|
opt->conn_timeout <= (int) get_timer( &t, 0 ) )
|
|
|
|
break;
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
if( read_buf != NULL )
|
|
|
|
free( read_buf );
|
|
|
|
|
|
|
|
if( write_buf != NULL )
|
|
|
|
free( write_buf );
|
|
|
|
|
|
|
|
ssl_close_notify( &ssl );
|
2013-09-17 11:25:29 +00:00
|
|
|
x509_crt_free( &srvcert );
|
2013-08-19 12:10:16 +00:00
|
|
|
pk_free( &pkey );
|
2009-01-03 21:22:43 +00:00
|
|
|
ssl_free( &ssl );
|
2013-09-28 13:23:03 +00:00
|
|
|
entropy_free( &entropy );
|
2009-01-03 21:22:43 +00:00
|
|
|
net_close( client_fd );
|
|
|
|
|
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
|
|
|
#define USAGE_TIMING \
|
|
|
|
" conn_timeout=%%d (ms) default: 0 (no timeout)\n"
|
|
|
|
#else
|
|
|
|
#define USAGE_TIMING ""
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 21:22:43 +00:00
|
|
|
#define USAGE \
|
|
|
|
"\n usage: ssl_test opmode=<> command=<>...\n" \
|
|
|
|
"\n acceptable parameters:\n" \
|
|
|
|
" opmode=client/server default: <none>\n" \
|
|
|
|
" iomode=block/nonblock default: block\n" \
|
|
|
|
" server_name=%%s default: localhost\n" \
|
|
|
|
" server_port=%%d default: 4433\n" \
|
|
|
|
" command=read/write/both default: read\n" \
|
|
|
|
" buffer_size=%%d (bytes) default: 1024\n" \
|
|
|
|
" max_bytes=%%d (bytes) default: 0 (no limit)\n" \
|
|
|
|
" debug_level=%%d default: 0 (disabled)\n" \
|
2013-07-04 08:34:10 +00:00
|
|
|
USAGE_TIMING \
|
2009-01-03 21:22:43 +00:00
|
|
|
" max_connections=%%d default: 0 (no limit)\n" \
|
|
|
|
" session_reuse=on/off default: on (enabled)\n" \
|
|
|
|
" session_lifetime=%%d (s) default: 86400\n" \
|
2011-01-27 17:40:50 +00:00
|
|
|
" force_ciphersuite=<name> default: all enabled\n" \
|
|
|
|
" acceptable ciphersuite names:\n"
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
2013-11-30 14:13:02 +00:00
|
|
|
int i;
|
2011-01-27 17:40:50 +00:00
|
|
|
const int *list;
|
2009-01-03 21:22:43 +00:00
|
|
|
int ret = 1;
|
|
|
|
int nb_conn;
|
|
|
|
char *p, *q;
|
|
|
|
struct options opt;
|
|
|
|
|
|
|
|
if( argc == 1 )
|
|
|
|
{
|
|
|
|
usage:
|
|
|
|
printf( USAGE );
|
2013-07-04 08:34:10 +00:00
|
|
|
|
2011-01-27 17:40:50 +00:00
|
|
|
list = ssl_list_ciphersuites();
|
|
|
|
while( *list )
|
|
|
|
{
|
|
|
|
printf(" %s\n", ssl_get_ciphersuite_name( *list ) );
|
|
|
|
list++;
|
|
|
|
}
|
|
|
|
printf("\n");
|
2009-01-03 21:22:43 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt.opmode = DFL_OPMODE;
|
|
|
|
opt.iomode = DFL_IOMODE;
|
|
|
|
opt.server_name = DFL_SERVER_NAME;
|
|
|
|
opt.server_port = DFL_SERVER_PORT;
|
|
|
|
opt.command = DFL_COMMAND;
|
|
|
|
opt.buffer_size = DFL_BUFFER_SIZE;
|
|
|
|
opt.max_bytes = DFL_MAX_BYTES;
|
|
|
|
opt.debug_level = DFL_DEBUG_LEVEL;
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
opt.conn_timeout = DFL_CONN_TIMEOUT;
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
opt.max_connections = DFL_MAX_CONNECTIONS;
|
|
|
|
opt.session_reuse = DFL_SESSION_REUSE;
|
|
|
|
opt.session_lifetime = DFL_SESSION_LIFETIME;
|
2011-01-27 17:40:50 +00:00
|
|
|
opt.force_ciphersuite[0] = DFL_FORCE_CIPHER;
|
2009-01-03 21:22:43 +00:00
|
|
|
|
|
|
|
for( i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
p = argv[i];
|
|
|
|
if( ( q = strchr( p, '=' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
*q++ = '\0';
|
|
|
|
|
|
|
|
if( strcmp( p, "opmode" ) == 0 )
|
|
|
|
{
|
|
|
|
if( strcmp( q, "client" ) == 0 )
|
|
|
|
opt.opmode = OPMODE_CLIENT;
|
|
|
|
else
|
|
|
|
if( strcmp( q, "server" ) == 0 )
|
|
|
|
opt.opmode = OPMODE_SERVER;
|
|
|
|
else goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "iomode" ) == 0 )
|
|
|
|
{
|
|
|
|
if( strcmp( q, "block" ) == 0 )
|
|
|
|
opt.iomode = IOMODE_BLOCK;
|
|
|
|
else
|
|
|
|
if( strcmp( q, "nonblock" ) == 0 )
|
|
|
|
opt.iomode = IOMODE_NONBLOCK;
|
|
|
|
else goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "server_name" ) == 0 )
|
|
|
|
opt.server_name = q;
|
|
|
|
|
|
|
|
if( strcmp( p, "server_port" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.server_port = atoi( q );
|
|
|
|
if( opt.server_port < 1 || opt.server_port > 65535 )
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "command" ) == 0 )
|
|
|
|
{
|
|
|
|
if( strcmp( q, "read" ) == 0 )
|
|
|
|
opt.command = COMMAND_READ;
|
|
|
|
else
|
|
|
|
if( strcmp( q, "write" ) == 0 )
|
|
|
|
opt.command = COMMAND_WRITE;
|
|
|
|
else
|
|
|
|
if( strcmp( q, "both" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.iomode = IOMODE_NONBLOCK;
|
|
|
|
opt.command = COMMAND_BOTH;
|
|
|
|
}
|
|
|
|
else goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "buffer_size" ) == 0 )
|
|
|
|
{
|
|
|
|
opt.buffer_size = atoi( q );
|
|
|
|
if( opt.buffer_size < 1 || opt.buffer_size > 1048576 )
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "max_bytes" ) == 0 )
|
|
|
|
opt.max_bytes = atoi( q );
|
|
|
|
|
|
|
|
if( strcmp( p, "debug_level" ) == 0 )
|
|
|
|
opt.debug_level = atoi( q );
|
2013-07-04 08:34:10 +00:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2009-01-03 21:22:43 +00:00
|
|
|
if( strcmp( p, "conn_timeout" ) == 0 )
|
|
|
|
opt.conn_timeout = atoi( q );
|
2013-07-04 08:34:10 +00:00
|
|
|
#endif
|
2009-01-03 21:22:43 +00:00
|
|
|
if( strcmp( p, "max_connections" ) == 0 )
|
|
|
|
opt.max_connections = atoi( q );
|
|
|
|
|
|
|
|
if( strcmp( p, "session_reuse" ) == 0 )
|
|
|
|
{
|
|
|
|
if( strcmp( q, "on" ) == 0 )
|
|
|
|
opt.session_reuse = 1;
|
|
|
|
else
|
|
|
|
if( strcmp( q, "off" ) == 0 )
|
|
|
|
opt.session_reuse = 0;
|
|
|
|
else
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strcmp( p, "session_lifetime" ) == 0 )
|
|
|
|
opt.session_lifetime = atoi( q );
|
|
|
|
|
2011-01-27 17:40:50 +00:00
|
|
|
if( strcmp( p, "force_ciphersuite" ) == 0 )
|
2009-01-03 21:22:43 +00:00
|
|
|
{
|
2011-01-27 17:40:50 +00:00
|
|
|
opt.force_ciphersuite[0] = -1;
|
2009-01-11 20:25:36 +00:00
|
|
|
|
2011-01-27 17:40:50 +00:00
|
|
|
opt.force_ciphersuite[0] = ssl_get_ciphersuite_id( q );
|
2009-01-11 20:25:36 +00:00
|
|
|
|
2011-01-27 17:40:50 +00:00
|
|
|
if( opt.force_ciphersuite[0] <= 0 )
|
2009-01-03 21:22:43 +00:00
|
|
|
goto usage;
|
|
|
|
|
2011-01-27 17:40:50 +00:00
|
|
|
opt.force_ciphersuite[1] = 0;
|
2009-01-03 21:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( opt.opmode )
|
|
|
|
{
|
|
|
|
case OPMODE_CLIENT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OPMODE_SERVER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_conn = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
nb_conn++;
|
|
|
|
ret = ssl_test( &opt );
|
|
|
|
if( opt.max_connections != 0 &&
|
|
|
|
opt.max_connections <= nb_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while( ret == 0 );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
2011-11-18 14:26:47 +00:00
|
|
|
#if defined(_WIN32)
|
2009-01-03 21:22:43 +00:00
|
|
|
printf( " Press Enter to exit this program.\n" );
|
|
|
|
fflush( stdout ); getchar();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( ret );
|
|
|
|
}
|
2011-12-04 17:09:26 +00:00
|
|
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
2011-05-26 13:16:06 +00:00
|
|
|
POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
|
2011-12-04 17:09:26 +00:00
|
|
|
POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */
|