1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/tsrc/topenssl/src/s_time.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,740 @@
1.4 +/* apps/s_time.c */
1.5 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +
1.62 +#define NO_SHUTDOWN
1.63 +
1.64 +/*-----------------------------------------
1.65 + s_time - SSL client connection timer program
1.66 + Written and donated by Larry Streepy <streepy@healthcare.com>
1.67 + -----------------------------------------*/
1.68 +#include <sys/select.h>
1.69 +#include <stdio.h>
1.70 +#include <stdlib.h>
1.71 +#include <string.h>
1.72 +
1.73 +#define USE_SOCKETS
1.74 +#include "apps.h"
1.75 +#ifdef OPENSSL_NO_STDIO
1.76 +#define APPS_WIN16
1.77 +#endif
1.78 +#include <openssl/x509.h>
1.79 +#include <openssl/ssl.h>
1.80 +#include <openssl/pem.h>
1.81 +#include "s_apps.h"
1.82 +#include <openssl/err.h>
1.83 +#ifdef WIN32_STUFF
1.84 +#include "winmain.h"
1.85 +#include "wintext.h"
1.86 +#endif
1.87 +#if !defined(OPENSSL_SYS_MSDOS)
1.88 +#include OPENSSL_UNISTD
1.89 +#endif
1.90 +
1.91 +#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
1.92 +#define TIMES
1.93 +#endif
1.94 +
1.95 +#ifndef _IRIX
1.96 +#include <time.h>
1.97 +#endif
1.98 +#ifdef TIMES
1.99 +#include <sys/types.h>
1.100 +#include <sys/times.h>
1.101 +#endif
1.102 +
1.103 +/* Depending on the VMS version, the tms structure is perhaps defined.
1.104 + The __TMS macro will show if it was. If it wasn't defined, we should
1.105 + undefine TIMES, since that tells the rest of the program how things
1.106 + should be handled. -- Richard Levitte */
1.107 +#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
1.108 +#undef TIMES
1.109 +#endif
1.110 +
1.111 +#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
1.112 +#include <sys/timeb.h>
1.113 +#endif
1.114 +
1.115 +#if defined(sun) || defined(__ultrix)
1.116 +#define _POSIX_SOURCE
1.117 +#include <limits.h>
1.118 +#include <sys/param.h>
1.119 +#endif
1.120 +
1.121 +/* The following if from times(3) man page. It may need to be changed
1.122 +*/
1.123 +#ifndef HZ
1.124 +# ifdef _SC_CLK_TCK
1.125 +# define HZ ((double)sysconf(_SC_CLK_TCK))
1.126 +# else
1.127 +# ifndef CLK_TCK
1.128 +# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
1.129 +# define HZ 100.0
1.130 +# else /* _BSD_CLK_TCK_ */
1.131 +# define HZ ((double)_BSD_CLK_TCK_)
1.132 +# endif
1.133 +# else /* CLK_TCK */
1.134 +# define HZ ((double)CLK_TCK)
1.135 +# endif
1.136 +# endif
1.137 +#endif
1.138 +
1.139 +#undef PROG
1.140 +#define PROG s_time_main
1.141 +
1.142 +#undef ioctl
1.143 +#define ioctl ioctlsocket
1.144 +
1.145 +#define SSL_CONNECT_NAME "localhost:4433"
1.146 +
1.147 +/*#define TEST_CERT "client.pem" */ /* no default cert. */
1.148 +
1.149 +#undef BUFSIZZ
1.150 +#define BUFSIZZ 1024*10
1.151 +
1.152 +#define MYBUFSIZ 1024*8
1.153 +
1.154 +#undef min
1.155 +#undef max
1.156 +#define min(a,b) (((a) < (b)) ? (a) : (b))
1.157 +#define max(a,b) (((a) > (b)) ? (a) : (b))
1.158 +
1.159 +#undef SECONDS
1.160 +#define SECONDS 30
1.161 +extern int verify_depth;
1.162 +extern int verify_error;
1.163 +
1.164 +static void s_time_usage(void);
1.165 +static int parseArgs( int argc, char **argv );
1.166 +static SSL *doConnection( SSL *scon );
1.167 +static void s_time_init(void);
1.168 +
1.169 +/***********************************************************************
1.170 + * Static data declarations
1.171 + */
1.172 +
1.173 +/* static char *port=PORT_STR;*/
1.174 +static char *host=SSL_CONNECT_NAME;
1.175 +static char *t_cert_file=NULL;
1.176 +static char *t_key_file=NULL;
1.177 +static char *CApath=NULL;
1.178 +static char *CAfile=NULL;
1.179 +static char *tm_cipher=NULL;
1.180 +static int tm_verify = SSL_VERIFY_NONE;
1.181 +static int maxTime = SECONDS;
1.182 +static SSL_CTX *tm_ctx=NULL;
1.183 +static SSL_METHOD *s_time_meth=NULL;
1.184 +static char *s_www_path=NULL;
1.185 +static long bytes_read=0;
1.186 +static int st_bugs=0;
1.187 +static int perform=0;
1.188 +#ifdef FIONBIO
1.189 +static int t_nbio=0;
1.190 +#endif
1.191 +#ifdef OPENSSL_SYS_WIN32
1.192 +static int exitNow = 0; /* Set when it's time to exit main */
1.193 +#endif
1.194 +
1.195 +static void s_time_init(void)
1.196 + {
1.197 + host=SSL_CONNECT_NAME;
1.198 + t_cert_file=NULL;
1.199 + t_key_file=NULL;
1.200 + CApath=NULL;
1.201 + CAfile=NULL;
1.202 + tm_cipher=NULL;
1.203 + tm_verify = SSL_VERIFY_NONE;
1.204 + maxTime = SECONDS;
1.205 + tm_ctx=NULL;
1.206 + s_time_meth=NULL;
1.207 + s_www_path=NULL;
1.208 + bytes_read=0;
1.209 + st_bugs=0;
1.210 + perform=0;
1.211 +
1.212 +#ifdef FIONBIO
1.213 + t_nbio=0;
1.214 +#endif
1.215 +#ifdef OPENSSL_SYS_WIN32
1.216 + exitNow = 0; /* Set when it's time to exit main */
1.217 +#endif
1.218 + }
1.219 +
1.220 +
1.221 +/***********************************************************************
1.222 + * usage - display usage message
1.223 + */
1.224 +static void s_time_usage(void)
1.225 +{
1.226 + static char umsg[] = "\
1.227 +-time arg - max number of seconds to collect data, default %d\n\
1.228 +-verify arg - turn on peer certificate verification, arg == depth\n\
1.229 +-cert arg - certificate file to use, PEM format assumed\n\
1.230 +-key arg - RSA file to use, PEM format assumed, key is in cert file\n\
1.231 + file if not specified by this option\n\
1.232 +-CApath arg - PEM format directory of CA's\n\
1.233 +-CAfile arg - PEM format file of CA's\n\
1.234 +-cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
1.235 +
1.236 + printf( "usage: s_time <args>\n\n" );
1.237 +
1.238 + printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
1.239 +#ifdef FIONBIO
1.240 + printf("-nbio - Run with non-blocking IO\n");
1.241 + printf("-ssl2 - Just use SSLv2\n");
1.242 + printf("-ssl3 - Just use SSLv3\n");
1.243 + printf("-bugs - Turn on SSL bug compatibility\n");
1.244 + printf("-new - Just time new connections\n");
1.245 + printf("-reuse - Just time connection reuse\n");
1.246 + printf("-www page - Retrieve 'page' from the site\n");
1.247 +#endif
1.248 + printf( umsg,SECONDS );
1.249 +
1.250 +}
1.251 +
1.252 +/***********************************************************************
1.253 + * parseArgs - Parse command line arguments and initialize data
1.254 + *
1.255 + * Returns 0 if ok, -1 on bad args
1.256 + */
1.257 +static int parseArgs(int argc, char **argv)
1.258 +{
1.259 + int badop = 0;
1.260 +
1.261 + verify_depth=0;
1.262 + verify_error=X509_V_OK;
1.263 +
1.264 + argc--;
1.265 + argv++;
1.266 +
1.267 + while (argc >= 1) {
1.268 + if (strcmp(*argv,"-connect") == 0)
1.269 + {
1.270 + if (--argc < 1) goto bad;
1.271 + host= *(++argv);
1.272 + }
1.273 +#if 0
1.274 + else if( strcmp(*argv,"-host") == 0)
1.275 + {
1.276 + if (--argc < 1) goto bad;
1.277 + host= *(++argv);
1.278 + }
1.279 + else if( strcmp(*argv,"-port") == 0)
1.280 + {
1.281 + if (--argc < 1) goto bad;
1.282 + port= *(++argv);
1.283 + }
1.284 +#endif
1.285 + else if (strcmp(*argv,"-reuse") == 0)
1.286 + perform=2;
1.287 + else if (strcmp(*argv,"-new") == 0)
1.288 + perform=1;
1.289 + else if( strcmp(*argv,"-verify") == 0) {
1.290 +
1.291 + tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
1.292 + if (--argc < 1) goto bad;
1.293 + verify_depth=atoi(*(++argv));
1.294 + BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
1.295 +
1.296 + } else if( strcmp(*argv,"-cert") == 0) {
1.297 +
1.298 + if (--argc < 1) goto bad;
1.299 + t_cert_file= *(++argv);
1.300 +
1.301 + } else if( strcmp(*argv,"-key") == 0) {
1.302 +
1.303 + if (--argc < 1) goto bad;
1.304 + t_key_file= *(++argv);
1.305 +
1.306 + } else if( strcmp(*argv,"-CApath") == 0) {
1.307 +
1.308 + if (--argc < 1) goto bad;
1.309 + CApath= *(++argv);
1.310 +
1.311 + } else if( strcmp(*argv,"-CAfile") == 0) {
1.312 +
1.313 + if (--argc < 1) goto bad;
1.314 + CAfile= *(++argv);
1.315 +
1.316 + } else if( strcmp(*argv,"-cipher") == 0) {
1.317 +
1.318 + if (--argc < 1) goto bad;
1.319 + tm_cipher= *(++argv);
1.320 + }
1.321 +#ifdef FIONBIO
1.322 + else if(strcmp(*argv,"-nbio") == 0) {
1.323 + t_nbio=1;
1.324 + }
1.325 +#endif
1.326 + else if(strcmp(*argv,"-www") == 0)
1.327 + {
1.328 + if (--argc < 1) goto bad;
1.329 + s_www_path= *(++argv);
1.330 + if(strlen(s_www_path) > MYBUFSIZ-100)
1.331 + {
1.332 + BIO_printf(bio_err,"-www option too long\n");
1.333 + badop=1;
1.334 + }
1.335 + }
1.336 + else if(strcmp(*argv,"-bugs") == 0)
1.337 + st_bugs=1;
1.338 +#ifndef OPENSSL_NO_SSL2
1.339 + else if(strcmp(*argv,"-ssl2") == 0)
1.340 + s_time_meth=SSLv2_client_method();
1.341 +#endif
1.342 +#ifndef OPENSSL_NO_SSL3
1.343 + else if(strcmp(*argv,"-ssl3") == 0)
1.344 + s_time_meth=SSLv3_client_method();
1.345 +#endif
1.346 + else if( strcmp(*argv,"-time") == 0) {
1.347 +
1.348 + if (--argc < 1) goto bad;
1.349 + maxTime= atoi(*(++argv));
1.350 + }
1.351 + else {
1.352 + BIO_printf(bio_err,"unknown option %s\n",*argv);
1.353 + badop=1;
1.354 + break;
1.355 + }
1.356 +
1.357 + argc--;
1.358 + argv++;
1.359 + }
1.360 +
1.361 + if (perform == 0) perform=3;
1.362 +
1.363 + if(badop) {
1.364 +bad:
1.365 + s_time_usage();
1.366 + return -1;
1.367 + }
1.368 +
1.369 + return 0; /* Valid args */
1.370 +}
1.371 +
1.372 +/***********************************************************************
1.373 + * TIME - time functions
1.374 + */
1.375 +#define START 0
1.376 +#define STOP 1
1.377 +
1.378 +static double tm_Time_F(int s)
1.379 + {
1.380 + static double ret;
1.381 +#ifdef TIMES
1.382 + static struct tms tstart,tend;
1.383 +
1.384 + if(s == START) {
1.385 + //times(&tstart); shilps
1.386 + return(0);
1.387 + } else {
1.388 + //times(&tend); shilpa
1.389 + ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
1.390 + return((ret == 0.0)?1e-6:ret);
1.391 + }
1.392 +#elif defined(OPENSSL_SYS_NETWARE)
1.393 + static clock_t tstart,tend;
1.394 +
1.395 + if (s == START)
1.396 + {
1.397 + tstart=clock();
1.398 + return(0);
1.399 + }
1.400 + else
1.401 + {
1.402 + tend=clock();
1.403 + ret=(double)((double)(tend)-(double)(tstart));
1.404 + return((ret < 0.001)?0.001:ret);
1.405 + }
1.406 +#elif defined(OPENSSL_SYS_VXWORKS)
1.407 + {
1.408 + static unsigned long tick_start, tick_end;
1.409 +
1.410 + if( s == START )
1.411 + {
1.412 + tick_start = tickGet();
1.413 + return 0;
1.414 + }
1.415 + else
1.416 + {
1.417 + tick_end = tickGet();
1.418 + ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
1.419 + return((ret == 0.0)?1e-6:ret);
1.420 + }
1.421 + }
1.422 +#else /* !times() */
1.423 + static struct timeb tstart,tend;
1.424 + long i;
1.425 +
1.426 + if(s == START) {
1.427 + ftime(&tstart);
1.428 + return(0);
1.429 + } else {
1.430 + ftime(&tend);
1.431 + i=(long)tend.millitm-(long)tstart.millitm;
1.432 + ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
1.433 + return((ret == 0.0)?1e-6:ret);
1.434 + }
1.435 +#endif
1.436 +}
1.437 +
1.438 +/***********************************************************************
1.439 + * MAIN - main processing area for client
1.440 + * real name depends on MONOLITH
1.441 + */
1.442 +int MAIN(int, char **);
1.443 +
1.444 +int MAIN(int argc, char **argv)
1.445 + {
1.446 + double totalTime = 0.0;
1.447 + int nConn = 0;
1.448 + SSL *scon=NULL;
1.449 + long finishtime=0;
1.450 + int ret=1,i;
1.451 + MS_STATIC char buf[1024*8];
1.452 + int ver;
1.453 +
1.454 + apps_startup();
1.455 + s_time_init();
1.456 +
1.457 + if (bio_err == NULL)
1.458 + bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
1.459 +
1.460 +#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
1.461 + s_time_meth=SSLv23_client_method();
1.462 +#elif !defined(OPENSSL_NO_SSL3)
1.463 + s_time_meth=SSLv3_client_method();
1.464 +#elif !defined(OPENSSL_NO_SSL2)
1.465 + s_time_meth=SSLv2_client_method();
1.466 +#endif
1.467 +
1.468 + /* parse the command line arguments */
1.469 + if( parseArgs( argc, argv ) < 0 )
1.470 + goto end;
1.471 +
1.472 + OpenSSL_add_ssl_algorithms();
1.473 + if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
1.474 +
1.475 + SSL_CTX_set_quiet_shutdown(tm_ctx,1);
1.476 +
1.477 + if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
1.478 + SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
1.479 + if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))
1.480 + goto end;
1.481 +
1.482 + SSL_load_error_strings();
1.483 +
1.484 + if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
1.485 + (!SSL_CTX_set_default_verify_paths(tm_ctx)))
1.486 + {
1.487 + /* BIO_printf(bio_err,"error setting default verify locations\n"); */
1.488 + ERR_print_errors(bio_err);
1.489 + /* goto end; */
1.490 + }
1.491 +
1.492 + if (tm_cipher == NULL)
1.493 + tm_cipher = getenv("SSL_CIPHER");
1.494 +
1.495 + if (tm_cipher == NULL ) {
1.496 + fprintf( stderr, "No CIPHER specified\n" );
1.497 +
1.498 +
1.499 + }
1.500 +
1.501 + if (!(perform & 1)) goto next;
1.502 + printf( "Collecting connection statistics for %d seconds\n", maxTime );
1.503 +
1.504 + /* Loop and time how long it takes to make connections */
1.505 +
1.506 + bytes_read=0;
1.507 + finishtime=(long)time(NULL)+maxTime;
1.508 + tm_Time_F(START);
1.509 + for (;;)
1.510 + {
1.511 + if (finishtime < (long)time(NULL)) break;
1.512 +#ifdef WIN32_STUFF
1.513 +
1.514 + if( flushWinMsgs(0) == -1 )
1.515 + goto end;
1.516 +
1.517 + if( waitingToDie || exitNow ) /* we're dead */
1.518 + goto end;
1.519 +#endif
1.520 +
1.521 + if( (scon = doConnection( NULL )) == NULL )
1.522 + goto end;
1.523 +
1.524 + if (s_www_path != NULL)
1.525 + {
1.526 + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
1.527 + SSL_write(scon,buf,strlen(buf));
1.528 + while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
1.529 + bytes_read+=i;
1.530 + }
1.531 +
1.532 +#ifdef NO_SHUTDOWN
1.533 + SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1.534 +#else
1.535 + SSL_shutdown(scon);
1.536 +#endif
1.537 + SHUTDOWN2(SSL_get_fd(scon));
1.538 +
1.539 + nConn += 1;
1.540 + if (SSL_session_reused(scon))
1.541 + ver='r';
1.542 + else
1.543 + {
1.544 + ver=SSL_version(scon);
1.545 + if (ver == TLS1_VERSION)
1.546 + ver='t';
1.547 + else if (ver == SSL3_VERSION)
1.548 + ver='3';
1.549 + else if (ver == SSL2_VERSION)
1.550 + ver='2';
1.551 + else
1.552 + ver='*';
1.553 + }
1.554 + fputc(ver,stdout);
1.555 + fflush(stdout);
1.556 + SSL_free( scon );
1.557 + scon=NULL;
1.558 + }
1.559 + totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
1.560 +
1.561 + i=(int)((long)time(NULL)-finishtime+maxTime);
1.562 + printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
1.563 + printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
1.564 +
1.565 +
1.566 + /* Now loop and time connections using the same session id over and over */
1.567 +
1.568 +next:
1.569 + if (!(perform & 2)) goto end;
1.570 +
1.571 + printf( "\n\nNow timing with session id reuse.\n" );
1.572 +
1.573 +
1.574 + /* Get an SSL object so we can reuse the session id */
1.575 + if( (scon = doConnection( NULL )) == NULL )
1.576 + {
1.577 + fprintf( stderr, "Unable to get connection\n" );
1.578 + goto end;
1.579 + }
1.580 +
1.581 + if (s_www_path != NULL)
1.582 + {
1.583 + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
1.584 + SSL_write(scon,buf,strlen(buf));
1.585 + while (SSL_read(scon,buf,sizeof(buf)) > 0)
1.586 + ;
1.587 + }
1.588 +#ifdef NO_SHUTDOWN
1.589 + SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1.590 +#else
1.591 + SSL_shutdown(scon);
1.592 +#endif
1.593 + SHUTDOWN2(SSL_get_fd(scon));
1.594 +
1.595 + nConn = 0;
1.596 + totalTime = 0.0;
1.597 +
1.598 + finishtime=(long)time(NULL)+maxTime;
1.599 +
1.600 + printf( "starting\n" );
1.601 + bytes_read=0;
1.602 + tm_Time_F(START);
1.603 +
1.604 + for (;;)
1.605 + {
1.606 + if (finishtime < (long)time(NULL)) break;
1.607 +
1.608 +#ifdef WIN32_STUFF
1.609 + if( flushWinMsgs(0) == -1 )
1.610 + goto end;
1.611 +
1.612 + if( waitingToDie || exitNow ) /* we're dead */
1.613 + goto end;
1.614 +#endif
1.615 +
1.616 + if( (doConnection( scon )) == NULL )
1.617 + goto end;
1.618 +
1.619 + if (s_www_path)
1.620 + {
1.621 + BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
1.622 + SSL_write(scon,buf,strlen(buf));
1.623 + while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
1.624 + bytes_read+=i;
1.625 + }
1.626 +
1.627 +#ifdef NO_SHUTDOWN
1.628 + SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1.629 +#else
1.630 + SSL_shutdown(scon);
1.631 +#endif
1.632 + SHUTDOWN2(SSL_get_fd(scon));
1.633 +
1.634 + nConn += 1;
1.635 + if (SSL_session_reused(scon))
1.636 + ver='r';
1.637 + else
1.638 + {
1.639 + ver=SSL_version(scon);
1.640 + if (ver == TLS1_VERSION)
1.641 + ver='t';
1.642 + else if (ver == SSL3_VERSION)
1.643 + ver='3';
1.644 + else if (ver == SSL2_VERSION)
1.645 + ver='2';
1.646 + else
1.647 + ver='*';
1.648 + }
1.649 + fputc(ver,stdout);
1.650 + fflush(stdout);
1.651 + }
1.652 + totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
1.653 +
1.654 + printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
1.655 + printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
1.656 +
1.657 + ret=0;
1.658 +end:
1.659 + if (scon != NULL) SSL_free(scon);
1.660 +
1.661 + if (tm_ctx != NULL)
1.662 + {
1.663 + SSL_CTX_free(tm_ctx);
1.664 + tm_ctx=NULL;
1.665 + }
1.666 + apps_shutdown();
1.667 + OPENSSL_EXIT(ret);
1.668 + }
1.669 +
1.670 +/***********************************************************************
1.671 + * doConnection - make a connection
1.672 + * Args:
1.673 + * scon = earlier ssl connection for session id, or NULL
1.674 + * Returns:
1.675 + * SSL * = the connection pointer.
1.676 + */
1.677 +static SSL *doConnection(SSL *scon)
1.678 + {
1.679 + BIO *conn;
1.680 + SSL *serverCon;
1.681 + int width, i;
1.682 + fd_set readfds;
1.683 +
1.684 + if ((conn=BIO_new(BIO_s_connect())) == NULL)
1.685 + return(NULL);
1.686 +
1.687 +/* BIO_set_conn_port(conn,port);*/
1.688 + BIO_set_conn_hostname(conn,host);
1.689 +
1.690 + if (scon == NULL)
1.691 + serverCon=SSL_new(tm_ctx);
1.692 + else
1.693 + {
1.694 + serverCon=scon;
1.695 + SSL_set_connect_state(serverCon);
1.696 + }
1.697 +
1.698 + SSL_set_bio(serverCon,conn,conn);
1.699 +
1.700 +#if 0
1.701 + if( scon != NULL )
1.702 + SSL_set_session(serverCon,SSL_get_session(scon));
1.703 +#endif
1.704 +
1.705 + /* ok, lets connect */
1.706 + for(;;) {
1.707 + i=SSL_connect(serverCon);
1.708 + if (BIO_sock_should_retry(i))
1.709 + {
1.710 + BIO_printf(bio_err,"DELAY\n");
1.711 +
1.712 + i=SSL_get_fd(serverCon);
1.713 + width=i+1;
1.714 + FD_ZERO(&readfds);
1.715 + FD_SET(i,&readfds);
1.716 + /* Note: under VMS with SOCKETSHR the 2nd parameter
1.717 + * is currently of type (int *) whereas under other
1.718 + * systems it is (void *) if you don't have a cast it
1.719 + * will choke the compiler: if you do have a cast then
1.720 + * you can either go for (int *) or (void *).
1.721 + */
1.722 + select(width,(void *)&readfds,NULL,NULL,NULL);
1.723 + continue;
1.724 + }
1.725 + break;
1.726 + }
1.727 + if(i <= 0)
1.728 + {
1.729 + BIO_printf(bio_err,"ERROR\n");
1.730 + if (verify_error != X509_V_OK)
1.731 + BIO_printf(bio_err,"verify error:%s\n",
1.732 + X509_verify_cert_error_string(verify_error));
1.733 + else
1.734 + ERR_print_errors(bio_err);
1.735 + if (scon == NULL)
1.736 + SSL_free(serverCon);
1.737 + return NULL;
1.738 + }
1.739 +
1.740 + return serverCon;
1.741 + }
1.742 +
1.743 +