72 #ifdef OPENSSL_NO_STDIO
84 #if !defined(OPENSSL_SYS_MSDOS)
85 #include OPENSSL_UNISTD
89 #define PROG s_time_main
92 #define ioctl ioctlsocket
94 #define SSL_CONNECT_NAME "localhost:4433"
99 #define BUFSIZZ 1024*10
101 #define MYBUFSIZ 1024*8
105 #define min(a,b) (((a) < (b)) ? (a) : (b))
106 #define max(a,b) (((a) > (b)) ? (a) : (b))
113 static void s_time_usage(
void);
114 static int parseArgs(
int argc,
char **argv );
115 static SSL *doConnection(
SSL *scon );
116 static void s_time_init(
void);
124 static char *t_cert_file=NULL;
125 static char *t_key_file=NULL;
126 static char *CApath=NULL;
127 static char *CAfile=NULL;
128 static char *tm_cipher=NULL;
133 static char *s_www_path=NULL;
134 static long bytes_read=0;
135 static int st_bugs=0;
136 static int perform=0;
140 #ifdef OPENSSL_SYS_WIN32
141 static int exitNow = 0;
144 static void s_time_init(
void)
164 #ifdef OPENSSL_SYS_WIN32
172 static void s_time_usage(
void)
174 static char umsg[] =
"\
175 -time arg - max number of seconds to collect data, default %d\n\
176 -verify arg - turn on peer certificate verification, arg == depth\n\
177 -cert arg - certificate file to use, PEM format assumed\n\
178 -key arg - RSA file to use, PEM format assumed, key is in cert file\n\
179 file if not specified by this option\n\
180 -CApath arg - PEM format directory of CA's\n\
181 -CAfile arg - PEM format file of CA's\n\
182 -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
184 printf(
"usage: s_time <args>\n\n" );
186 printf(
"-connect host:port - host:port to connect to (default is %s)\n",
SSL_CONNECT_NAME);
188 printf(
"-nbio - Run with non-blocking IO\n");
189 printf(
"-ssl2 - Just use SSLv2\n");
190 printf(
"-ssl3 - Just use SSLv3\n");
191 printf(
"-bugs - Turn on SSL bug compatibility\n");
192 printf(
"-new - Just time new connections\n");
193 printf(
"-reuse - Just time connection reuse\n");
194 printf(
"-www page - Retrieve 'page' from the site\n");
204 static int parseArgs(
int argc,
char **argv)
215 if (strcmp(*argv,
"-connect") == 0)
217 if (--argc < 1)
goto bad;
221 else if( strcmp(*argv,
"-host") == 0)
223 if (--argc < 1)
goto bad;
226 else if( strcmp(*argv,
"-port") == 0)
228 if (--argc < 1)
goto bad;
232 else if (strcmp(*argv,
"-reuse") == 0)
234 else if (strcmp(*argv,
"-new") == 0)
236 else if( strcmp(*argv,
"-verify") == 0) {
239 if (--argc < 1)
goto bad;
243 }
else if( strcmp(*argv,
"-cert") == 0) {
245 if (--argc < 1)
goto bad;
246 t_cert_file= *(++argv);
248 }
else if( strcmp(*argv,
"-key") == 0) {
250 if (--argc < 1)
goto bad;
251 t_key_file= *(++argv);
253 }
else if( strcmp(*argv,
"-CApath") == 0) {
255 if (--argc < 1)
goto bad;
258 }
else if( strcmp(*argv,
"-CAfile") == 0) {
260 if (--argc < 1)
goto bad;
263 }
else if( strcmp(*argv,
"-cipher") == 0) {
265 if (--argc < 1)
goto bad;
266 tm_cipher= *(++argv);
269 else if(strcmp(*argv,
"-nbio") == 0) {
273 else if(strcmp(*argv,
"-www") == 0)
275 if (--argc < 1)
goto bad;
276 s_www_path= *(++argv);
277 if(strlen(s_www_path) >
MYBUFSIZ-100)
283 else if(strcmp(*argv,
"-bugs") == 0)
285 #ifndef OPENSSL_NO_SSL2
286 else if(strcmp(*argv,
"-ssl2") == 0)
289 #ifndef OPENSSL_NO_SSL3
290 else if(strcmp(*argv,
"-ssl3") == 0)
293 else if( strcmp(*argv,
"-time") == 0) {
295 if (--argc < 1)
goto bad;
296 maxTime= atoi(*(++argv));
308 if (perform == 0) perform=3;
325 static double tm_Time_F(
int s)
334 int MAIN(
int,
char **);
336 int MAIN(
int argc,
char **argv)
338 double totalTime = 0.0;
352 #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
354 #elif !defined(OPENSSL_NO_SSL3)
356 #elif !defined(OPENSSL_NO_SSL2)
361 if( parseArgs( argc, argv ) < 0 )
365 if ((tm_ctx=
SSL_CTX_new(s_time_meth)) == NULL)
return(1);
384 if (tm_cipher == NULL)
385 tm_cipher = getenv(
"SSL_CIPHER");
387 if (tm_cipher == NULL ) {
388 fprintf( stderr,
"No CIPHER specified\n" );
391 if (!(perform & 1))
goto next;
392 printf(
"Collecting connection statistics for %d seconds\n", maxTime );
397 finishtime=(long)time(NULL)+maxTime;
401 if (finishtime < (
long)time(NULL))
break;
404 if( flushWinMsgs(0) == -1 )
407 if( waitingToDie || exitNow )
411 if( (scon = doConnection( NULL )) == NULL )
414 if (s_www_path != NULL)
416 BIO_snprintf(buf,
sizeof buf,
"GET %s HTTP/1.0\r\n\r\n",s_www_path);
418 while ((i=
SSL_read(scon,buf,
sizeof(buf))) > 0)
450 totalTime += tm_Time_F(
STOP);
452 i=(int)((
long)time(NULL)-finishtime+maxTime);
453 printf(
"\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((
double)nConn/totalTime),bytes_read);
454 printf(
"%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(
long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
459 if (!(perform & 2))
goto end;
460 printf(
"\n\nNow timing with session id reuse.\n" );
463 if( (scon = doConnection( NULL )) == NULL )
465 fprintf( stderr,
"Unable to get connection\n" );
469 if (s_www_path != NULL)
471 BIO_snprintf(buf,
sizeof buf,
"GET %s HTTP/1.0\r\n\r\n",s_www_path);
473 while (
SSL_read(scon,buf,
sizeof(buf)) > 0)
486 finishtime=(long)time(NULL)+maxTime;
488 printf(
"starting\n" );
494 if (finishtime < (
long)time(NULL))
break;
497 if( flushWinMsgs(0) == -1 )
500 if( waitingToDie || exitNow )
504 if( (doConnection( scon )) == NULL )
509 BIO_snprintf(buf,
sizeof buf,
"GET %s HTTP/1.0\r\n\r\n",s_www_path);
511 while ((i=
SSL_read(scon,buf,
sizeof(buf))) > 0)
540 totalTime += tm_Time_F(
STOP);
543 printf(
"\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((
double)nConn/totalTime),bytes_read);
544 printf(
"%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(
long)time(NULL)-finishtime+maxTime,bytes_read/nConn);
566 static SSL *doConnection(
SSL *scon)
611 select(width,(
void *)&readfds,NULL,NULL,NULL);