os/ossrv/ssl/tsrc/topenssl/src/s_time.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* apps/s_time.c */
sl@0
     2
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
sl@0
     3
 * All rights reserved.
sl@0
     4
 *
sl@0
     5
 * This package is an SSL implementation written
sl@0
     6
 * by Eric Young (eay@cryptsoft.com).
sl@0
     7
 * The implementation was written so as to conform with Netscapes SSL.
sl@0
     8
 * 
sl@0
     9
 * This library is free for commercial and non-commercial use as long as
sl@0
    10
 * the following conditions are aheared to.  The following conditions
sl@0
    11
 * apply to all code found in this distribution, be it the RC4, RSA,
sl@0
    12
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
sl@0
    13
 * included with this distribution is covered by the same copyright terms
sl@0
    14
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
sl@0
    15
 * 
sl@0
    16
 * Copyright remains Eric Young's, and as such any Copyright notices in
sl@0
    17
 * the code are not to be removed.
sl@0
    18
 * If this package is used in a product, Eric Young should be given attribution
sl@0
    19
 * as the author of the parts of the library used.
sl@0
    20
 * This can be in the form of a textual message at program startup or
sl@0
    21
 * in documentation (online or textual) provided with the package.
sl@0
    22
 * 
sl@0
    23
 * Redistribution and use in source and binary forms, with or without
sl@0
    24
 * modification, are permitted provided that the following conditions
sl@0
    25
 * are met:
sl@0
    26
 * 1. Redistributions of source code must retain the copyright
sl@0
    27
 *    notice, this list of conditions and the following disclaimer.
sl@0
    28
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    29
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    30
 *    documentation and/or other materials provided with the distribution.
sl@0
    31
 * 3. All advertising materials mentioning features or use of this software
sl@0
    32
 *    must display the following acknowledgement:
sl@0
    33
 *    "This product includes cryptographic software written by
sl@0
    34
 *     Eric Young (eay@cryptsoft.com)"
sl@0
    35
 *    The word 'cryptographic' can be left out if the rouines from the library
sl@0
    36
 *    being used are not cryptographic related :-).
sl@0
    37
 * 4. If you include any Windows specific code (or a derivative thereof) from 
sl@0
    38
 *    the apps directory (application code) you must include an acknowledgement:
sl@0
    39
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
sl@0
    40
 * 
sl@0
    41
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
sl@0
    42
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    44
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
sl@0
    45
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
sl@0
    46
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
sl@0
    47
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    48
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
sl@0
    49
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
sl@0
    50
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
sl@0
    51
 * SUCH DAMAGE.
sl@0
    52
 * 
sl@0
    53
 * The licence and distribution terms for any publically available version or
sl@0
    54
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
sl@0
    55
 * copied and put under another distribution licence
sl@0
    56
 * [including the GNU Public Licence.]
sl@0
    57
 */
sl@0
    58
sl@0
    59
#define NO_SHUTDOWN
sl@0
    60
sl@0
    61
/*-----------------------------------------
sl@0
    62
   s_time - SSL client connection timer program
sl@0
    63
   Written and donated by Larry Streepy <streepy@healthcare.com>
sl@0
    64
  -----------------------------------------*/
sl@0
    65
#include <sys/select.h>
sl@0
    66
#include <stdio.h>
sl@0
    67
#include <stdlib.h>
sl@0
    68
#include <string.h>
sl@0
    69
sl@0
    70
#define USE_SOCKETS
sl@0
    71
#include "apps.h"
sl@0
    72
#ifdef OPENSSL_NO_STDIO
sl@0
    73
#define APPS_WIN16
sl@0
    74
#endif
sl@0
    75
#include <openssl/x509.h>
sl@0
    76
#include <openssl/ssl.h>
sl@0
    77
#include <openssl/pem.h>
sl@0
    78
#include "s_apps.h"
sl@0
    79
#include <openssl/err.h>
sl@0
    80
#ifdef WIN32_STUFF
sl@0
    81
#include "winmain.h"
sl@0
    82
#include "wintext.h"
sl@0
    83
#endif
sl@0
    84
#if !defined(OPENSSL_SYS_MSDOS)
sl@0
    85
#include OPENSSL_UNISTD
sl@0
    86
