sl@0: /* apps/s_time.c */ sl@0: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: sl@0: #define NO_SHUTDOWN sl@0: sl@0: /*----------------------------------------- sl@0: s_time - SSL client connection timer program sl@0: Written and donated by Larry Streepy sl@0: -----------------------------------------*/ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #define USE_SOCKETS sl@0: #include "apps.h" sl@0: #ifdef OPENSSL_NO_STDIO sl@0: #define APPS_WIN16 sl@0: #endif sl@0: #include sl@0: #include sl@0: #include sl@0: #include "s_apps.h" sl@0: #include sl@0: #ifdef WIN32_STUFF sl@0: #include "winmain.h" sl@0: #include "wintext.h" sl@0: #endif sl@0: #if !defined(OPENSSL_SYS_MSDOS) sl@0: #include OPENSSL_UNISTD sl@0: #endif sl@0: sl@0: #if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) sl@0: #define TIMES sl@0: #endif sl@0: sl@0: #ifndef _IRIX sl@0: #include sl@0: #endif sl@0: #ifdef TIMES sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: /* Depending on the VMS version, the tms structure is perhaps defined. sl@0: The __TMS macro will show if it was. If it wasn't defined, we should sl@0: undefine TIMES, since that tells the rest of the program how things sl@0: should be handled. -- Richard Levitte */ sl@0: #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) sl@0: #undef TIMES sl@0: #endif sl@0: sl@0: #if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE) sl@0: #include sl@0: #endif sl@0: sl@0: #if defined(sun) || defined(__ultrix) sl@0: #define _POSIX_SOURCE sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: /* The following if from times(3) man page. It may need to be changed sl@0: */ sl@0: #ifndef HZ sl@0: # ifdef _SC_CLK_TCK sl@0: # define HZ ((double)sysconf(_SC_CLK_TCK)) sl@0: # else sl@0: # ifndef CLK_TCK sl@0: # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ sl@0: # define HZ 100.0 sl@0: # else /* _BSD_CLK_TCK_ */ sl@0: # define HZ ((double)_BSD_CLK_TCK_) sl@0: # endif sl@0: # else /* CLK_TCK */ sl@0: # define HZ ((double)CLK_TCK) sl@0: # endif sl@0: # endif sl@0: #endif sl@0: sl@0: #undef PROG sl@0: #define PROG s_time_main sl@0: sl@0: #undef ioctl sl@0: #define ioctl ioctlsocket sl@0: sl@0: #define SSL_CONNECT_NAME "localhost:4433" sl@0: sl@0: /*#define TEST_CERT "client.pem" */ /* no default cert. */ sl@0: sl@0: #undef BUFSIZZ sl@0: #define BUFSIZZ 1024*10 sl@0: sl@0: #define MYBUFSIZ 1024*8 sl@0: sl@0: #undef min sl@0: #undef max sl@0: #define min(a,b) (((a) < (b)) ? (a) : (b)) sl@0: #define max(a,b) (((a) > (b)) ? (a) : (b)) sl@0: sl@0: #undef SECONDS sl@0: #define SECONDS 30 sl@0: extern int verify_depth; sl@0: extern int verify_error; sl@0: sl@0: static void s_time_usage(void); sl@0: static int parseArgs( int argc, char **argv ); sl@0: static SSL *doConnection( SSL *scon ); sl@0: static void s_time_init(void); sl@0: sl@0: /*********************************************************************** sl@0: * Static data declarations sl@0: */ sl@0: sl@0: /* static char *port=PORT_STR;*/ sl@0: static char *host=SSL_CONNECT_NAME; sl@0: static char *t_cert_file=NULL; sl@0: static char *t_key_file=NULL; sl@0: static char *CApath=NULL; sl@0: static char *CAfile=NULL; sl@0: static char *tm_cipher=NULL; sl@0: static int tm_verify = SSL_VERIFY_NONE; sl@0: static int maxTime = SECONDS; sl@0: static SSL_CTX *tm_ctx=NULL; sl@0: static SSL_METHOD *s_time_meth=NULL; sl@0: static char *s_www_path=NULL; sl@0: static long bytes_read=0; sl@0: static int st_bugs=0; sl@0: static int perform=0; sl@0: #ifdef FIONBIO sl@0: static int t_nbio=0; sl@0: #endif sl@0: #ifdef OPENSSL_SYS_WIN32 sl@0: static int exitNow = 0; /* Set when it's time to exit main */ sl@0: #endif sl@0: sl@0: static void s_time_init(void) sl@0: { sl@0: host=SSL_CONNECT_NAME; sl@0: t_cert_file=NULL; sl@0: t_key_file=NULL; sl@0: CApath=NULL; sl@0: CAfile=NULL; sl@0: tm_cipher=NULL; sl@0: tm_verify = SSL_VERIFY_NONE; sl@0: maxTime = SECONDS; sl@0: tm_ctx=NULL; sl@0: s_time_meth=NULL; sl@0: s_www_path=NULL; sl@0: bytes_read=0; sl@0: st_bugs=0; sl@0: perform=0; sl@0: sl@0: #ifdef FIONBIO sl@0: t_nbio=0; sl@0: #endif sl@0: #ifdef OPENSSL_SYS_WIN32 sl@0: exitNow = 0; /* Set when it's time to exit main */ sl@0: #endif sl@0: } sl@0: sl@0: sl@0: /*********************************************************************** sl@0: * usage - display usage message sl@0: */ sl@0: static void s_time_usage(void) sl@0: { sl@0: static char umsg[] = "\ sl@0: -time arg - max number of seconds to collect data, default %d\n\ sl@0: -verify arg - turn on peer certificate verification, arg == depth\n\ sl@0: -cert arg - certificate file to use, PEM format assumed\n\ sl@0: -key arg - RSA file to use, PEM format assumed, key is in cert file\n\ sl@0: file if not specified by this option\n\ sl@0: -CApath arg - PEM format directory of CA's\n\ sl@0: -CAfile arg - PEM format file of CA's\n\ sl@0: -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n"; sl@0: sl@0: printf( "usage: s_time \n\n" ); sl@0: sl@0: printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME); sl@0: #ifdef FIONBIO sl@0: printf("-nbio - Run with non-blocking IO\n"); sl@0: printf("-ssl2 - Just use SSLv2\n"); sl@0: printf("-ssl3 - Just use SSLv3\n"); sl@0: printf("-bugs - Turn on SSL bug compatibility\n"); sl@0: printf("-new - Just time new connections\n"); sl@0: printf("-reuse - Just time connection reuse\n"); sl@0: printf("-www page - Retrieve 'page' from the site\n"); sl@0: #endif sl@0: printf( umsg,SECONDS ); sl@0: sl@0: } sl@0: sl@0: /*********************************************************************** sl@0: * parseArgs - Parse command line arguments and initialize data sl@0: * sl@0: * Returns 0 if ok, -1 on bad args sl@0: */ sl@0: static int parseArgs(int argc, char **argv) sl@0: { sl@0: int badop = 0; sl@0: sl@0: verify_depth=0; sl@0: verify_error=X509_V_OK; sl@0: sl@0: argc--; sl@0: argv++; sl@0: sl@0: while (argc >= 1) { sl@0: if (strcmp(*argv,"-connect") == 0) sl@0: { sl@0: if (--argc < 1) goto bad; sl@0: host= *(++argv); sl@0: } sl@0: #if 0 sl@0: else if( strcmp(*argv,"-host") == 0) sl@0: { sl@0: if (--argc < 1) goto bad; sl@0: host= *(++argv); sl@0: } sl@0: else if( strcmp(*argv,"-port") == 0) sl@0: { sl@0: if (--argc < 1) goto bad; sl@0: port= *(++argv); sl@0: } sl@0: #endif sl@0: else if (strcmp(*argv,"-reuse") == 0) sl@0: perform=2; sl@0: else if (strcmp(*argv,"-new") == 0) sl@0: perform=1; sl@0: else if( strcmp(*argv,"-verify") == 0) { sl@0: sl@0: tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE; sl@0: if (--argc < 1) goto bad; sl@0: verify_depth=atoi(*(++argv)); sl@0: BIO_printf(bio_err,"verify depth is %d\n",verify_depth); sl@0: sl@0: } else if( strcmp(*argv,"-cert") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: t_cert_file= *(++argv); sl@0: sl@0: } else if( strcmp(*argv,"-key") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: t_key_file= *(++argv); sl@0: sl@0: } else if( strcmp(*argv,"-CApath") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: CApath= *(++argv); sl@0: sl@0: } else if( strcmp(*argv,"-CAfile") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: CAfile= *(++argv); sl@0: sl@0: } else if( strcmp(*argv,"-cipher") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: tm_cipher= *(++argv); sl@0: } sl@0: #ifdef FIONBIO sl@0: else if(strcmp(*argv,"-nbio") == 0) { sl@0: t_nbio=1; sl@0: } sl@0: #endif sl@0: else if(strcmp(*argv,"-www") == 0) sl@0: { sl@0: if (--argc < 1) goto bad; sl@0: s_www_path= *(++argv); sl@0: if(strlen(s_www_path) > MYBUFSIZ-100) sl@0: { sl@0: BIO_printf(bio_err,"-www option too long\n"); sl@0: badop=1; sl@0: } sl@0: } sl@0: else if(strcmp(*argv,"-bugs") == 0) sl@0: st_bugs=1; sl@0: #ifndef OPENSSL_NO_SSL2 sl@0: else if(strcmp(*argv,"-ssl2") == 0) sl@0: s_time_meth=SSLv2_client_method(); sl@0: #endif sl@0: #ifndef OPENSSL_NO_SSL3 sl@0: else if(strcmp(*argv,"-ssl3") == 0) sl@0: s_time_meth=SSLv3_client_method(); sl@0: #endif sl@0: else if( strcmp(*argv,"-time") == 0) { sl@0: sl@0: if (--argc < 1) goto bad; sl@0: maxTime= atoi(*(++argv)); sl@0: } sl@0: else { sl@0: BIO_printf(bio_err,"unknown option %s\n",*argv); sl@0: badop=1; sl@0: break; sl@0: } sl@0: sl@0: argc--; sl@0: argv++; sl@0: } sl@0: sl@0: if (perform == 0) perform=3; sl@0: sl@0: if(badop) { sl@0: bad: sl@0: s_time_usage(); sl@0: return -1; sl@0: } sl@0: sl@0: return 0; /* Valid args */ sl@0: } sl@0: sl@0: /*********************************************************************** sl@0: * TIME - time functions sl@0: */ sl@0: #define START 0 sl@0: #define STOP 1 sl@0: sl@0: static double tm_Time_F(int s) sl@0: { sl@0: static double ret; sl@0: #ifdef TIMES sl@0: static struct tms tstart,tend; sl@0: sl@0: if(s == START) { sl@0: //times(&tstart); shilps sl@0: return(0); sl@0: } else { sl@0: //times(&tend); shilpa sl@0: ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; sl@0: return((ret == 0.0)?1e-6:ret); sl@0: } sl@0: #elif defined(OPENSSL_SYS_NETWARE) sl@0: static clock_t tstart,tend; sl@0: sl@0: if (s == START) sl@0: { sl@0: tstart=clock(); sl@0: return(0); sl@0: } sl@0: else sl@0: { sl@0: tend=clock(); sl@0: ret=(double)((double)(tend)-(double)(tstart)); sl@0: return((ret < 0.001)?0.001:ret); sl@0: } sl@0: #elif defined(OPENSSL_SYS_VXWORKS) sl@0: { sl@0: static unsigned long tick_start, tick_end; sl@0: sl@0: if( s == START ) sl@0: { sl@0: tick_start = tickGet(); sl@0: return 0; sl@0: } sl@0: else sl@0: { sl@0: tick_end = tickGet(); sl@0: ret = (double)(tick_end - tick_start) / (double)sysClkRateGet(); sl@0: return((ret == 0.0)?1e-6:ret); sl@0: } sl@0: } sl@0: #else /* !times() */ sl@0: static struct timeb tstart,tend; sl@0: long i; sl@0: sl@0: if(s == START) { sl@0: ftime(&tstart); sl@0: return(0); sl@0: } else { sl@0: ftime(&tend); sl@0: i=(long)tend.millitm-(long)tstart.millitm; sl@0: ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; sl@0: return((ret == 0.0)?1e-6:ret); sl@0: } sl@0: #endif sl@0: } sl@0: sl@0: /*********************************************************************** sl@0: * MAIN - main processing area for client sl@0: * real name depends on MONOLITH sl@0: */ sl@0: int MAIN(int, char **); sl@0: sl@0: int MAIN(int argc, char **argv) sl@0: { sl@0: double totalTime = 0.0; sl@0: int nConn = 0; sl@0: SSL *scon=NULL; sl@0: long finishtime=0; sl@0: int ret=1,i; sl@0: MS_STATIC char buf[1024*8]; sl@0: int ver; sl@0: sl@0: apps_startup(); sl@0: s_time_init(); sl@0: sl@0: if (bio_err == NULL) sl@0: bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); sl@0: sl@0: #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3) sl@0: s_time_meth=SSLv23_client_method(); sl@0: #elif !defined(OPENSSL_NO_SSL3) sl@0: s_time_meth=SSLv3_client_method(); sl@0: #elif !defined(OPENSSL_NO_SSL2) sl@0: s_time_meth=SSLv2_client_method(); sl@0: #endif sl@0: sl@0: /* parse the command line arguments */ sl@0: if( parseArgs( argc, argv ) < 0 ) sl@0: goto end; sl@0: sl@0: OpenSSL_add_ssl_algorithms(); sl@0: if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1); sl@0: sl@0: SSL_CTX_set_quiet_shutdown(tm_ctx,1); sl@0: sl@0: if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL); sl@0: SSL_CTX_set_cipher_list(tm_ctx,tm_cipher); sl@0: if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file)) sl@0: goto end; sl@0: sl@0: SSL_load_error_strings(); sl@0: sl@0: if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) || sl@0: (!SSL_CTX_set_default_verify_paths(tm_ctx))) sl@0: { sl@0: /* BIO_printf(bio_err,"error setting default verify locations\n"); */ sl@0: ERR_print_errors(bio_err); sl@0: /* goto end; */ sl@0: } sl@0: sl@0: if (tm_cipher == NULL) sl@0: tm_cipher = getenv("SSL_CIPHER"); sl@0: sl@0: if (tm_cipher == NULL ) { sl@0: fprintf( stderr, "No CIPHER specified\n" ); sl@0: sl@0: sl@0: } sl@0: sl@0: if (!(perform & 1)) goto next; sl@0: printf( "Collecting connection statistics for %d seconds\n", maxTime ); sl@0: sl@0: /* Loop and time how long it takes to make connections */ sl@0: sl@0: bytes_read=0; sl@0: finishtime=(long)time(NULL)+maxTime; sl@0: tm_Time_F(START); sl@0: for (;;) sl@0: { sl@0: if (finishtime < (long)time(NULL)) break; sl@0: #ifdef WIN32_STUFF sl@0: sl@0: if( flushWinMsgs(0) == -1 ) sl@0: goto end; sl@0: sl@0: if( waitingToDie || exitNow ) /* we're dead */ sl@0: goto end; sl@0: #endif sl@0: sl@0: if( (scon = doConnection( NULL )) == NULL ) sl@0: goto end; sl@0: sl@0: if (s_www_path != NULL) sl@0: { sl@0: BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); sl@0: SSL_write(scon,buf,strlen(buf)); sl@0: while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) sl@0: bytes_read+=i; sl@0: } sl@0: sl@0: #ifdef NO_SHUTDOWN sl@0: SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); sl@0: #else sl@0: SSL_shutdown(scon); sl@0: #endif sl@0: SHUTDOWN2(SSL_get_fd(scon)); sl@0: sl@0: nConn += 1; sl@0: if (SSL_session_reused(scon)) sl@0: ver='r'; sl@0: else sl@0: { sl@0: ver=SSL_version(scon); sl@0: if (ver == TLS1_VERSION) sl@0: ver='t'; sl@0: else if (ver == SSL3_VERSION) sl@0: ver='3'; sl@0: else if (ver == SSL2_VERSION) sl@0: ver='2'; sl@0: else sl@0: ver='*'; sl@0: } sl@0: fputc(ver,stdout); sl@0: fflush(stdout); sl@0: SSL_free( scon ); sl@0: scon=NULL; sl@0: } sl@0: totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ sl@0: sl@0: i=(int)((long)time(NULL)-finishtime+maxTime); sl@0: printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); sl@0: printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); sl@0: sl@0: sl@0: /* Now loop and time connections using the same session id over and over */ sl@0: sl@0: next: sl@0: if (!(perform & 2)) goto end; sl@0: sl@0: printf( "\n\nNow timing with session id reuse.\n" ); sl@0: sl@0: sl@0: /* Get an SSL object so we can reuse the session id */ sl@0: if( (scon = doConnection( NULL )) == NULL ) sl@0: { sl@0: fprintf( stderr, "Unable to get connection\n" ); sl@0: goto end; sl@0: } sl@0: sl@0: if (s_www_path != NULL) sl@0: { sl@0: BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); sl@0: SSL_write(scon,buf,strlen(buf)); sl@0: while (SSL_read(scon,buf,sizeof(buf)) > 0) sl@0: ; sl@0: } sl@0: #ifdef NO_SHUTDOWN sl@0: SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); sl@0: #else sl@0: SSL_shutdown(scon); sl@0: #endif sl@0: SHUTDOWN2(SSL_get_fd(scon)); sl@0: sl@0: nConn = 0; sl@0: totalTime = 0.0; sl@0: sl@0: finishtime=(long)time(NULL)+maxTime; sl@0: sl@0: printf( "starting\n" ); sl@0: bytes_read=0; sl@0: tm_Time_F(START); sl@0: sl@0: for (;;) sl@0: { sl@0: if (finishtime < (long)time(NULL)) break; sl@0: sl@0: #ifdef WIN32_STUFF sl@0: if( flushWinMsgs(0) == -1 ) sl@0: goto end; sl@0: sl@0: if( waitingToDie || exitNow ) /* we're dead */ sl@0: goto end; sl@0: #endif sl@0: sl@0: if( (doConnection( scon )) == NULL ) sl@0: goto end; sl@0: sl@0: if (s_www_path) sl@0: { sl@0: BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); sl@0: SSL_write(scon,buf,strlen(buf)); sl@0: while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) sl@0: bytes_read+=i; sl@0: } sl@0: sl@0: #ifdef NO_SHUTDOWN sl@0: SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); sl@0: #else sl@0: SSL_shutdown(scon); sl@0: #endif sl@0: SHUTDOWN2(SSL_get_fd(scon)); sl@0: sl@0: nConn += 1; sl@0: if (SSL_session_reused(scon)) sl@0: ver='r'; sl@0: else sl@0: { sl@0: ver=SSL_version(scon); sl@0: if (ver == TLS1_VERSION) sl@0: ver='t'; sl@0: else if (ver == SSL3_VERSION) sl@0: ver='3'; sl@0: else if (ver == SSL2_VERSION) sl@0: ver='2'; sl@0: else sl@0: ver='*'; sl@0: } sl@0: fputc(ver,stdout); sl@0: fflush(stdout); sl@0: } sl@0: totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/ sl@0: sl@0: printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); sl@0: printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); sl@0: sl@0: ret=0; sl@0: end: sl@0: if (scon != NULL) SSL_free(scon); sl@0: sl@0: if (tm_ctx != NULL) sl@0: { sl@0: SSL_CTX_free(tm_ctx); sl@0: tm_ctx=NULL; sl@0: } sl@0: apps_shutdown(); sl@0: OPENSSL_EXIT(ret); sl@0: } sl@0: sl@0: /*********************************************************************** sl@0: * doConnection - make a connection sl@0: * Args: sl@0: * scon = earlier ssl connection for session id, or NULL sl@0: * Returns: sl@0: * SSL * = the connection pointer. sl@0: */ sl@0: static SSL *doConnection(SSL *scon) sl@0: { sl@0: BIO *conn; sl@0: SSL *serverCon; sl@0: int width, i; sl@0: fd_set readfds; sl@0: sl@0: if ((conn=BIO_new(BIO_s_connect())) == NULL) sl@0: return(NULL); sl@0: sl@0: /* BIO_set_conn_port(conn,port);*/ sl@0: BIO_set_conn_hostname(conn,host); sl@0: sl@0: if (scon == NULL) sl@0: serverCon=SSL_new(tm_ctx); sl@0: else sl@0: { sl@0: serverCon=scon; sl@0: SSL_set_connect_state(serverCon); sl@0: } sl@0: sl@0: SSL_set_bio(serverCon,conn,conn); sl@0: sl@0: #if 0 sl@0: if( scon != NULL ) sl@0: SSL_set_session(serverCon,SSL_get_session(scon)); sl@0: #endif sl@0: sl@0: /* ok, lets connect */ sl@0: for(;;) { sl@0: i=SSL_connect(serverCon); sl@0: if (BIO_sock_should_retry(i)) sl@0: { sl@0: BIO_printf(bio_err,"DELAY\n"); sl@0: sl@0: i=SSL_get_fd(serverCon); sl@0: width=i+1; sl@0: FD_ZERO(&readfds); sl@0: FD_SET(i,&readfds); sl@0: /* Note: under VMS with SOCKETSHR the 2nd parameter sl@0: * is currently of type (int *) whereas under other sl@0: * systems it is (void *) if you don't have a cast it sl@0: * will choke the compiler: if you do have a cast then sl@0: * you can either go for (int *) or (void *). sl@0: */ sl@0: select(width,(void *)&readfds,NULL,NULL,NULL); sl@0: continue; sl@0: } sl@0: break; sl@0: } sl@0: if(i <= 0) sl@0: { sl@0: BIO_printf(bio_err,"ERROR\n"); sl@0: if (verify_error != X509_V_OK) sl@0: BIO_printf(bio_err,"verify error:%s\n", sl@0: X509_verify_cert_error_string(verify_error)); sl@0: else sl@0: ERR_print_errors(bio_err); sl@0: if (scon == NULL) sl@0: SSL_free(serverCon); sl@0: return NULL; sl@0: } sl@0: sl@0: return serverCon; sl@0: } sl@0: sl@0: