Main Page | Class List | Directories | File List | Class Members | File Members

s_time.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
#include <openssl/x509.h>
#include <openssl/ssl.h>
#include <openssl/pem.h>
#include "s_apps.h"
#include <openssl/err.h>
#include <time.h>
#include <sys/types.h>
#include <sys/times.h>

Go to the source code of this file.

Defines

#define NO_SHUTDOWN
#define USE_SOCKETS
#define TIMES
#define HZ   100.0
#define PROG   s_time_main
#define ioctl   ioctlsocket
#define SSL_CONNECT_NAME   "localhost:4433"
#define BUFSIZZ   1024*10
#define MYBUFSIZ   1024*8
#define min(a, b)   (((a) < (b)) ? (a) : (b))
#define max(a, b)   (((a) > (b)) ? (a) : (b))
#define SECONDS   30
#define START   0
#define STOP   1

Functions

static void s_time_usage (void)
static int parseArgs (int argc, char **argv)
static SSLdoConnection (SSL *scon)
static void s_time_init (void)
static double tm_Time_F (int s)
int MAIN (int, char **)

Variables

int verify_depth
int verify_error
static char * host = SSL_CONNECT_NAME
static char * t_cert_file = NULL
static char * t_key_file = NULL
static char * CApath = NULL
static char * CAfile = NULL
static char * tm_cipher = NULL
static int tm_verify = SSL_VERIFY_NONE
static int maxTime = SECONDS
static SSL_CTXtm_ctx = NULL
static SSL_METHODs_time_meth = NULL
static char * s_www_path = NULL
static long bytes_read = 0
static int st_bugs = 0
static int perform = 0


Define Documentation

#define BUFSIZZ   1024*10
 

Definition at line 147 of file s_time.c.

#define HZ   100.0
 

Definition at line 126 of file s_time.c.

Referenced by ms_time_cmp(), ms_time_diff(), Time_F(), and tm_Time_F().

#define ioctl   ioctlsocket
 

Definition at line 140 of file s_time.c.

#define max a,
b   )     (((a) > (b)) ? (a) : (b))
 

Definition at line 154 of file s_time.c.

Referenced by _dopr(), ASN1_GENERALIZEDTIME_check(), ASN1_get_object(), ASN1_UTCTIME_check(), bio_ber_get_header(), BN_from_montgomery(), BN_GF2m_mod(), BN_sqr(), bn_sqr_normal(), BN_sub(), BN_uadd(), BN_usub(), main(), PEM_SealInit(), PKCS7_dataDecode(), PKCS7_dataInit(), tls_sockets_select(), and TXT_DB_free().

#define min a,
b   )     (((a) < (b)) ? (a) : (b))
 

Definition at line 153 of file s_time.c.

Referenced by _dopr(), ASN1_GENERALIZEDTIME_check(), ASN1_UTCTIME_check(), BN_uadd(), BN_usub(), and PKCS12_key_gen_uni().

#define MYBUFSIZ   1024*8
 

Definition at line 149 of file s_time.c.

Referenced by parseArgs().

#define NO_SHUTDOWN
 

Definition at line 59 of file s_time.c.

#define PROG   s_time_main
 

Definition at line 137 of file s_time.c.

#define SECONDS   30
 

Definition at line 157 of file s_time.c.

Referenced by print_message(), s_time_init(), and s_time_usage().

#define SSL_CONNECT_NAME   "localhost:4433"
 

Definition at line 142 of file s_time.c.

Referenced by s_time_init(), and s_time_usage().

#define START   0
 

Definition at line 370 of file s_time.c.

Referenced by do_mul(), do_mul_exp(), main(), Time_F(), and tm_Time_F().

#define STOP   1
 

Definition at line 371 of file s_time.c.

Referenced by do_mul(), do_mul_exp(), and main().

#define TIMES
 

Definition at line 89 of file s_time.c.

#define USE_SOCKETS
 

Definition at line 70 of file s_time.c.


Function Documentation

static SSL * doConnection SSL scon  )  [static]
 

Definition at line 669 of file s_time.c.