#endif
sl@0
    87
sl@0
    88
#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
sl@0
    89
#define TIMES
sl@0
    90
#endif
sl@0
    91
sl@0
    92
#ifndef _IRIX
sl@0
    93
#include <time.h>
sl@0
    94
#endif
sl@0
    95
#ifdef TIMES
sl@0
    96
#include <sys/types.h>
sl@0
    97
#include <sys/times.h>
sl@0
    98
#endif
sl@0
    99
sl@0
   100
/* Depending on the VMS version, the tms structure is perhaps defined.
sl@0
   101
   The __TMS macro will show if it was.  If it wasn't defined, we should
sl@0
   102
   undefine TIMES, since that tells the rest of the program how things
sl@0
   103
   should be handled.				-- Richard Levitte */
sl@0
   104
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
sl@0
   105
#undef TIMES
sl@0
   106
#endif
sl@0
   107
sl@0
   108
#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
sl@0
   109
#include <sys/timeb.h>
sl@0
   110
#endif
sl@0
   111
sl@0
   112
#if defined(sun) || defined(__ultrix)
sl@0
   113
#define _POSIX_SOURCE
sl@0
   114
#include <limits.h>
sl@0
   115
#include <sys/param.h>
sl@0
   116
#endif
sl@0
   117
sl@0
   118
/* The following if from times(3) man page.  It may need to be changed
sl@0
   119
*/
sl@0
   120
#ifndef HZ
sl@0
   121
# ifdef _SC_CLK_TCK
sl@0
   122
#  define HZ ((double)sysconf(_SC_CLK_TCK))
sl@0
   123
# else
sl@0
   124
#  ifndef CLK_TCK
sl@0
   125
#   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
sl@0
   126
#    define HZ	100.0
sl@0
   127
#   else /* _BSD_CLK_TCK_ */
sl@0
   128
#    define HZ ((double)_BSD_CLK_TCK_)
sl@0
   129
#   endif
sl@0
   130
#  else /* CLK_TCK */
sl@0
   131
#   define HZ ((double)CLK_TCK)
sl@0
   132
#  endif
sl@0
   133
# endif
sl@0
   134
#endif
sl@0
   135
sl@0
   136
#undef PROG
sl@0
   137
#define PROG s_time_main
sl@0
   138
sl@0
   139
#undef ioctl
sl@0
   140
#define ioctl ioctlsocket
sl@0
   141
sl@0
   142
#define SSL_CONNECT_NAME	"localhost:4433"
sl@0
   143
sl@0
   144
/*#define TEST_CERT "client.pem" */ /* no default cert. */
sl@0
   145
sl@0
   146
#undef BUFSIZZ
sl@0
   147
#define BUFSIZZ 1024*10
sl@0
   148
sl@0
   149
#define MYBUFSIZ 1024*8
sl@0
   150
sl@0
   151
#undef min
sl@0
   152
#undef max
sl@0
   153
#define min(a,b) (((a) < (b)) ? (a) : (b))
sl@0
   154
#define max(a,b) (((a) > (b)) ? (a) : (b))
sl@0
   155
sl@0
   156
#undef SECONDS
sl@0
   157
#define SECONDS	30
sl@0
   158
extern int verify_depth;
sl@0
   159
extern int verify_error;
sl@0
   160
sl@0
   161
static void s_time_usage(void);
sl@0
   162
static int parseArgs( int argc, char **argv );
sl@0
   163
static SSL *doConnection( SSL *scon );
sl@0
   164
static void s_time_init(void);
sl@0
   165
sl@0
   166
/***********************************************************************
sl@0
   167
 * Static data declarations
sl@0
   168
 */
sl@0
   169
sl@0
   170
/* static char *port=PORT_STR;*/
sl@0
   171
static char *host=SSL_CONNECT_NAME;
sl@0
   172
static char *t_cert_file=NULL;
sl@0
   173
static char *t_key_file=NULL;
sl@0
   174
static char *CApath=NULL;
sl@0
   175
static char *CAfile=NULL;
sl@0
   176
static char *tm_cipher=NULL;
sl@0
   177
static int tm_verify = SSL_VERIFY_NONE;
sl@0
   178
static int maxTime = SECONDS;
sl@0
   179
