s_time.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#define NO_SHUTDOWN
/*-----------------------------------------
s_time - SSL client connection timer program
Written and donated by Larry Streepy <streepy@healthcare.com>
-----------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define USE_SOCKETS
#include "apps.h"
#ifdef OPENSSL_NO_STDIO
#define APPS_WIN16
#endif
#include "s_apps.h"
#ifdef WIN32_STUFF
#include "winmain.h"
#include "wintext.h"
#endif
#if !defined(OPENSSL_SYS_MSDOS)
#include OPENSSL_UNISTD
#endif
#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
#define TIMES
#endif
#ifndef _IRIX
#include <time.h>
#endif
#ifdef TIMES
#endif
/* 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)
#endif
#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS)
#endif
#define _POSIX_SOURCE
#include <limits.h>
#endif
/* The following if from times(3) man page. It may need to be changed
*/
#ifndef HZ
# ifdef _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 */
# endif
# endif
#endif
#define PROG s_time_main
#define ioctl ioctlsocket
#define SSL_CONNECT_NAME "localhost:4433"
/*#define TEST_CERT "client.pem" */ /* no default cert. */
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define SECONDS 30
extern int verify_depth;
extern int verify_error;
static void s_time_usage(void);
static void s_time_init(void);
/***********************************************************************
* Static data declarations
*/
/* static char *port=PORT_STR;*/
static char *host=SSL_CONNECT_NAME;
static char *t_cert_file=NULL;
static char *t_key_file=NULL;
static int tm_verify = SSL_VERIFY_NONE;
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 OPENSSL_SYS_WIN32
static int exitNow = 0; /* Set when it's time to exit main */
#endif
static void s_time_init(void)
{
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(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, 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 - preferred cipher to use, play with 'openssl ciphers'\n\n";
printf( "usage: s_time <args>\n\n" );
#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 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");
#endif
}
/***********************************************************************
* parseArgs - Parse command line arguments and initialize data
*
* Returns 0 if ok, -1 on bad args
*/
{
int badop = 0;
verify_depth=0;
argc--;
argv++;
while (argc >= 1) {
{
}
#if 0
{
}
{
}
#endif
perform=2;
perform=1;
t_cert_file= *(++argv);
t_key_file= *(++argv);
}
#ifdef FIONBIO
t_nbio=1;
}
#endif
{
s_www_path= *(++argv);
{
badop=1;
}
}
st_bugs=1;
#ifndef OPENSSL_NO_SSL2
#endif
#ifndef OPENSSL_NO_SSL3
#endif
}
else {
badop=1;
break;
}
argc--;
argv++;
}
if(badop) {
bad:
s_time_usage();
return -1;
}
return 0; /* Valid args */
}
/***********************************************************************
* TIME - time functions
*/
#define START 0
#define STOP 1
static double tm_Time_F(int s)
{
static double ret;
#ifdef TIMES
if(s == START) {
return(0);
} else {
}
#elif defined(OPENSSL_SYS_VXWORKS)
{
static unsigned long tick_start, tick_end;
if( s == START )
{
tick_start = tickGet();
return 0;
}
else
{
}
}
#else /* !times() */
long i;
if(s == START) {
return(0);
} else {
}
#endif
}
/***********************************************************************
* MAIN - main processing area for client
* real name depends on MONOLITH
*/
int MAIN(int, char **);
{
double totalTime = 0.0;
int nConn = 0;
long finishtime=0;
int ret=1,i;
int ver;
apps_startup();
s_time_init();
#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
#elif !defined(OPENSSL_NO_SSL3)
#elif !defined(OPENSSL_NO_SSL2)
#endif
/* parse the command line arguments */
goto end;
goto end;
{
/* BIO_printf(bio_err,"error setting default verify locations\n"); */
/* goto end; */
}
}
/* Loop and time how long it takes to make connections */
bytes_read=0;
for (;;)
{
#ifdef WIN32_STUFF
if( flushWinMsgs(0) == -1 )
goto end;
goto end;
#endif
goto end;
if (s_www_path != NULL)
{
bytes_read+=i;
}
#ifdef NO_SHUTDOWN
#else
#endif
nConn += 1;
if (SSL_session_reused(scon))
ver='r';
else
{
if (ver == TLS1_VERSION)
ver='t';
else if (ver == SSL3_VERSION)
ver='3';
else if (ver == SSL2_VERSION)
ver='2';
else
ver='*';
}
}
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,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
/* Now loop and time connections using the same session id over and over */
next:
printf( "\n\nNow timing with session id reuse.\n" );
/* Get an SSL object so we can reuse the session id */
{
goto end;
}
if (s_www_path != NULL)
{
;
}
#ifdef NO_SHUTDOWN
#else
#endif
nConn = 0;
totalTime = 0.0;
printf( "starting\n" );
bytes_read=0;
for (;;)
{
#ifdef WIN32_STUFF
if( flushWinMsgs(0) == -1 )
goto end;
goto end;
#endif
goto end;
if (s_www_path)
{
bytes_read+=i;
}
#ifdef NO_SHUTDOWN
#else
#endif
nConn += 1;
if (SSL_session_reused(scon))
ver='r';
else
{
if (ver == TLS1_VERSION)
ver='t';
else if (ver == SSL3_VERSION)
ver='3';
else if (ver == SSL2_VERSION)
ver='2';
else
ver='*';
}
}
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,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
ret=0;
end:
{
}
}
/***********************************************************************
* doConnection - make a connection
* Args:
* scon = earlier ssl connection for session id, or NULL
* Returns:
* SSL * = the connection pointer.
*/
{
int width, i;
return(NULL);
/* BIO_set_conn_port(conn,port);*/
else
{
}
#if 0
#endif
/* ok, lets connect */
for(;;) {
i=SSL_connect(serverCon);
if (BIO_sock_should_retry(i))
{
i=SSL_get_fd(serverCon);
width=i+1;
/* 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 *).
*/
continue;
}
break;
}
if(i <= 0)
{
if (verify_error != X509_V_OK)
else
return NULL;
}
return serverCon;
}