References bio_err, BIO_new(), BIO_printf(), BIO_s_connect(), BIO_set_conn_hostname, BIO_sock_should_retry(), ERR_print_errors(), host, SSL_connect(), SSL_free(), SSL_get_fd(), SSL_get_session(), SSL_new(), SSL_set_bio(), SSL_set_connect_state(), SSL_set_session(), verify_error, X509_V_OK, and X509_verify_cert_error_string().

00670         {
00671         BIO *conn;
00672         SSL *serverCon;
00673         int width, i;
00674         fd_set readfds;
00675 
00676         if ((conn=BIO_new(BIO_s_connect())) == NULL)
00677                 return(NULL);
00678 
00679 /*      BIO_set_conn_port(conn,port);*/
00680         BIO_set_conn_hostname(conn,host);
00681 
00682         if (scon == NULL)
00683                 serverCon=SSL_new(tm_ctx);
00684         else
00685                 {
00686                 serverCon=scon;
00687                 SSL_set_connect_state(serverCon);
00688                 }
00689 
00690         SSL_set_bio(serverCon,conn,conn);
00691 
00692 #if 0
00693         if( scon != NULL )
00694                 SSL_set_session(serverCon,SSL_get_session(scon));
00695 #endif
00696 
00697         /* ok, lets connect */
00698         for(;;) {
00699                 i=SSL_connect(serverCon);
00700                 if (BIO_sock_should_retry(i))
00701                         {
00702                         BIO_printf(bio_err,"DELAY\n");
00703 
00704                         i=SSL_get_fd(serverCon);
00705                         width=i+1;
00706                         FD_ZERO(&readfds);
00707                         FD_SET(i,&readfds);
00708                         /* Note: under VMS with SOCKETSHR the 2nd parameter
00709                          * is currently of type (int *) whereas under other
00710                          * systems it is (void *) if you don't have a cast it
00711                          * will choke the compiler: if you do have a cast then
00712                          * you can either go for (int *) or (void *).
00713                          */
00714                         select(width,(void *)&readfds,NULL,NULL,NULL);
00715                         continue;
00716                         }
00717                 break;
00718                 }
00719         if(i <= 0)
00720                 {
00721                 BIO_printf(bio_err,"ERROR\n");
00722                 if (verify_error != X509_V_OK)
00723                         BIO_printf(bio_err,"verify error:%s\n",
00724                                 X509_verify_cert_error_string(verify_error));
00725                 else
00726                         ERR_print_errors(bio_err);
00727                 if (scon == NULL)
00728                         SSL_free(serverCon);
00729                 return NULL;
00730                 }
00731 
00732         return serverCon;
00733         }

int MAIN int  ,
char ** 
 

static int parseArgs int  argc,
char **  argv
[static]
 

Definition at line 252 of file s_time.c.

References bio_err, BIO_printf(), CAfile, CApath, host, maxTime, MYBUFSIZ, perform, s_time_usage(), s_www_path, SSL_VERIFY_CLIENT_ONCE, SSL_VERIFY_PEER, SSLv2_client_method(), SSLv3_client_method(), st_bugs, t_cert_file, t_key_file, tm_cipher, tm_verify, verify_depth, verify_error, and X509_V_OK.

