10Sstevel@tonic-gate /* apps/s_time.c */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * This package is an SSL implementation written
60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions
110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation
130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate * the code are not to be removed.
180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate * as the author of the parts of the library used.
200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate *
230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate * are met:
260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate * must display the following acknowledgement:
330Sstevel@tonic-gate * "This product includes cryptographic software written by
340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate * being used are not cryptographic related :-).
370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate * SUCH DAMAGE.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be
550Sstevel@tonic-gate * copied and put under another distribution licence
560Sstevel@tonic-gate * [including the GNU Public Licence.]
570Sstevel@tonic-gate */
580Sstevel@tonic-gate
590Sstevel@tonic-gate #define NO_SHUTDOWN
600Sstevel@tonic-gate
610Sstevel@tonic-gate /*-----------------------------------------
620Sstevel@tonic-gate s_time - SSL client connection timer program
630Sstevel@tonic-gate Written and donated by Larry Streepy <streepy@healthcare.com>
640Sstevel@tonic-gate -----------------------------------------*/
650Sstevel@tonic-gate
660Sstevel@tonic-gate #include <stdio.h>
670Sstevel@tonic-gate #include <stdlib.h>
680Sstevel@tonic-gate #include <string.h>
690Sstevel@tonic-gate
700Sstevel@tonic-gate #define USE_SOCKETS
710Sstevel@tonic-gate #include "apps.h"
720Sstevel@tonic-gate #ifdef OPENSSL_NO_STDIO
730Sstevel@tonic-gate #define APPS_WIN16
740Sstevel@tonic-gate #endif
750Sstevel@tonic-gate #include <openssl/x509.h>
760Sstevel@tonic-gate #include <openssl/ssl.h>
770Sstevel@tonic-gate #include <openssl/pem.h>
780Sstevel@tonic-gate #include "s_apps.h"
790Sstevel@tonic-gate #include <openssl/err.h>
800Sstevel@tonic-gate #ifdef WIN32_STUFF
810Sstevel@tonic-gate #include "winmain.h"
820Sstevel@tonic-gate #include "wintext.h"
830Sstevel@tonic-gate #endif
840Sstevel@tonic-gate #if !defined(OPENSSL_SYS_MSDOS)
850Sstevel@tonic-gate #include OPENSSL_UNISTD
860Sstevel@tonic-gate #endif
870Sstevel@tonic-gate
88*2139Sjp161948 #if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
890Sstevel@tonic-gate #define TIMES
900Sstevel@tonic-gate #endif
910Sstevel@tonic-gate
920Sstevel@tonic-gate #ifndef _IRIX
930Sstevel@tonic-gate #include <time.h>
940Sstevel@tonic-gate #endif
950Sstevel@tonic-gate #ifdef TIMES
960Sstevel@tonic-gate #include <sys/types.h>
970Sstevel@tonic-gate #include <sys/times.h>
980Sstevel@tonic-gate #endif
990Sstevel@tonic-gate
1000Sstevel@tonic-gate /* Depending on the VMS version, the tms structure is perhaps defined.
1010Sstevel@tonic-gate The __TMS macro will show if it was. If it wasn't defined, we should
1020Sstevel@tonic-gate undefine TIMES, since that tells the rest of the program how things
1030Sstevel@tonic-gate should be handled. -- Richard Levitte */
1040Sstevel@tonic-gate #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
1050Sstevel@tonic-gate #undef TIMES
1060Sstevel@tonic-gate #endif
1070Sstevel@tonic-gate
108*2139Sjp161948 #if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
1090Sstevel@tonic-gate #include <sys/timeb.h>
1100Sstevel@tonic-gate #endif
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate #if defined(sun) || defined(__ultrix)
1130Sstevel@tonic-gate #define _POSIX_SOURCE
1140Sstevel@tonic-gate #include <limits.h>
1150Sstevel@tonic-gate #include <sys/param.h>
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate /* The following if from times(3) man page. It may need to be changed
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate #ifndef HZ
1210Sstevel@tonic-gate # ifdef _SC_CLK_TCK
1220Sstevel@tonic-gate # define HZ ((double)sysconf(_SC_CLK_TCK))
1230Sstevel@tonic-gate # else
1240Sstevel@tonic-gate # ifndef CLK_TCK
1250Sstevel@tonic-gate # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
1260Sstevel@tonic-gate # define HZ 100.0
1270Sstevel@tonic-gate # else /* _BSD_CLK_TCK_ */
1280Sstevel@tonic-gate # define HZ ((double)_BSD_CLK_TCK_)
1290Sstevel@tonic-gate # endif
1300Sstevel@tonic-gate # else /* CLK_TCK */
1310Sstevel@tonic-gate # define HZ ((double)CLK_TCK)
1320Sstevel@tonic-gate # endif
1330Sstevel@tonic-gate # endif
1340Sstevel@tonic-gate #endif
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate #undef PROG
1370Sstevel@tonic-gate #define PROG s_time_main
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate #undef ioctl
1400Sstevel@tonic-gate #define ioctl ioctlsocket
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate #define SSL_CONNECT_NAME "localhost:4433"
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate /*#define TEST_CERT "client.pem" */ /* no default cert. */
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate #undef BUFSIZZ
1470Sstevel@tonic-gate #define BUFSIZZ 1024*10
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate #define MYBUFSIZ 1024*8
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate #undef min
1520Sstevel@tonic-gate #undef max
1530Sstevel@tonic-gate #define min(a,b) (((a) < (b)) ? (a) : (b))
1540Sstevel@tonic-gate #define max(a,b) (((a) > (b)) ? (a) : (b))
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate #undef SECONDS
1570Sstevel@tonic-gate #define SECONDS 30
1580Sstevel@tonic-gate extern int verify_depth;
1590Sstevel@tonic-gate extern int verify_error;
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate static void s_time_usage(void);
1620Sstevel@tonic-gate static int parseArgs( int argc, char **argv );
1630Sstevel@tonic-gate static SSL *doConnection( SSL *scon );
1640Sstevel@tonic-gate static void s_time_init(void);
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /***********************************************************************
1670Sstevel@tonic-gate * Static data declarations
1680Sstevel@tonic-gate */
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /* static char *port=PORT_STR;*/
1710Sstevel@tonic-gate static char *host=SSL_CONNECT_NAME;
1720Sstevel@tonic-gate static char *t_cert_file=NULL;
1730Sstevel@tonic-gate static char *t_key_file=NULL;
1740Sstevel@tonic-gate static char *CApath=NULL;
1750Sstevel@tonic-gate static char *CAfile=NULL;
1760Sstevel@tonic-gate static char *tm_cipher=NULL;
1770Sstevel@tonic-gate static int tm_verify = SSL_VERIFY_NONE;
1780Sstevel@tonic-gate static int maxTime = SECONDS;
1790Sstevel@tonic-gate static SSL_CTX *tm_ctx=NULL;
1800Sstevel@tonic-gate static SSL_METHOD *s_time_meth=NULL;
1810Sstevel@tonic-gate static char *s_www_path=NULL;
1820Sstevel@tonic-gate static long bytes_read=0;
1830Sstevel@tonic-gate static int st_bugs=0;
1840Sstevel@tonic-gate static int perform=0;
1850Sstevel@tonic-gate #ifdef FIONBIO
1860Sstevel@tonic-gate static int t_nbio=0;
1870Sstevel@tonic-gate #endif
1880Sstevel@tonic-gate #ifdef OPENSSL_SYS_WIN32
1890Sstevel@tonic-gate static int exitNow = 0; /* Set when it's time to exit main */
1900Sstevel@tonic-gate #endif
1910Sstevel@tonic-gate
s_time_init(void)1920Sstevel@tonic-gate static void s_time_init(void)
1930Sstevel@tonic-gate {
1940Sstevel@tonic-gate host=SSL_CONNECT_NAME;
1950Sstevel@tonic-gate t_cert_file=NULL;
1960Sstevel@tonic-gate t_key_file=NULL;
1970Sstevel@tonic-gate CApath=NULL;
1980Sstevel@tonic-gate CAfile=NULL;
1990Sstevel@tonic-gate tm_cipher=NULL;
2000Sstevel@tonic-gate tm_verify = SSL_VERIFY_NONE;
2010Sstevel@tonic-gate maxTime = SECONDS;
2020Sstevel@tonic-gate tm_ctx=NULL;
2030Sstevel@tonic-gate s_time_meth=NULL;
2040Sstevel@tonic-gate s_www_path=NULL;
2050Sstevel@tonic-gate bytes_read=0;
2060Sstevel@tonic-gate st_bugs=0;
2070Sstevel@tonic-gate perform=0;
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate #ifdef FIONBIO
2100Sstevel@tonic-gate t_nbio=0;
2110Sstevel@tonic-gate #endif
2120Sstevel@tonic-gate #ifdef OPENSSL_SYS_WIN32
2130Sstevel@tonic-gate exitNow = 0; /* Set when it's time to exit main */
2140Sstevel@tonic-gate #endif
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate /***********************************************************************
2180Sstevel@tonic-gate * usage - display usage message
2190Sstevel@tonic-gate */
s_time_usage(void)2200Sstevel@tonic-gate static void s_time_usage(void)
2210Sstevel@tonic-gate {
2220Sstevel@tonic-gate static char umsg[] = "\
2230Sstevel@tonic-gate -time arg - max number of seconds to collect data, default %d\n\
2240Sstevel@tonic-gate -verify arg - turn on peer certificate verification, arg == depth\n\
2250Sstevel@tonic-gate -cert arg - certificate file to use, PEM format assumed\n\
2260Sstevel@tonic-gate -key arg - RSA file to use, PEM format assumed, key is in cert file\n\
2270Sstevel@tonic-gate file if not specified by this option\n\
2280Sstevel@tonic-gate -CApath arg - PEM format directory of CA's\n\
2290Sstevel@tonic-gate -CAfile arg - PEM format file of CA's\n\
2300Sstevel@tonic-gate -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate printf( "usage: s_time <args>\n\n" );
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
2350Sstevel@tonic-gate #ifdef FIONBIO
2360Sstevel@tonic-gate printf("-nbio - Run with non-blocking IO\n");
2370Sstevel@tonic-gate printf("-ssl2 - Just use SSLv2\n");
2380Sstevel@tonic-gate printf("-ssl3 - Just use SSLv3\n");
2390Sstevel@tonic-gate printf("-bugs - Turn on SSL bug compatibility\n");
2400Sstevel@tonic-gate printf("-new - Just time new connections\n");
2410Sstevel@tonic-gate printf("-reuse - Just time connection reuse\n");
2420Sstevel@tonic-gate printf("-www page - Retrieve 'page' from the site\n");
2430Sstevel@tonic-gate #endif
2440Sstevel@tonic-gate printf( umsg,SECONDS );
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate /***********************************************************************
2480Sstevel@tonic-gate * parseArgs - Parse command line arguments and initialize data
2490Sstevel@tonic-gate *
2500Sstevel@tonic-gate * Returns 0 if ok, -1 on bad args
2510Sstevel@tonic-gate */
parseArgs(int argc,char ** argv)2520Sstevel@tonic-gate static int parseArgs(int argc, char **argv)
2530Sstevel@tonic-gate {
2540Sstevel@tonic-gate int badop = 0;
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate verify_depth=0;
2570Sstevel@tonic-gate verify_error=X509_V_OK;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate argc--;
2600Sstevel@tonic-gate argv++;
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate while (argc >= 1) {
2630Sstevel@tonic-gate if (strcmp(*argv,"-connect") == 0)
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate if (--argc < 1) goto bad;
2660Sstevel@tonic-gate host= *(++argv);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate #if 0
2690Sstevel@tonic-gate else if( strcmp(*argv,"-host") == 0)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate if (--argc < 1) goto bad;
2720Sstevel@tonic-gate host= *(++argv);
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate else if( strcmp(*argv,"-port") == 0)
2750Sstevel@tonic-gate {
2760Sstevel@tonic-gate if (--argc < 1) goto bad;
2770Sstevel@tonic-gate port= *(++argv);
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate #endif
2800Sstevel@tonic-gate else if (strcmp(*argv,"-reuse") == 0)
2810Sstevel@tonic-gate perform=2;
2820Sstevel@tonic-gate else if (strcmp(*argv,"-new") == 0)
2830Sstevel@tonic-gate perform=1;
2840Sstevel@tonic-gate else if( strcmp(*argv,"-verify") == 0) {
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
2870Sstevel@tonic-gate if (--argc < 1) goto bad;
2880Sstevel@tonic-gate verify_depth=atoi(*(++argv));
2890Sstevel@tonic-gate BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate } else if( strcmp(*argv,"-cert") == 0) {
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate if (--argc < 1) goto bad;
2940Sstevel@tonic-gate t_cert_file= *(++argv);
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate } else if( strcmp(*argv,"-key") == 0) {
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate if (--argc < 1) goto bad;
2990Sstevel@tonic-gate t_key_file= *(++argv);
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate } else if( strcmp(*argv,"-CApath") == 0) {
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate if (--argc < 1) goto bad;
3040Sstevel@tonic-gate CApath= *(++argv);
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate } else if( strcmp(*argv,"-CAfile") == 0) {
3070Sstevel@tonic-gate
3080Sstevel@tonic-gate if (--argc < 1) goto bad;
3090Sstevel@tonic-gate CAfile= *(++argv);
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate } else if( strcmp(*argv,"-cipher") == 0) {
3120Sstevel@tonic-gate
3130Sstevel@tonic-gate if (--argc < 1) goto bad;
3140Sstevel@tonic-gate tm_cipher= *(++argv);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate #ifdef FIONBIO
3170Sstevel@tonic-gate else if(strcmp(*argv,"-nbio") == 0) {
3180Sstevel@tonic-gate t_nbio=1;
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate #endif
3210Sstevel@tonic-gate else if(strcmp(*argv,"-www") == 0)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate if (--argc < 1) goto bad;
3240Sstevel@tonic-gate s_www_path= *(++argv);
3250Sstevel@tonic-gate if(strlen(s_www_path) > MYBUFSIZ-100)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate BIO_printf(bio_err,"-www option too long\n");
3280Sstevel@tonic-gate badop=1;
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate }
3310Sstevel@tonic-gate else if(strcmp(*argv,"-bugs") == 0)
3320Sstevel@tonic-gate st_bugs=1;
3330Sstevel@tonic-gate #ifndef OPENSSL_NO_SSL2
3340Sstevel@tonic-gate else if(strcmp(*argv,"-ssl2") == 0)
3350Sstevel@tonic-gate s_time_meth=SSLv2_client_method();
3360Sstevel@tonic-gate #endif
3370Sstevel@tonic-gate #ifndef OPENSSL_NO_SSL3
3380Sstevel@tonic-gate else if(strcmp(*argv,"-ssl3") == 0)
3390Sstevel@tonic-gate s_time_meth=SSLv3_client_method();
3400Sstevel@tonic-gate #endif
3410Sstevel@tonic-gate else if( strcmp(*argv,"-time") == 0) {
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate if (--argc < 1) goto bad;
3440Sstevel@tonic-gate maxTime= atoi(*(++argv));
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate else {
3470Sstevel@tonic-gate BIO_printf(bio_err,"unknown option %s\n",*argv);
3480Sstevel@tonic-gate badop=1;
3490Sstevel@tonic-gate break;
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate argc--;
3530Sstevel@tonic-gate argv++;
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate if (perform == 0) perform=3;
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate if(badop) {
3590Sstevel@tonic-gate bad:
3600Sstevel@tonic-gate s_time_usage();
3610Sstevel@tonic-gate return -1;
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate return 0; /* Valid args */
3650Sstevel@tonic-gate }
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate /***********************************************************************
3680Sstevel@tonic-gate * TIME - time functions
3690Sstevel@tonic-gate */
3700Sstevel@tonic-gate #define START 0
3710Sstevel@tonic-gate #define STOP 1
3720Sstevel@tonic-gate
tm_Time_F(int s)3730Sstevel@tonic-gate static double tm_Time_F(int s)
3740Sstevel@tonic-gate {
3750Sstevel@tonic-gate static double ret;
3760Sstevel@tonic-gate #ifdef TIMES
3770Sstevel@tonic-gate static struct tms tstart,tend;
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate if(s == START) {
3800Sstevel@tonic-gate times(&tstart);
3810Sstevel@tonic-gate return(0);
3820Sstevel@tonic-gate } else {
3830Sstevel@tonic-gate times(&tend);
3840Sstevel@tonic-gate ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
3850Sstevel@tonic-gate return((ret == 0.0)?1e-6:ret);
3860Sstevel@tonic-gate }
387*2139Sjp161948 #elif defined(OPENSSL_SYS_NETWARE)
388*2139Sjp161948 static clock_t tstart,tend;
389*2139Sjp161948
390*2139Sjp161948 if (s == START)
391*2139Sjp161948 {
392*2139Sjp161948 tstart=clock();
393*2139Sjp161948 return(0);
394*2139Sjp161948 }
395*2139Sjp161948 else
396*2139Sjp161948 {
397*2139Sjp161948 tend=clock();
398*2139Sjp161948 ret=(double)((double)(tend)-(double)(tstart));
399*2139Sjp161948 return((ret < 0.001)?0.001:ret);
400*2139Sjp161948 }
4010Sstevel@tonic-gate #elif defined(OPENSSL_SYS_VXWORKS)
4020Sstevel@tonic-gate {
4030Sstevel@tonic-gate static unsigned long tick_start, tick_end;
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate if( s == START )
4060Sstevel@tonic-gate {
4070Sstevel@tonic-gate tick_start = tickGet();
4080Sstevel@tonic-gate return 0;
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate else
4110Sstevel@tonic-gate {
4120Sstevel@tonic-gate tick_end = tickGet();
4130Sstevel@tonic-gate ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
4140Sstevel@tonic-gate return((ret == 0.0)?1e-6:ret);
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate #else /* !times() */
4180Sstevel@tonic-gate static struct timeb tstart,tend;
4190Sstevel@tonic-gate long i;
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate if(s == START) {
4220Sstevel@tonic-gate ftime(&tstart);
4230Sstevel@tonic-gate return(0);
4240Sstevel@tonic-gate } else {
4250Sstevel@tonic-gate ftime(&tend);
4260Sstevel@tonic-gate i=(long)tend.millitm-(long)tstart.millitm;
4270Sstevel@tonic-gate ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
4280Sstevel@tonic-gate return((ret == 0.0)?1e-6:ret);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate #endif
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate /***********************************************************************
4340Sstevel@tonic-gate * MAIN - main processing area for client
4350Sstevel@tonic-gate * real name depends on MONOLITH
4360Sstevel@tonic-gate */
4370Sstevel@tonic-gate int MAIN(int, char **);
4380Sstevel@tonic-gate
MAIN(int argc,char ** argv)4390Sstevel@tonic-gate int MAIN(int argc, char **argv)
4400Sstevel@tonic-gate {
4410Sstevel@tonic-gate double totalTime = 0.0;
4420Sstevel@tonic-gate int nConn = 0;
4430Sstevel@tonic-gate SSL *scon=NULL;
4440Sstevel@tonic-gate long finishtime=0;
4450Sstevel@tonic-gate int ret=1,i;
4460Sstevel@tonic-gate MS_STATIC char buf[1024*8];
4470Sstevel@tonic-gate int ver;
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate apps_startup();
4500Sstevel@tonic-gate s_time_init();
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate if (bio_err == NULL)
4530Sstevel@tonic-gate bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
4540Sstevel@tonic-gate
4550Sstevel@tonic-gate #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
4560Sstevel@tonic-gate s_time_meth=SSLv23_client_method();
4570Sstevel@tonic-gate #elif !defined(OPENSSL_NO_SSL3)
4580Sstevel@tonic-gate s_time_meth=SSLv3_client_method();
4590Sstevel@tonic-gate #elif !defined(OPENSSL_NO_SSL2)
4600Sstevel@tonic-gate s_time_meth=SSLv2_client_method();
4610Sstevel@tonic-gate #endif
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate /* parse the command line arguments */
4640Sstevel@tonic-gate if( parseArgs( argc, argv ) < 0 )
4650Sstevel@tonic-gate goto end;
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate OpenSSL_add_ssl_algorithms();
4680Sstevel@tonic-gate if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate SSL_CTX_set_quiet_shutdown(tm_ctx,1);
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
4730Sstevel@tonic-gate SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
4740Sstevel@tonic-gate if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))
4750Sstevel@tonic-gate goto end;
4760Sstevel@tonic-gate
4770Sstevel@tonic-gate SSL_load_error_strings();
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
4800Sstevel@tonic-gate (!SSL_CTX_set_default_verify_paths(tm_ctx)))
4810Sstevel@tonic-gate {
4820Sstevel@tonic-gate /* BIO_printf(bio_err,"error setting default verify locations\n"); */
4830Sstevel@tonic-gate ERR_print_errors(bio_err);
4840Sstevel@tonic-gate /* goto end; */
4850Sstevel@tonic-gate }
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate if (tm_cipher == NULL)
4880Sstevel@tonic-gate tm_cipher = getenv("SSL_CIPHER");
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate if (tm_cipher == NULL ) {
4910Sstevel@tonic-gate fprintf( stderr, "No CIPHER specified\n" );
4920Sstevel@tonic-gate }
4930Sstevel@tonic-gate
4940Sstevel@tonic-gate if (!(perform & 1)) goto next;
4950Sstevel@tonic-gate printf( "Collecting connection statistics for %d seconds\n", maxTime );
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate /* Loop and time how long it takes to make connections */
4980Sstevel@tonic-gate
4990Sstevel@tonic-gate bytes_read=0;
5000Sstevel@tonic-gate finishtime=(long)time(NULL)+maxTime;
5010Sstevel@tonic-gate tm_Time_F(START);
5020Sstevel@tonic-gate for (;;)
5030Sstevel@tonic-gate {
5040Sstevel@tonic-gate if (finishtime < (long)time(NULL)) break;
5050Sstevel@tonic-gate #ifdef WIN32_STUFF
5060Sstevel@tonic-gate
5070Sstevel@tonic-gate if( flushWinMsgs(0) == -1 )
5080Sstevel@tonic-gate goto end;
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate if( waitingToDie || exitNow ) /* we're dead */
5110Sstevel@tonic-gate goto end;
5120Sstevel@tonic-gate #endif
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate if( (scon = doConnection( NULL )) == NULL )
5150Sstevel@tonic-gate goto end;
5160Sstevel@tonic-gate
5170Sstevel@tonic-gate if (s_www_path != NULL)
5180Sstevel@tonic-gate {
5190Sstevel@tonic-gate BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
5200Sstevel@tonic-gate SSL_write(scon,buf,strlen(buf));
5210Sstevel@tonic-gate while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
5220Sstevel@tonic-gate bytes_read+=i;
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate
5250Sstevel@tonic-gate #ifdef NO_SHUTDOWN
5260Sstevel@tonic-gate SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
5270Sstevel@tonic-gate #else
5280Sstevel@tonic-gate SSL_shutdown(scon);
5290Sstevel@tonic-gate #endif
5300Sstevel@tonic-gate SHUTDOWN2(SSL_get_fd(scon));
5310Sstevel@tonic-gate
5320Sstevel@tonic-gate nConn += 1;
5330Sstevel@tonic-gate if (SSL_session_reused(scon))
5340Sstevel@tonic-gate ver='r';
5350Sstevel@tonic-gate else
5360Sstevel@tonic-gate {
5370Sstevel@tonic-gate ver=SSL_version(scon);
5380Sstevel@tonic-gate if (ver == TLS1_VERSION)
5390Sstevel@tonic-gate ver='t';
5400Sstevel@tonic-gate else if (ver == SSL3_VERSION)
5410Sstevel@tonic-gate ver='3';
5420Sstevel@tonic-gate else if (ver == SSL2_VERSION)
5430Sstevel@tonic-gate ver='2';
5440Sstevel@tonic-gate else
5450Sstevel@tonic-gate ver='*';
5460Sstevel@tonic-gate }
5470Sstevel@tonic-gate fputc(ver,stdout);
5480Sstevel@tonic-gate fflush(stdout);
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate SSL_free( scon );
5510Sstevel@tonic-gate scon=NULL;
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
5540Sstevel@tonic-gate
5550Sstevel@tonic-gate i=(int)((long)time(NULL)-finishtime+maxTime);
5560Sstevel@tonic-gate printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
5570Sstevel@tonic-gate printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate /* Now loop and time connections using the same session id over and over */
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate next:
5620Sstevel@tonic-gate if (!(perform & 2)) goto end;
5630Sstevel@tonic-gate printf( "\n\nNow timing with session id reuse.\n" );
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate /* Get an SSL object so we can reuse the session id */
5660Sstevel@tonic-gate if( (scon = doConnection( NULL )) == NULL )
5670Sstevel@tonic-gate {
5680Sstevel@tonic-gate fprintf( stderr, "Unable to get connection\n" );
5690Sstevel@tonic-gate goto end;
5700Sstevel@tonic-gate }
5710Sstevel@tonic-gate
5720Sstevel@tonic-gate if (s_www_path != NULL)
5730Sstevel@tonic-gate {
5740Sstevel@tonic-gate BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
5750Sstevel@tonic-gate SSL_write(scon,buf,strlen(buf));
5760Sstevel@tonic-gate while (SSL_read(scon,buf,sizeof(buf)) > 0)
5770Sstevel@tonic-gate ;
5780Sstevel@tonic-gate }
5790Sstevel@tonic-gate #ifdef NO_SHUTDOWN
5800Sstevel@tonic-gate SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
5810Sstevel@tonic-gate #else
5820Sstevel@tonic-gate SSL_shutdown(scon);
5830Sstevel@tonic-gate #endif
5840Sstevel@tonic-gate SHUTDOWN2(SSL_get_fd(scon));
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate nConn = 0;
5870Sstevel@tonic-gate totalTime = 0.0;
5880Sstevel@tonic-gate
5890Sstevel@tonic-gate finishtime=(long)time(NULL)+maxTime;
5900Sstevel@tonic-gate
5910Sstevel@tonic-gate printf( "starting\n" );
5920Sstevel@tonic-gate bytes_read=0;
5930Sstevel@tonic-gate tm_Time_F(START);
5940Sstevel@tonic-gate
5950Sstevel@tonic-gate for (;;)
5960Sstevel@tonic-gate {
5970Sstevel@tonic-gate if (finishtime < (long)time(NULL)) break;
5980Sstevel@tonic-gate
5990Sstevel@tonic-gate #ifdef WIN32_STUFF
6000Sstevel@tonic-gate if( flushWinMsgs(0) == -1 )
6010Sstevel@tonic-gate goto end;
6020Sstevel@tonic-gate
6030Sstevel@tonic-gate if( waitingToDie || exitNow ) /* we're dead */
6040Sstevel@tonic-gate goto end;
6050Sstevel@tonic-gate #endif
6060Sstevel@tonic-gate
6070Sstevel@tonic-gate if( (doConnection( scon )) == NULL )
6080Sstevel@tonic-gate goto end;
6090Sstevel@tonic-gate
6100Sstevel@tonic-gate if (s_www_path)
6110Sstevel@tonic-gate {
6120Sstevel@tonic-gate BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
6130Sstevel@tonic-gate SSL_write(scon,buf,strlen(buf));
6140Sstevel@tonic-gate while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
6150Sstevel@tonic-gate bytes_read+=i;
6160Sstevel@tonic-gate }
6170Sstevel@tonic-gate
6180Sstevel@tonic-gate #ifdef NO_SHUTDOWN
6190Sstevel@tonic-gate SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
6200Sstevel@tonic-gate #else
6210Sstevel@tonic-gate SSL_shutdown(scon);
6220Sstevel@tonic-gate #endif
6230Sstevel@tonic-gate SHUTDOWN2(SSL_get_fd(scon));
6240Sstevel@tonic-gate
6250Sstevel@tonic-gate nConn += 1;
6260Sstevel@tonic-gate if (SSL_session_reused(scon))
6270Sstevel@tonic-gate ver='r';
6280Sstevel@tonic-gate else
6290Sstevel@tonic-gate {
6300Sstevel@tonic-gate ver=SSL_version(scon);
6310Sstevel@tonic-gate if (ver == TLS1_VERSION)
6320Sstevel@tonic-gate ver='t';
6330Sstevel@tonic-gate else if (ver == SSL3_VERSION)
6340Sstevel@tonic-gate ver='3';
6350Sstevel@tonic-gate else if (ver == SSL2_VERSION)
6360Sstevel@tonic-gate ver='2';
6370Sstevel@tonic-gate else
6380Sstevel@tonic-gate ver='*';
6390Sstevel@tonic-gate }
6400Sstevel@tonic-gate fputc(ver,stdout);
6410Sstevel@tonic-gate fflush(stdout);
6420Sstevel@tonic-gate }
6430Sstevel@tonic-gate totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
6440Sstevel@tonic-gate
6450Sstevel@tonic-gate
6460Sstevel@tonic-gate printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
6470Sstevel@tonic-gate printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate ret=0;
6500Sstevel@tonic-gate end:
6510Sstevel@tonic-gate if (scon != NULL) SSL_free(scon);
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate if (tm_ctx != NULL)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate SSL_CTX_free(tm_ctx);
6560Sstevel@tonic-gate tm_ctx=NULL;
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate apps_shutdown();
6590Sstevel@tonic-gate OPENSSL_EXIT(ret);
6600Sstevel@tonic-gate }
6610Sstevel@tonic-gate
6620Sstevel@tonic-gate /***********************************************************************
6630Sstevel@tonic-gate * doConnection - make a connection
6640Sstevel@tonic-gate * Args:
6650Sstevel@tonic-gate * scon = earlier ssl connection for session id, or NULL
6660Sstevel@tonic-gate * Returns:
6670Sstevel@tonic-gate * SSL * = the connection pointer.
6680Sstevel@tonic-gate */
doConnection(SSL * scon)6690Sstevel@tonic-gate static SSL *doConnection(SSL *scon)
6700Sstevel@tonic-gate {
6710Sstevel@tonic-gate BIO *conn;
6720Sstevel@tonic-gate SSL *serverCon;
6730Sstevel@tonic-gate int width, i;
6740Sstevel@tonic-gate fd_set readfds;
6750Sstevel@tonic-gate
6760Sstevel@tonic-gate if ((conn=BIO_new(BIO_s_connect())) == NULL)
6770Sstevel@tonic-gate return(NULL);
6780Sstevel@tonic-gate
6790Sstevel@tonic-gate /* BIO_set_conn_port(conn,port);*/
6800Sstevel@tonic-gate BIO_set_conn_hostname(conn,host);
6810Sstevel@tonic-gate
6820Sstevel@tonic-gate if (scon == NULL)
6830Sstevel@tonic-gate serverCon=SSL_new(tm_ctx);
6840Sstevel@tonic-gate else
6850Sstevel@tonic-gate {
6860Sstevel@tonic-gate serverCon=scon;
6870Sstevel@tonic-gate SSL_set_connect_state(serverCon);
6880Sstevel@tonic-gate }
6890Sstevel@tonic-gate
6900Sstevel@tonic-gate SSL_set_bio(serverCon,conn,conn);
6910Sstevel@tonic-gate
6920Sstevel@tonic-gate #if 0
6930Sstevel@tonic-gate if( scon != NULL )
6940Sstevel@tonic-gate SSL_set_session(serverCon,SSL_get_session(scon));
6950Sstevel@tonic-gate #endif
6960Sstevel@tonic-gate
6970Sstevel@tonic-gate /* ok, lets connect */
6980Sstevel@tonic-gate for(;;) {
6990Sstevel@tonic-gate i=SSL_connect(serverCon);
7000Sstevel@tonic-gate if (BIO_sock_should_retry(i))
7010Sstevel@tonic-gate {
7020Sstevel@tonic-gate BIO_printf(bio_err,"DELAY\n");
7030Sstevel@tonic-gate
7040Sstevel@tonic-gate i=SSL_get_fd(serverCon);
7050Sstevel@tonic-gate width=i+1;
7060Sstevel@tonic-gate FD_ZERO(&readfds);
7070Sstevel@tonic-gate FD_SET(i,&readfds);
7080Sstevel@tonic-gate /* Note: under VMS with SOCKETSHR the 2nd parameter
7090Sstevel@tonic-gate * is currently of type (int *) whereas under other
7100Sstevel@tonic-gate * systems it is (void *) if you don't have a cast it
7110Sstevel@tonic-gate * will choke the compiler: if you do have a cast then
7120Sstevel@tonic-gate * you can either go for (int *) or (void *).
7130Sstevel@tonic-gate */
7140Sstevel@tonic-gate select(width,(void *)&readfds,NULL,NULL,NULL);
7150Sstevel@tonic-gate continue;
7160Sstevel@tonic-gate }
7170Sstevel@tonic-gate break;
7180Sstevel@tonic-gate }
7190Sstevel@tonic-gate if(i <= 0)
7200Sstevel@tonic-gate {
7210Sstevel@tonic-gate BIO_printf(bio_err,"ERROR\n");
7220Sstevel@tonic-gate if (verify_error != X509_V_OK)
7230Sstevel@tonic-gate BIO_printf(bio_err,"verify error:%s\n",
7240Sstevel@tonic-gate X509_verify_cert_error_string(verify_error));
7250Sstevel@tonic-gate else
7260Sstevel@tonic-gate ERR_print_errors(bio_err);
7270Sstevel@tonic-gate if (scon == NULL)
7280Sstevel@tonic-gate SSL_free(serverCon);
7290Sstevel@tonic-gate return NULL;
7300Sstevel@tonic-gate }
7310Sstevel@tonic-gate
7320Sstevel@tonic-gate return serverCon;
7330Sstevel@tonic-gate }
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate
736