static SSL_CTX *tm_ctx=NULL;
sl@0
   180
static SSL_METHOD *s_time_meth=NULL;
sl@0
   181
static char *s_www_path=NULL;
sl@0
   182
static long bytes_read=0; 
sl@0
   183
static int st_bugs=0;
sl@0
   184
static int perform=0;
sl@0
   185
#ifdef FIONBIO
sl@0
   186
static int t_nbio=0;
sl@0
   187
#endif
sl@0
   188
#ifdef OPENSSL_SYS_WIN32
sl@0
   189
static int exitNow = 0;		/* Set when it's time to exit main */
sl@0
   190
#endif
sl@0
   191
sl@0
   192
static void s_time_init(void)
sl@0
   193
	{
sl@0
   194
	host=SSL_CONNECT_NAME;
sl@0
   195
	t_cert_file=NULL;
sl@0
   196
	t_key_file=NULL;
sl@0
   197
	CApath=NULL;
sl@0
   198
	CAfile=NULL;
sl@0
   199
	tm_cipher=NULL;
sl@0
   200
	tm_verify = SSL_VERIFY_NONE;
sl@0
   201
	maxTime = SECONDS;
sl@0
   202
	tm_ctx=NULL;
sl@0
   203
	s_time_meth=NULL;
sl@0
   204
	s_www_path=NULL;
sl@0
   205
	bytes_read=0; 
sl@0
   206
	st_bugs=0;
sl@0
   207
	perform=0;
sl@0
   208
sl@0
   209
#ifdef FIONBIO
sl@0
   210
	t_nbio=0;
sl@0
   211
#endif
sl@0
   212
#ifdef OPENSSL_SYS_WIN32
sl@0
   213
	exitNow = 0;		/* Set when it's time to exit main */
sl@0
   214
#endif
sl@0
   215
	}
sl@0
   216
sl@0
   217
sl@0
   218
/***********************************************************************
sl@0
   219
 * usage - display usage message
sl@0
   220
 */
sl@0
   221
static void s_time_usage(void)
sl@0
   222
{
sl@0
   223
	static char umsg[] = "\
sl@0
   224
-time arg     - max number of seconds to collect data, default %d\n\
sl@0
   225
-verify arg   - turn on peer certificate verification, arg == depth\n\
sl@0
   226
-cert arg     - certificate file to use, PEM format assumed\n\
sl@0
   227
-key arg      - RSA file to use, PEM format assumed, key is in cert file\n\
sl@0
   228
                file if not specified by this option\n\
sl@0
   229
-CApath arg   - PEM format directory of CA's\n\
sl@0
   230
-CAfile arg   - PEM format file of CA's\n\
sl@0
   231
-cipher       - preferred cipher to use, play with 'openssl ciphers'\n\n";
sl@0
   232
sl@0
   233
	printf( "usage: s_time <args>\n\n" );
sl@0
   234
sl@0
   235
	printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
sl@0
   236
#ifdef FIONBIO
sl@0
   237
	printf("-nbio         - Run with non-blocking IO\n");
sl@0
   238
	printf("-ssl2         - Just use SSLv2\n");
sl@0
   239
	printf("-ssl3         - Just use SSLv3\n");
sl@0
   240
	printf("-bugs         - Turn on SSL bug compatibility\n");
sl@0
   241
	printf("-new          - Just time new connections\n");
sl@0
   242
	printf("-reuse        - Just time connection reuse\n");
sl@0
   243
	printf("-www page     - Retrieve 'page' from the site\n");
sl@0
   244
#endif
sl@0
   245
	printf( umsg,SECONDS );
sl@0
   246
sl@0
   247
}
sl@0
   248
sl@0
   249
/***********************************************************************
sl@0
   250
 * parseArgs - Parse command line arguments and initialize data
sl@0
   251
 *
sl@0
   252
 * Returns 0 if ok, -1 on bad args
sl@0
   253
 */
sl@0
   254