00253 {
00254     int badop = 0;
00255 
00256     verify_depth=0;
00257     verify_error=X509_V_OK;
00258 
00259     argc--;
00260     argv++;
00261 
00262     while (argc >= 1) {
00263         if (strcmp(*argv,"-connect") == 0)
00264                 {
00265                 if (--argc < 1) goto bad;
00266                 host= *(++argv);
00267                 }
00268 #if 0
00269         else if( strcmp(*argv,"-host") == 0)
00270                 {
00271                 if (--argc < 1) goto bad;
00272                 host= *(++argv);
00273                 }
00274         else if( strcmp(*argv,"-port") == 0)
00275                 {
00276                 if (--argc < 1) goto bad;
00277                 port= *(++argv);
00278                 }
00279 #endif
00280         else if (strcmp(*argv,"-reuse") == 0)
00281                 perform=2;
00282         else if (strcmp(*argv,"-new") == 0)
00283                 perform=1;
00284         else if( strcmp(*argv,"-verify") == 0) {
00285 
00286             tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
00287             if (--argc < 1) goto bad;
00288             verify_depth=atoi(*(++argv));
00289             BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
00290 
00291         } else if( strcmp(*argv,"-cert") == 0) {
00292 
00293             if (--argc < 1) goto bad;
00294             t_cert_file= *(++argv);
00295 
00296         } else if( strcmp(*argv,"-key") == 0) {
00297 
00298             if (--argc < 1) goto bad;
00299             t_key_file= *(++argv);
00300 
00301         } else if( strcmp(*argv,"-CApath") == 0) {
00302 
00303             if (--argc < 1) goto bad;
00304             CApath= *(++argv);
00305 
00306         } else if( strcmp(*argv,"-CAfile") == 0) {
00307 
00308             if (--argc < 1) goto bad;
00309             CAfile= *(++argv);
00310 
00311         } else if( strcmp(*argv,"-cipher") == 0) {
00312 
00313             if (--argc < 1) goto bad;
00314             tm_cipher= *(++argv);
00315         }
00316 #ifdef FIONBIO
00317         else if(strcmp(*argv,"-nbio") == 0) {
00318             t_nbio=1;
00319         }
00320 #endif
00321         else if(strcmp(*argv,"-www") == 0)
00322                 {
00323                 if (--argc < 1) goto bad;
00324                 s_www_path= *(++argv);
00325                 if(strlen(s_www_path) > MYBUFSIZ-100)
00326                         {
00327                         BIO_printf(bio_err,"-www option too long\n");
00328                         badop=1;
00329                         }
00330                 }
00331         else if(strcmp(*argv,"-bugs") == 0)
00332             st_bugs=1;
00333 #ifndef OPENSSL_NO_SSL2
00334         else if(strcmp(*argv,"-ssl2") == 0)
00335             s_time_meth=SSLv2_client_method();
00336 #endif
00337 #ifndef OPENSSL_NO_SSL3
00338         else if(strcmp(*argv,"-ssl3") == 0)
00339             s_time_meth=SSLv3_client_method();
00340 #endif
00341         else if( strcmp(*argv,"-time") == 0) {
00342 
00343             if (--argc < 1) goto bad;
00344             maxTime= atoi(*(++argv));
00345         }
00346         else {
00347             BIO_printf(bio_err,"unknown option %s\n",*argv);
00348             badop=1;
00349             break;
00350         }
00351 
00352         argc--;
00353         argv++;
00354     }
00355 
00356     if (perform == 0) perform=3;
00357 
00358     if(badop) {
00359 bad:
00360                 s_time_usage();
00361                 return -1;
00362     }
00363 
00364         return 0;                       /* Valid args */
00365 }

static void s_time_init void   )  [static]
 

Definition at line 192 of file s_time.c.

References bytes_read, CAfile, CApath, host, maxTime, perform, s_www_path, SECONDS, SSL_CONNECT_NAME, SSL_VERIFY_NONE, st_bugs, t_cert_file, t_key_file, tm_cipher, and tm_verify.

00193         {
00194         host=SSL_CONNECT_NAME;
00195         t_cert_file=NULL;
00196         t_key_file=NULL;
00197         CApath=NULL;
00198         CAfile=NULL;
00199         tm_cipher=NULL;
00200         tm_verify = SSL_VERIFY_NONE;
00201         maxTime = SECONDS;
00202         tm_ctx=NULL;
00203         s_time_meth=NULL;
00204         s_www_path=NULL;
00205         bytes_read=0; 
00206         st_bugs=0;
00207         perform=0;
00208 
00209 #ifdef FIONBIO
00210         t_nbio=0;
00211 #endif
00212 #ifdef OPENSSL_SYS_WIN32
00213         exitNow = 0;            /* Set when it's time to exit main */
00214 #endif
00215         }

static void s_time_usage void   )  [static]
 

Definition at line 220 of file s_time.c.

References SECONDS, and SSL_CONNECT_NAME.

Referenced by parseArgs().

