/* apps/s_time.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* [including the GNU Public Licence.]
*/
-#undef NO_SHUTDOWN
+#define NO_SHUTDOWN
/*-----------------------------------------
- cntime - SSL client connection timer program
+ s_time - SSL client connection timer program
Written and donated by Larry Streepy <streepy@healthcare.com>
-----------------------------------------*/
#include <stdlib.h>
#include <string.h>
-#ifdef WIN16
-#define APPS_WIN16
-#endif
-#include "x509.h"
-#include "ssl.h"
-#include "pem.h"
#define USE_SOCKETS
#include "apps.h"
+#ifdef OPENSSL_NO_STDIO
+#define APPS_WIN16
+#endif
+#include <openssl/x509.h>
+#include <openssl/ssl.h>
+#include <openssl/pem.h>
#include "s_apps.h"
-#include "err.h"
+#include <openssl/err.h>
#ifdef WIN32_STUFF
#include "winmain.h"
#include "wintext.h"
#endif
+#if !defined(OPENSSL_SYS_MSDOS)
+#include OPENSSL_UNISTD
+#endif
-#ifndef MSDOS
+#if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
#define TIMES
#endif
-#ifndef VMS
#ifndef _IRIX
#include <time.h>
#endif
#include <sys/types.h>
#include <sys/times.h>
#endif
-#else /* VMS */
-#include <types.h>
-struct tms {
- time_t tms_utime;
- time_t tms_stime;
- time_t tms_uchild; /* I dunno... */
- time_t tms_uchildsys; /* so these names are a guess :-) */
- }
-#endif
-#ifndef TIMES
-#include <sys/timeb.h>
+
+/* Depending on the VMS version, the tms structure is perhaps defined.
+ The __TMS macro will show if it was. If it wasn't defined, we should
+ undefine TIMES, since that tells the rest of the program how things
+ should be handled. -- Richard Levitte */
+#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
+#undef TIMES
#endif
-#ifdef _AIX
-#include <sys/select.h>
+#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
+#include <sys/timeb.h>
#endif
-#ifdef sun
+#if defined(sun) || defined(__ultrix)
+#define _POSIX_SOURCE
#include <limits.h>
#include <sys/param.h>
#endif
/* The following if from times(3) man page. It may need to be changed
*/
#ifndef HZ
-#ifndef CLK_TCK
-#ifndef VMS
-#define HZ 100.0
-#else /* VMS */
-#define HZ 100.0
-#endif
-#else /* CLK_TCK */
-#define HZ ((double)CLK_TCK)
-#endif
+# ifdef _SC_CLK_TCK
+# define HZ ((double)sysconf(_SC_CLK_TCK))
+# else
+# ifndef CLK_TCK
+# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
+# define HZ 100.0
+# else /* _BSD_CLK_TCK_ */
+# define HZ ((double)_BSD_CLK_TCK_)
+# endif
+# else /* CLK_TCK */
+# define HZ ((double)CLK_TCK)
+# endif
+# endif
#endif
#undef PROG
#define PROG s_time_main
+#undef ioctl
#define ioctl ioctlsocket
#define SSL_CONNECT_NAME "localhost:4433"
#undef BUFSIZZ
#define BUFSIZZ 1024*10
+#define MYBUFSIZ 1024*8
+
+#undef min
+#undef max
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
extern int verify_depth;
extern int verify_error;
-#ifndef NOPROTO
static void s_time_usage(void);
static int parseArgs( int argc, char **argv );
static SSL *doConnection( SSL *scon );
-#else
-static void s_time_usage();
-static int parseArgs();
-static SSL *doConnection();
-#endif
-
+static void s_time_init(void);
/***********************************************************************
* Static data declarations
static int tm_verify = SSL_VERIFY_NONE;
static int maxTime = SECONDS;
static SSL_CTX *tm_ctx=NULL;
-static SSL_METHOD *s_time_meth=NULL;
+static const SSL_METHOD *s_time_meth=NULL;
static char *s_www_path=NULL;
static long bytes_read=0;
static int st_bugs=0;
static int perform=0;
-
#ifdef FIONBIO
static int t_nbio=0;
#endif
-
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
static int exitNow = 0; /* Set when it's time to exit main */
#endif
+static void s_time_init(void)
+ {
+ host=SSL_CONNECT_NAME;
+ t_cert_file=NULL;
+ t_key_file=NULL;
+ CApath=NULL;
+ CAfile=NULL;
+ tm_cipher=NULL;
+ tm_verify = SSL_VERIFY_NONE;
+ maxTime = SECONDS;
+ tm_ctx=NULL;
+ s_time_meth=NULL;
+ s_www_path=NULL;
+ bytes_read=0;
+ st_bugs=0;
+ perform=0;
+
+#ifdef FIONBIO
+ t_nbio=0;
+#endif
+#ifdef OPENSSL_SYS_WIN32
+ exitNow = 0; /* Set when it's time to exit main */
+#endif
+ }
+
/***********************************************************************
* usage - display usage message
*/
-static void s_time_usage()
+static void s_time_usage(void)
{
static char umsg[] = "\
-time arg - max number of seconds to collect data, default %d\n\
-verify arg - turn on peer certificate verification, arg == depth\n\
-cert arg - certificate file to use, PEM format assumed\n\
--key arg - RSA file to use, PEM format assumed, in cert file if\n\
- not specified but cert fill is.\n\
+-key arg - RSA file to use, PEM format assumed, key is in cert file\n\
+ file if not specified by this option\n\
-CApath arg - PEM format directory of CA's\n\
-CAfile arg - PEM format file of CA's\n\
--cipher - prefered cipher to use, play with 'ssleay ciphers'\n\n";
+-cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
- printf( "usage: client <args>\n\n" );
+ printf( "usage: s_time <args>\n\n" );
printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
#ifdef FIONBIO
printf("-nbio - Run with non-blocking IO\n");
printf("-ssl2 - Just use SSLv2\n");
printf("-ssl3 - Just use SSLv3\n");
- printf("-bugs - Turn on SSL bug compatability\n");
+ printf("-bugs - Turn on SSL bug compatibility\n");
printf("-new - Just time new connections\n");
printf("-reuse - Just time connection reuse\n");
printf("-www page - Retrieve 'page' from the site\n");
*
* Returns 0 if ok, -1 on bad args
*/
-static int parseArgs(argc,argv)
-int argc;
-char **argv;
+static int parseArgs(int argc, char **argv)
{
int badop = 0;
verify_depth=0;
verify_error=X509_V_OK;
-#ifdef FIONBIO
- t_nbio=0;
-#endif
-
- apps_startup();
-
- if (bio_err == NULL)
- bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
argc--;
argv++;
{
if (--argc < 1) goto bad;
s_www_path= *(++argv);
+ if(strlen(s_www_path) > MYBUFSIZ-100)
+ {
+ BIO_printf(bio_err,"-www option too long\n");
+ badop=1;
+ }
}
else if(strcmp(*argv,"-bugs") == 0)
st_bugs=1;
-#ifndef NO_SSL2
+#ifndef OPENSSL_NO_SSL2
else if(strcmp(*argv,"-ssl2") == 0)
s_time_meth=SSLv2_client_method();
#endif
-#ifndef NO_SSL3
+#ifndef OPENSSL_NO_SSL3
else if(strcmp(*argv,"-ssl3") == 0)
s_time_meth=SSLv3_client_method();
#endif
#define START 0
#define STOP 1
-static double tm_Time_F(s)
-int s;
+static double tm_Time_F(int s)
{
static double ret;
#ifdef TIMES
ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
return((ret == 0.0)?1e-6:ret);
}
+#elif defined(OPENSSL_SYS_NETWARE)
+ static clock_t tstart,tend;
+
+ if (s == START)
+ {
+ tstart=clock();
+ return(0);
+ }
+ else
+ {
+ tend=clock();
+ ret=(double)((double)(tend)-(double)(tstart));
+ return((ret < 0.001)?0.001:ret);
+ }
+#elif defined(OPENSSL_SYS_VXWORKS)
+ {
+ static unsigned long tick_start, tick_end;
+
+ if( s == START )
+ {
+ tick_start = tickGet();
+ return 0;
+ }
+ else
+ {
+ tick_end = tickGet();
+ ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
+ return((ret == 0.0)?1e-6:ret);
+ }
+ }
#else /* !times() */
static struct timeb tstart,tend;
long i;
* MAIN - main processing area for client
* real name depends on MONOLITH
*/
-int
-MAIN(argc,argv)
-int argc;
-char **argv;
+int MAIN(int, char **);
+
+int MAIN(int argc, char **argv)
{
double totalTime = 0.0;
int nConn = 0;
long finishtime=0;
int ret=1,i;
MS_STATIC char buf[1024*8];
+ int ver;
-#if !defined(NO_SSL2) && !defined(NO_SSL3)
+ apps_startup();
+ s_time_init();
+
+ if (bio_err == NULL)
+ bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
+
+#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
s_time_meth=SSLv23_client_method();
-#elif !defined(NO_SSL3)
+#elif !defined(OPENSSL_NO_SSL3)
s_time_meth=SSLv3_client_method();
-#elif !defined(NO_SSL2)
+#elif !defined(OPENSSL_NO_SSL2)
s_time_meth=SSLv2_client_method();
#endif
if( parseArgs( argc, argv ) < 0 )
goto end;
- SSLeay_add_ssl_algorithms();
+ OpenSSL_add_ssl_algorithms();
if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
+ SSL_CTX_set_quiet_shutdown(tm_ctx,1);
+
if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))
if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
(!SSL_CTX_set_default_verify_paths(tm_ctx)))
{
- BIO_printf(bio_err,"error seting default verify locations\n");
+ /* BIO_printf(bio_err,"error setting default verify locations\n"); */
ERR_print_errors(bio_err);
- goto end;
+ /* goto end; */
}
if (tm_cipher == NULL)
if (tm_cipher == NULL ) {
fprintf( stderr, "No CIPHER specified\n" );
-/* EXIT(1); */
}
if (!(perform & 1)) goto next;
tm_Time_F(START);
for (;;)
{
- if (finishtime < time(NULL)) break;
+ if (finishtime < (long)time(NULL)) break;
#ifdef WIN32_STUFF
if( flushWinMsgs(0) == -1 )
if (s_www_path != NULL)
{
- sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+ BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
SSL_write(scon,buf,strlen(buf));
while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
bytes_read+=i;
#else
SSL_shutdown(scon);
#endif
- SHUTDOWN(SSL_get_fd(scon));
+ SHUTDOWN2(SSL_get_fd(scon));
nConn += 1;
- fputc(SSL_session_reused(scon)?'r':
- (SSL_version(scon))+'0', stdout );
+ if (SSL_session_reused(scon))
+ ver='r';
+ else
+ {
+ ver=SSL_version(scon);
+ if (ver == TLS1_VERSION)
+ ver='t';
+ else if (ver == SSL3_VERSION)
+ ver='3';
+ else if (ver == SSL2_VERSION)
+ ver='2';
+ else
+ ver='*';
+ }
+ fputc(ver,stdout);
fflush(stdout);
SSL_free( scon );
}
totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
- i=(int)(time(NULL)-finishtime+maxTime);
+ i=(int)((long)time(NULL)-finishtime+maxTime);
printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
- printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
+ printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
/* Now loop and time connections using the same session id over and over */
if (s_www_path != NULL)
{
- sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+ BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
SSL_write(scon,buf,strlen(buf));
while (SSL_read(scon,buf,sizeof(buf)) > 0)
;
#else
SSL_shutdown(scon);
#endif
- SHUTDOWN(SSL_get_fd(scon));
+ SHUTDOWN2(SSL_get_fd(scon));
nConn = 0;
totalTime = 0.0;
- finishtime=time(NULL)+maxTime;
+ finishtime=(long)time(NULL)+maxTime;
printf( "starting\n" );
bytes_read=0;
for (;;)
{
- if (finishtime < time(NULL)) break;
+ if (finishtime < (long)time(NULL)) break;
#ifdef WIN32_STUFF
if( flushWinMsgs(0) == -1 )
if (s_www_path)
{
- sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
+ BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
SSL_write(scon,buf,strlen(buf));
while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
bytes_read+=i;
#else
SSL_shutdown(scon);
#endif
- SHUTDOWN(SSL_get_fd(scon));
+ SHUTDOWN2(SSL_get_fd(scon));
nConn += 1;
- fputc(SSL_session_reused(scon)?'r':
- (SSL_version(scon))+'0', stdout );
+ if (SSL_session_reused(scon))
+ ver='r';
+ else
+ {
+ ver=SSL_version(scon);
+ if (ver == TLS1_VERSION)
+ ver='t';
+ else if (ver == SSL3_VERSION)
+ ver='3';
+ else if (ver == SSL2_VERSION)
+ ver='2';
+ else
+ ver='*';
+ }
+ fputc(ver,stdout);
fflush(stdout);
}
totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
- printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
+ printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
ret=0;
end:
SSL_CTX_free(tm_ctx);
tm_ctx=NULL;
}
- EXIT(ret);
+ apps_shutdown();
+ OPENSSL_EXIT(ret);
}
/***********************************************************************
* Returns:
* SSL * = the connection pointer.
*/
-static SSL *
-doConnection(scon)
-SSL *scon;
+static SSL *doConnection(SSL *scon)
{
BIO *conn;
SSL *serverCon;
if ((conn=BIO_new(BIO_s_connect())) == NULL)
return(NULL);
-/* BIO_set_port(conn,port);*/
- BIO_set_hostname(conn,host);
+/* BIO_set_conn_port(conn,port);*/
+ BIO_set_conn_hostname(conn,host);
if (scon == NULL)
- serverCon=(SSL *)SSL_new(tm_ctx);
+ serverCon=SSL_new(tm_ctx);
else
{
serverCon=scon;
width=i+1;
FD_ZERO(&readfds);
FD_SET(i,&readfds);
- select(width,&readfds,NULL,NULL,NULL);
+ /* Note: under VMS with SOCKETSHR the 2nd parameter
+ * is currently of type (int *) whereas under other
+ * systems it is (void *) if you don't have a cast it
+ * will choke the compiler: if you do have a cast then
+ * you can either go for (int *) or (void *).
+ */
+ select(width,(void *)&readfds,NULL,NULL,NULL);
continue;
}
break;