static int parseArgs(int argc, char **argv)
sl@0
   255
{
sl@0
   256
    int badop = 0;
sl@0
   257
sl@0
   258
    verify_depth=0;
sl@0
   259
    verify_error=X509_V_OK;
sl@0
   260
sl@0
   261
    argc--;
sl@0
   262
    argv++;
sl@0
   263
sl@0
   264
    while (argc >= 1) {
sl@0
   265
	if (strcmp(*argv,"-connect") == 0)
sl@0
   266
		{
sl@0
   267
		if (--argc < 1) goto bad;
sl@0
   268
		host= *(++argv);
sl@0
   269
		}
sl@0
   270
#if 0
sl@0
   271
	else if( strcmp(*argv,"-host") == 0)
sl@0
   272
		{
sl@0
   273
		if (--argc < 1) goto bad;
sl@0
   274
		host= *(++argv);
sl@0
   275
		}
sl@0
   276
	else if( strcmp(*argv,"-port") == 0)
sl@0
   277
		{
sl@0
   278
		if (--argc < 1) goto bad;
sl@0
   279
		port= *(++argv);
sl@0
   280
		}
sl@0
   281
#endif
sl@0
   282
	else if (strcmp(*argv,"-reuse") == 0)
sl@0
   283
		perform=2;
sl@0
   284
	else if (strcmp(*argv,"-new") == 0)
sl@0
   285
		perform=1;
sl@0
   286
	else if( strcmp(*argv,"-verify") == 0) {
sl@0
   287
sl@0
   288
	    tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
sl@0
   289
	    if (--argc < 1) goto bad;
sl@0
   290
	    verify_depth=atoi(*(++argv));
sl@0
   291
	    BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
sl@0
   292
sl@0
   293
	} else if( strcmp(*argv,"-cert") == 0) {
sl@0
   294
sl@0
   295
	    if (--argc < 1) goto bad;
sl@0
   296
	    t_cert_file= *(++argv);
sl@0
   297
sl@0
   298
	} else if( strcmp(*argv,"-key") == 0) {
sl@0
   299
sl@0
   300
	    if (--argc < 1) goto bad;
sl@0
   301
	    t_key_file= *(++argv);
sl@0
   302
sl@0
   303
	} else if( strcmp(*argv,"-CApath") == 0) {
sl@0
   304
sl@0
   305
	    if (--argc < 1) goto bad;
sl@0
   306
	    CApath= *(++argv);
sl@0
   307
sl@0
   308
	} else if( strcmp(*argv,"-CAfile") == 0) {
sl@0
   309
sl@0
   310
	    if (--argc < 1) goto bad;
sl@0
   311
	    CAfile= *(++argv);
sl@0
   312
sl@0
   313
	} else if( strcmp(*argv,"-cipher") == 0) {
sl@0
   314
sl@0
   315
	    if (--argc < 1) goto bad;
sl@0
   316
	    tm_cipher= *(++argv);
sl@0
   317
	}
sl@0
   318
#ifdef FIONBIO
sl@0
   319
	else if(strcmp(*argv,"-nbio") == 0) {
sl@0
   320
	    t_nbio=1;
sl@0
   321
	}
sl@0
   322
#endif
sl@0
   323
	else if(strcmp(*argv,"-www") == 0)
sl@0
   324
		{
sl@0
   325
		if (--argc < 1) goto bad;
sl@0
   326
		s_www_path= *(++argv);
sl@0
   327
		if(strlen(s_www_path) > MYBUFSIZ-100)
sl@0
   328
			{
sl@0
   329
			BIO_printf(bio_err,"-www option too long\n");
sl@0
   330
			badop=1;
sl@0
   331
			}
sl@0
   332
		}
sl@0
   333
	else if(strcmp(*argv,"-bugs") == 0)
sl@0
   334
	    st_bugs=1;
sl@0
   335
#ifndef OPENSSL_NO_SSL2
sl@0
   336
	else if(strcmp(*argv,"-ssl2") == 0)
sl@0
   337
	    s_time_meth=SSLv2_client_method();
sl@0
   338
#endif
sl@0
   339
#ifndef OPENSSL_NO_SSL3
sl@0
   340
	else if(strcmp(*argv,"-ssl3") == 0)
sl@0
   341
	    s_time_meth=SSLv3_client_method();
sl@0
   342
#endif
sl@0
   343
	else if( strcmp(*argv,"-time") == 0) {
sl@0
   344
sl@0
   345
	    if (--argc < 1) goto bad;
sl@0
   346
	    maxTime= atoi(*(++argv));
sl@0
   347
	}
sl@0
   348
	else {
sl@0
   349
	    BIO_printf(bio_err,"unknown option %s\n",*argv);
sl@0
   350
	    badop=1;
sl@0
   351
	    break;
sl@0
   352
	}
sl@0
   353
sl@0
   354
	argc--;
sl@0
   355
	argv++;
sl@0
   356
    }
sl@0
   357
sl@0
   358
    if (perform == 0) perform=3;
sl@0
   359
sl@0
   360
    if(badop) {
sl@0
   361
bad:
sl@0
   362
		s_time_usage();
sl@0
   363
		return -1;
sl@0
   364
    }
sl@0
   365
sl@0
   366
	return 0;			/* Valid args */
sl@0
   367
}
sl@0
   368