00221 {
00222         static char umsg[] = "\
00223 -time arg     - max number of seconds to collect data, default %d\n\
00224 -verify arg   - turn on peer certificate verification, arg == depth\n\
00225 -cert arg     - certificate file to use, PEM format assumed\n\
00226 -key arg      - RSA file to use, PEM format assumed, key is in cert file\n\
00227                 file if not specified by this option\n\
00228 -CApath arg   - PEM format directory of CA's\n\
00229 -CAfile arg   - PEM format file of CA's\n\
00230 -cipher       - preferred cipher to use, play with 'openssl ciphers'\n\n";
00231 
00232         printf( "usage: s_time <args>\n\n" );
00233 
00234         printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
00235 #ifdef FIONBIO
00236         printf("-nbio         - Run with non-blocking IO\n");
00237         printf("-ssl2         - Just use SSLv2\n");
00238         printf("-ssl3         - Just use SSLv3\n");
00239         printf("-bugs         - Turn on SSL bug compatibility\n");
00240         printf("-new          - Just time new connections\n");
00241         printf("-reuse        - Just time connection reuse\n");
00242         printf("-www page     - Retrieve 'page' from the site\n");
00243 #endif
00244         printf( umsg,SECONDS );
00245 }

static double tm_Time_F int  s  )  [static]
 

Definition at line 373 of file s_time.c.

References e, HZ, ret, and START.

00374         {
00375         static double ret;
00376 #ifdef TIMES
00377         static struct tms tstart,tend;
00378 
00379         if(s == START) {
00380                 times(&tstart);
00381                 return(0);
00382         } else {
00383                 times(&tend);
00384                 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
00385                 return((ret == 0.0)?1e-6:ret);
00386         }
00387 #elif defined(OPENSSL_SYS_NETWARE)
00388     static clock_t tstart,tend;
00389 
00390     if (s == START)
00391     {
00392         tstart=clock();
00393         return(0);
00394     }
00395     else
00396     {
00397         tend=clock();
00398         ret=(double)((double)(tend)-(double)(tstart));
00399         return((ret < 0.001)?0.001:ret);
00400     }
00401 #elif defined(OPENSSL_SYS_VXWORKS)
00402         {
00403         static unsigned long tick_start, tick_end;
00404 
00405         if( s == START )
00406                 {
00407                 tick_start = tickGet();
00408                 return 0;
00409                 }
00410         else
00411                 {
00412                 tick_end = tickGet();
00413                 ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
00414                 return((ret == 0.0)?1e-6:ret);
00415                 }
00416         }
00417 #else /* !times() */
00418         static struct timeb tstart,tend;
00419         long i;
00420 
00421         if(s == START) {
00422                 ftime(&tstart);
00423                 return(0);
00424         } else {
00425                 ftime(&tend);
00426                 i=(long)tend.millitm-(long)tstart.millitm;
00427                 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
00428                 return((ret == 0.0)?1e-6:ret);
00429         }
00430 #endif
00431 }


Variable Documentation

long bytes_read = 0 [static]
 

Definition at line 182 of file s_time.c.

Referenced by s_time_init().

char* CAfile = NULL [static]
 

Definition at line 175 of file s_time.c.

Referenced by main(), MAIN(), parseArgs(), and s_time_init().

char* CApath = NULL [static]
 

Definition at line 174 of file s_time.c.

Referenced by main(), MAIN(), parseArgs(), and s_time_init().

char* host = SSL_CONNECT_NAME [static]
 

Definition at line 171 of file s_time.c.

Referenced by doConnection(), main(), OCSP_parse_url(), parseArgs(), and s_time_init().

int maxTime = SECONDS [static]
 

Definition at line 178 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

int perform = 0 [static]
 

Definition at line 184 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

SSL_METHOD* s_time_meth = NULL [static]
 

Definition at line 180 of file s_time.c.

char* s_www_path = NULL [static]
 

Definition at line 181 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

int st_bugs = 0 [static]
 

Definition at line 183 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

char* t_cert_file = NULL [static]
 

Definition at line 172 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

char* t_key_file = NULL [static]
 

Definition at line 173 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

char* tm_cipher = NULL [static]
 

Definition at line 176 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

SSL_CTX* tm_ctx = NULL [static]
 

Definition at line 179 of file s_time.c.

int tm_verify = SSL_VERIFY_NONE [static]
 

Definition at line 177 of file s_time.c.

Referenced by parseArgs(), and s_time_init().

int verify_depth
 

Definition at line 124 of file s_cb.c.

Referenced by MAIN(), main(), parseArgs(), and verify_callback().

int verify_error
 

Definition at line 125 of file s_cb.c.

Referenced by doConnection(), init_ssl_connection(), parseArgs(), and verify_callback().


© sourcejam.com 2005-2008