sl@0
   369
/***********************************************************************
sl@0
   370
 * TIME - time functions
sl@0
   371
 */
sl@0
   372
#define START	0
sl@0
   373
#define STOP	1
sl@0
   374
sl@0
   375
static double tm_Time_F(int s)
sl@0
   376
	{
sl@0
   377
	static double ret;
sl@0
   378
#ifdef TIMES
sl@0
   379
	static struct tms tstart,tend;
sl@0
   380
sl@0
   381
	if(s == START) {
sl@0
   382
		//times(&tstart); shilps
sl@0
   383
		return(0);
sl@0
   384
	} else {
sl@0
   385
		//times(&tend); shilpa
sl@0
   386
		ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
sl@0
   387
		return((ret == 0.0)?1e-6:ret);
sl@0
   388
	}
sl@0
   389
#elif defined(OPENSSL_SYS_NETWARE)
sl@0
   390
    static clock_t tstart,tend;
sl@0
   391
sl@0
   392
    if (s == START)
sl@0
   393
    {
sl@0
   394
        tstart=clock();
sl@0
   395
        return(0);
sl@0
   396
    }
sl@0
   397
    else
sl@0
   398
    {
sl@0
   399
        tend=clock();
sl@0
   400
        ret=(double)((double)(tend)-(double)(tstart));
sl@0
   401
        return((ret < 0.001)?0.001:ret);
sl@0
   402
    }
sl@0
   403
#elif defined(OPENSSL_SYS_VXWORKS)
sl@0
   404
        {
sl@0
   405
	static unsigned long tick_start, tick_end;
sl@0
   406
sl@0
   407
	if( s == START )
sl@0
   408
		{
sl@0
   409
		tick_start = tickGet();
sl@0
   410
		return 0;
sl@0
   411
		}
sl@0
   412
	else
sl@0
   413
		{
sl@0
   414
		tick_end = tickGet();
sl@0
   415
		ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
sl@0
   416
		return((ret == 0.0)?1e-6:ret);
sl@0
   417
		}
sl@0
   418
        }
sl@0
   419
#else /* !times() */
sl@0
   420
	static struct timeb tstart,tend;
sl@0
   421
	long i;
sl@0
   422
sl@0
   423
	if(s == START) {
sl@0
   424
		ftime(&tstart);
sl@0
   425
		return(0);
sl@0
   426
	} else {
sl@0
   427
		ftime(&tend);
sl@0
   428
		i=(long)tend.millitm-(long)tstart.millitm;
sl@0
   429
		ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
sl@0
   430
		return((ret == 0.0)?1e-6:ret);
sl@0
   431
	}
sl@0
   432
#endif
sl@0
   433
}
sl@0
   434
sl@0
   435
/***********************************************************************
sl@0
   436
 * MAIN - main processing area for client
sl@0
   437
 *			real name depends on MONOLITH
sl@0
   438
 */
sl@0
   439
int MAIN(int, char **);
sl@0
   440
sl@0
   441
int MAIN(int argc, char **argv)
sl@0
   442
	{
sl@0
   443
	double totalTime = 0.0;
sl@0
   444
	int nConn = 0;
sl@0
   445
	SSL *scon=NULL;
sl@0
   446
	long finishtime=0;
sl@0
   447
	int ret=1,i;
sl@0
   448
	MS_STATIC char buf[1024*8];
sl@0
   449
	int ver;
sl@0
   450
sl@0
   451
	apps_startup();
sl@0
   452
	s_time_init();
sl@0
   453
sl@0
   454
	if (bio_err == NULL)
sl@0
   455
		bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
sl@0
   456
sl@0
   457
#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
sl@0
   458
	s_time_meth=SSLv23_client_method();
sl@0
   459
#elif !defined(OPENSSL_NO_SSL3)
sl@0
   460
	s_time_meth=SSLv3_client_method();
sl@0
   461
#elif !defined(OPENSSL_NO_SSL2)
sl@0
   462
	s_time_meth=SSLv2_client_method();
sl@0
   463
#endif
sl@0
   464
sl@0
   465
	/* parse the command line arguments */
sl@0
   466
	if( parseArgs( argc, argv ) < 0 )
sl@0
   467
		goto end;
sl@0
   468
sl@0
   469
	OpenSSL_add_ssl_algorithms();
sl@0
   470
	if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
sl@0
   471
sl@0
   472
	SSL_CTX_set_quiet_shutdown(tm_ctx,1);
sl@0
   473
sl@0
   474
	if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
sl@0
   475
	SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
sl@0
   476
	if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file)) 
sl@0
   477
		goto end;
sl@0
   478
sl@0
   479
	SSL_load_error_strings();
sl@0
   480
sl@0
   481
	if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
sl@0
   482
		(!SSL_CTX_set_default_verify_paths(tm_ctx)))
sl@0
   483
		{
sl@0
   484
		/* BIO_printf(bio_err,"error setting default verify locations\n"); */
sl@0
   485
		ERR_print_errors(bio_err);
sl@0
   486
		/* goto end; */
sl@0
   487
		}
sl@0
   488
sl@0
   489
	if (tm_cipher == NULL)
sl@0
   490
		tm_cipher = getenv("SSL_CIPHER");
sl@0
   491
sl@0
   492
	if (tm_cipher == NULL ) {
sl@0
   493
		fprintf( stderr, "No CIPHER specified\n" );
sl@0
   494
sl@0
   495
		
sl@0
   496
	}
sl@0
   497
sl@0
   498
	if (!(perform & 1)) goto next;
sl@0
   499
	printf( "Collecting connection statistics for %d seconds\n", maxTime );
sl@0
   500
sl@0
   501
	/* Loop and time how long it takes to make connections */
sl@0
   502
sl@0
   503
	bytes_read=0;
sl@0
   504
	finishtime=(long)time(NULL)+maxTime;
sl@0
   505
	tm_Time_F(START);
sl@0
   506
	for (;;)
sl@0
   507
		{
sl@0
   508
		if (finishtime < (long)time(NULL)) break;
sl@0
   509
#ifdef WIN32_STUFF
sl@0
   510
sl@0
   511
		if( flushWinMsgs(0) == -1 )
sl@0
   512
			goto end;
sl@0
   513
sl@0
   514
		if( waitingToDie || exitNow )		/* we're dead */
sl@0
   515
			goto end;
sl@0
   516
#endif
sl@0
   517
sl@0
   518
		if( (scon = doConnection( NULL )) == NULL )
sl@0
   519
			goto end;
sl@0
   520
sl@0
   521
		if (s_www_path != NULL)
sl@0
   522
			{
sl@0
   523
			BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
sl@0
   524
			SSL_write(scon,buf,strlen(buf));
sl@0
   525
			while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
sl@0
   526
				bytes_read+=i;
sl@0
   527
			}
sl@0
   528
sl@0
   529
#ifdef NO_SHUTDOWN
sl@0
   530
		SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
sl@0
   531
#else
sl@0
   532
		SSL_shutdown(scon);
sl@0
   533
#endif
sl@0
   534
		SHUTDOWN2(SSL_get_fd(scon));
sl@0
   535
sl@0
   536
		nConn += 1;
sl@0
   537
		if (SSL_session_reused(scon))
sl@0
   538
			ver='r';
sl@0
   539
		else
sl@0
   540
			{
sl@0
   541
			ver=SSL_version(scon);
sl@0
   542
			if (ver == TLS1_VERSION)
sl@0
   543
				ver='t';
sl@0
   544
			else if (ver == SSL3_VERSION)
sl@0
   545
				ver='3';
sl@0
   546
			else if (ver == SSL2_VERSION)
sl@0
   547
				ver='2';
sl@0
   548
			else
sl@0
   549
				ver='*';
sl@0
   550
			}
sl@0
   551
		fputc(ver,stdout);
sl@0
   552
		fflush(stdout);
sl@0
   553
		SSL_free( scon );
sl@0
   554
		scon=NULL;
sl@0
   555
		}
sl@0
   556
	totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
sl@0
   557
sl@0
   558
	i=(int)((long)time(NULL)-finishtime+maxTime);
sl@0
   559
	printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
sl@0
   560
	printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
sl@0
   561
sl@0
   562
sl@0
   563
	/* Now loop and time connections using the same session id over and over */
sl@0
   564
sl@0
   565
next:
sl@0
   566
	if (!(perform & 2)) goto end;
sl@0
   567
sl@0
   568
	printf( "\n\nNow timing with session id reuse.\n" );
sl@0
   569
sl@0
   570
sl@0
   571
	/* Get an SSL object so we can reuse the session id */
sl@0
   572
	if( (scon = doConnection( NULL )) == NULL )
sl@0
   573
		{
sl@0
   574
		fprintf( stderr, "Unable to get connection\n" );
sl@0
   575
		goto end;
sl@0
   576
		}
sl@0
   577
sl@0
   578
	if (s_www_path != NULL)
sl@0
   579
		{
sl@0
   580
		BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
sl@0
   581
		SSL_write(scon,buf,strlen(buf));
sl@0
   582
		while (SSL_read(scon,buf,sizeof(buf)) > 0)
sl@0
   583
			;
sl@0
   584
		}
sl@0
   585
#ifdef NO_SHUTDOWN
sl@0
   586
	SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
sl@0
   587
#else
sl@0
   588
	SSL_shutdown(scon);
sl@0
   589
#endif
sl@0
   590
	SHUTDOWN2(SSL_get_fd(scon));
sl@0
   591
sl@0
   592
	nConn = 0;
sl@0
   593
	totalTime = 0.0;
sl@0
   594
sl@0
   595
	finishtime=(long)time(NULL)+maxTime;
sl@0
   596
sl@0
   597
	printf( "starting\n" );
sl@0
   598
	bytes_read=0;
sl@0
   599
	tm_Time_F(START);
sl@0
   600
		
sl@0
   601
	for (;;)
sl@0
   602
		{
sl@0
   603
		if (finishtime < (long)time(NULL)) break;
sl@0
   604
sl@0
   605
#ifdef WIN32_STUFF
sl@0
   606
		if( flushWinMsgs(0) == -1 )
sl@0
   607
			goto end;
sl@0
   608
sl@0
   609
		if( waitingToDie || exitNow )	/* we're dead */
sl@0
   610
			goto end;
sl@0
   611
#endif
sl@0
   612
sl@0
   613
	 	if( (doConnection( scon )) == NULL )
sl@0
   614
			goto end;
sl@0
   615
sl@0
   616
		if (s_www_path)
sl@0
   617
			{
sl@0
   618
			BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
sl@0
   619
			SSL_write(scon,buf,strlen(buf));
sl@0
   620
			while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
sl@0
   621
				bytes_read+=i;
sl@0
   622
			}
sl@0
   623
sl@0
   624
#ifdef NO_SHUTDOWN
sl@0
   625
		SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
sl@0
   626
#else
sl@0
   627
		SSL_shutdown(scon);
sl@0
   628
#endif
sl@0
   629
		SHUTDOWN2(SSL_get_fd(scon));
sl@0
   630
	
sl@0
   631
		nConn += 1;
sl@0
   632
		if (SSL_session_reused(scon))
sl@0
   633
			ver='r';
sl@0
   634
		else
sl@0
   635
			{
sl@0
   636
			ver=SSL_version(scon);
sl@0
   637
			if (ver == TLS1_VERSION)
sl@0
   638
				ver='t';
sl@0
   639
			else if (ver == SSL3_VERSION)
sl@0
   640
				ver='3';
sl@0
   641
			else if (ver == SSL2_VERSION)
sl@0
   642
				ver='2';
sl@0
   643
			else
sl@0
   644
				ver='*';
sl@0
   645
			}
sl@0
   646
		fputc(ver,stdout);
sl@0
   647
		fflush(stdout);
sl@0
   648
		}
sl@0
   649
	totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
sl@0
   650
sl@0
   651
	printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
sl@0
   652
	printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
sl@0
   653
sl@0
   654
	ret=0;
sl@0
   655
end:
sl@0
   656
	if (scon != NULL) SSL_free(scon);
sl@0
   657
sl@0
   658
	if (tm_ctx != NULL)
sl@0
   659
		{
sl@0
   660
		SSL_CTX_free(tm_ctx);
sl@0
   661
		tm_ctx=NULL;
sl@0
   662
		}
sl@0
   663
	apps_shutdown();
sl@0
   664
	OPENSSL_EXIT(ret);
sl@0
   665
	}
sl@0
   666
sl@0
   667
/***********************************************************************
sl@0
   668
 * doConnection - make a connection
sl@0
   669
 * Args:
sl@0
   670
 *		scon	= earlier ssl connection for session id, or NULL
sl@0
   671
 * Returns:
sl@0
   672
 *		SSL *	= the connection pointer.
sl@0
   673
 */
sl@0
   674
static SSL *doConnection(SSL *scon)
sl@0
   675
	{
sl@0
   676
	BIO *conn;
sl@0
   677
	SSL *serverCon;
sl@0
   678
	int width, i;
sl@0
   679
	fd_set readfds;
sl@0
   680
sl@0
   681
	if ((conn=BIO_new(BIO_s_connect())) == NULL)
sl@0
   682
		return(NULL);
sl@0
   683
sl@0
   684
/*	BIO_set_conn_port(conn,port);*/
sl@0
   685
	BIO_set_conn_hostname(conn,host);
sl@0
   686
sl@0
   687
	if (scon == NULL)
sl@0
   688
		serverCon=SSL_new(tm_ctx);
sl@0
   689
	else
sl@0
   690
		{
sl@0
   691
		serverCon=scon;
sl@0
   692
		SSL_set_connect_state(serverCon);
sl@0
   693
		}
sl@0
   694
sl@0
   695
	SSL_set_bio(serverCon,conn,conn);
sl@0
   696
sl@0
   697
#if 0
sl@0
   698
	if( scon != NULL )
sl@0
   699
		SSL_set_session(serverCon,SSL_get_session(scon));
sl@0
   700
#endif
sl@0
   701
sl@0
   702
	/* ok, lets connect */
sl@0
   703
	for(;;) {
sl@0
   704
		i=SSL_connect(serverCon);
sl@0
   705
		if (BIO_sock_should_retry(i))
sl@0
   706
			{
sl@0
   707
			BIO_printf(bio_err,"DELAY\n");
sl@0
   708
sl@0
   709
			i=SSL_get_fd(serverCon);
sl@0
   710
			width=i+1;
sl@0
   711
			FD_ZERO(&readfds);
sl@0
   712
			FD_SET(i,&readfds);
sl@0
   713
			/* Note: under VMS with SOCKETSHR the 2nd parameter
sl@0
   714
			 * is currently of type (int *) whereas under other
sl@0
   715
			 * systems it is (void *) if you don't have a cast it
sl@0
   716
			 * will choke the compiler: if you do have a cast then
sl@0
   717
			 * you can either go for (int *) or (void *).
sl@0
   718
			 */
sl@0
   719
			select(width,(void *)&readfds,NULL,NULL,NULL);
sl@0
   720
			continue;
sl@0
   721
			}
sl@0
   722
		break;
sl@0
   723
		}
sl@0
   724
	if(i <= 0)
sl@0
   725
		{
sl@0
   726
		BIO_printf(bio_err,"ERROR\n");
sl@0
   727
		if (verify_error != X509_V_OK)
sl@0
   728
			BIO_printf(bio_err,"verify error:%s\n",
sl@0
   729
				X509_verify_cert_error_string(verify_error));
sl@0
   730
		else
sl@0
   731
			ERR_print_errors(bio_err);
sl@0
   732
		if (scon == NULL)
sl@0
   733
			SSL_free(serverCon);
sl@0
   734
		return NULL;
sl@0
   735
		}
sl@0
   736
sl@0
   737
	return serverCon;
sl@0
   738
	}
sl@0
   739
sl@0
   740