174664626SKris Kennaway /* apps/s_time.c */ 274664626SKris Kennaway /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 374664626SKris Kennaway * All rights reserved. 474664626SKris Kennaway * 574664626SKris Kennaway * This package is an SSL implementation written 674664626SKris Kennaway * by Eric Young (eay@cryptsoft.com). 774664626SKris Kennaway * The implementation was written so as to conform with Netscapes SSL. 874664626SKris Kennaway * 974664626SKris Kennaway * This library is free for commercial and non-commercial use as long as 1074664626SKris Kennaway * the following conditions are aheared to. The following conditions 1174664626SKris Kennaway * apply to all code found in this distribution, be it the RC4, RSA, 1274664626SKris Kennaway * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1374664626SKris Kennaway * included with this distribution is covered by the same copyright terms 1474664626SKris Kennaway * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1574664626SKris Kennaway * 1674664626SKris Kennaway * Copyright remains Eric Young's, and as such any Copyright notices in 1774664626SKris Kennaway * the code are not to be removed. 1874664626SKris Kennaway * If this package is used in a product, Eric Young should be given attribution 1974664626SKris Kennaway * as the author of the parts of the library used. 2074664626SKris Kennaway * This can be in the form of a textual message at program startup or 2174664626SKris Kennaway * in documentation (online or textual) provided with the package. 2274664626SKris Kennaway * 2374664626SKris Kennaway * Redistribution and use in source and binary forms, with or without 2474664626SKris Kennaway * modification, are permitted provided that the following conditions 2574664626SKris Kennaway * are met: 2674664626SKris Kennaway * 1. Redistributions of source code must retain the copyright 2774664626SKris Kennaway * notice, this list of conditions and the following disclaimer. 2874664626SKris Kennaway * 2. Redistributions in binary form must reproduce the above copyright 2974664626SKris Kennaway * notice, this list of conditions and the following disclaimer in the 3074664626SKris Kennaway * documentation and/or other materials provided with the distribution. 3174664626SKris Kennaway * 3. All advertising materials mentioning features or use of this software 3274664626SKris Kennaway * must display the following acknowledgement: 3374664626SKris Kennaway * "This product includes cryptographic software written by 3474664626SKris Kennaway * Eric Young (eay@cryptsoft.com)" 3574664626SKris Kennaway * The word 'cryptographic' can be left out if the rouines from the library 3674664626SKris Kennaway * being used are not cryptographic related :-). 3774664626SKris Kennaway * 4. If you include any Windows specific code (or a derivative thereof) from 3874664626SKris Kennaway * the apps directory (application code) you must include an acknowledgement: 3974664626SKris Kennaway * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4074664626SKris Kennaway * 4174664626SKris Kennaway * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4274664626SKris Kennaway * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4374664626SKris Kennaway * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4474664626SKris Kennaway * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4574664626SKris Kennaway * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4674664626SKris Kennaway * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4774664626SKris Kennaway * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4874664626SKris Kennaway * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4974664626SKris Kennaway * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5074664626SKris Kennaway * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5174664626SKris Kennaway * SUCH DAMAGE. 5274664626SKris Kennaway * 5374664626SKris Kennaway * The licence and distribution terms for any publically available version or 5474664626SKris Kennaway * derivative of this code cannot be changed. i.e. this code cannot simply be 5574664626SKris Kennaway * copied and put under another distribution licence 5674664626SKris Kennaway * [including the GNU Public Licence.] 5774664626SKris Kennaway */ 5874664626SKris Kennaway 5974664626SKris Kennaway #define NO_SHUTDOWN 6074664626SKris Kennaway 616f9291ceSJung-uk Kim /* ---------------------------------------- 6274664626SKris Kennaway s_time - SSL client connection timer program 6374664626SKris Kennaway Written and donated by Larry Streepy <streepy@healthcare.com> 6474664626SKris Kennaway -----------------------------------------*/ 6574664626SKris Kennaway 6674664626SKris Kennaway #include <stdio.h> 6774664626SKris Kennaway #include <stdlib.h> 6874664626SKris Kennaway #include <string.h> 6974664626SKris Kennaway 705c87c606SMark Murray #define USE_SOCKETS 715c87c606SMark Murray #include "apps.h" 725c87c606SMark Murray #ifdef OPENSSL_NO_STDIO 7374664626SKris Kennaway # define APPS_WIN16 7474664626SKris Kennaway #endif 7574664626SKris Kennaway #include <openssl/x509.h> 7674664626SKris Kennaway #include <openssl/ssl.h> 7774664626SKris Kennaway #include <openssl/pem.h> 7874664626SKris Kennaway #include "s_apps.h" 7974664626SKris Kennaway #include <openssl/err.h> 8074664626SKris Kennaway #ifdef WIN32_STUFF 8174664626SKris Kennaway # include "winmain.h" 8274664626SKris Kennaway # include "wintext.h" 8374664626SKris Kennaway #endif 845c87c606SMark Murray #if !defined(OPENSSL_SYS_MSDOS) 855c87c606SMark Murray # include OPENSSL_UNISTD 865c87c606SMark Murray #endif 8774664626SKris Kennaway 8874664626SKris Kennaway #undef PROG 8974664626SKris Kennaway #define PROG s_time_main 9074664626SKris Kennaway 9174664626SKris Kennaway #undef ioctl 9274664626SKris Kennaway #define ioctl ioctlsocket 9374664626SKris Kennaway 9474664626SKris Kennaway #define SSL_CONNECT_NAME "localhost:4433" 9574664626SKris Kennaway 966f9291ceSJung-uk Kim /* no default cert. */ 976f9291ceSJung-uk Kim /* 986f9291ceSJung-uk Kim * #define TEST_CERT "client.pem" 996f9291ceSJung-uk Kim */ 10074664626SKris Kennaway 10174664626SKris Kennaway #undef BUFSIZZ 10274664626SKris Kennaway #define BUFSIZZ 1024*10 10374664626SKris Kennaway 1045c87c606SMark Murray #define MYBUFSIZ 1024*8 1055c87c606SMark Murray 106c1803d78SJacques Vidrine #undef min 107c1803d78SJacques Vidrine #undef max 10874664626SKris Kennaway #define min(a,b) (((a) < (b)) ? (a) : (b)) 10974664626SKris Kennaway #define max(a,b) (((a) > (b)) ? (a) : (b)) 11074664626SKris Kennaway 11174664626SKris Kennaway #undef SECONDS 11274664626SKris Kennaway #define SECONDS 30 11374664626SKris Kennaway extern int verify_depth; 11474664626SKris Kennaway extern int verify_error; 11574664626SKris Kennaway 11674664626SKris Kennaway static void s_time_usage(void); 11774664626SKris Kennaway static int parseArgs(int argc, char **argv); 11874664626SKris Kennaway static SSL *doConnection(SSL *scon); 11974664626SKris Kennaway static void s_time_init(void); 12074664626SKris Kennaway 12174664626SKris Kennaway /*********************************************************************** 12274664626SKris Kennaway * Static data declarations 12374664626SKris Kennaway */ 12474664626SKris Kennaway 12574664626SKris Kennaway /* static char *port=PORT_STR;*/ 12674664626SKris Kennaway static char *host = SSL_CONNECT_NAME; 12774664626SKris Kennaway static char *t_cert_file = NULL; 12874664626SKris Kennaway static char *t_key_file = NULL; 12974664626SKris Kennaway static char *CApath = NULL; 13074664626SKris Kennaway static char *CAfile = NULL; 13174664626SKris Kennaway static char *tm_cipher = NULL; 13274664626SKris Kennaway static int tm_verify = SSL_VERIFY_NONE; 13374664626SKris Kennaway static int maxTime = SECONDS; 13474664626SKris Kennaway static SSL_CTX *tm_ctx = NULL; 1351f13597dSJung-uk Kim static const SSL_METHOD *s_time_meth = NULL; 13674664626SKris Kennaway static char *s_www_path = NULL; 13774664626SKris Kennaway static long bytes_read = 0; 13874664626SKris Kennaway static int st_bugs = 0; 13974664626SKris Kennaway static int perform = 0; 14074664626SKris Kennaway #ifdef FIONBIO 14174664626SKris Kennaway static int t_nbio = 0; 14274664626SKris Kennaway #endif 1435c87c606SMark Murray #ifdef OPENSSL_SYS_WIN32 14474664626SKris Kennaway static int exitNow = 0; /* Set when it's time to exit main */ 14574664626SKris Kennaway #endif 14674664626SKris Kennaway 14774664626SKris Kennaway static void s_time_init(void) 14874664626SKris Kennaway { 14974664626SKris Kennaway host = SSL_CONNECT_NAME; 15074664626SKris Kennaway t_cert_file = NULL; 15174664626SKris Kennaway t_key_file = NULL; 15274664626SKris Kennaway CApath = NULL; 15374664626SKris Kennaway CAfile = NULL; 15474664626SKris Kennaway tm_cipher = NULL; 15574664626SKris Kennaway tm_verify = SSL_VERIFY_NONE; 15674664626SKris Kennaway maxTime = SECONDS; 15774664626SKris Kennaway tm_ctx = NULL; 15874664626SKris Kennaway s_time_meth = NULL; 15974664626SKris Kennaway s_www_path = NULL; 16074664626SKris Kennaway bytes_read = 0; 16174664626SKris Kennaway st_bugs = 0; 16274664626SKris Kennaway perform = 0; 16374664626SKris Kennaway 16474664626SKris Kennaway #ifdef FIONBIO 16574664626SKris Kennaway t_nbio = 0; 16674664626SKris Kennaway #endif 1675c87c606SMark Murray #ifdef OPENSSL_SYS_WIN32 16874664626SKris Kennaway exitNow = 0; /* Set when it's time to exit main */ 16974664626SKris Kennaway #endif 17074664626SKris Kennaway } 17174664626SKris Kennaway 17274664626SKris Kennaway /*********************************************************************** 17374664626SKris Kennaway * usage - display usage message 17474664626SKris Kennaway */ 17574664626SKris Kennaway static void s_time_usage(void) 17674664626SKris Kennaway { 17774664626SKris Kennaway static char umsg[] = "\ 17874664626SKris Kennaway -time arg - max number of seconds to collect data, default %d\n\ 17974664626SKris Kennaway -verify arg - turn on peer certificate verification, arg == depth\n\ 18074664626SKris Kennaway -cert arg - certificate file to use, PEM format assumed\n\ 18174664626SKris Kennaway -key arg - RSA file to use, PEM format assumed, key is in cert file\n\ 18274664626SKris Kennaway file if not specified by this option\n\ 18374664626SKris Kennaway -CApath arg - PEM format directory of CA's\n\ 18474664626SKris Kennaway -CAfile arg - PEM format file of CA's\n\ 185f579bf8eSKris Kennaway -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n"; 18674664626SKris Kennaway 18774664626SKris Kennaway printf("usage: s_time <args>\n\n"); 18874664626SKris Kennaway 1896f9291ceSJung-uk Kim printf("-connect host:port - host:port to connect to (default is %s)\n", 1906f9291ceSJung-uk Kim SSL_CONNECT_NAME); 19174664626SKris Kennaway #ifdef FIONBIO 19274664626SKris Kennaway printf("-nbio - Run with non-blocking IO\n"); 19374664626SKris Kennaway printf("-ssl2 - Just use SSLv2\n"); 19474664626SKris Kennaway printf("-ssl3 - Just use SSLv3\n"); 195f579bf8eSKris Kennaway printf("-bugs - Turn on SSL bug compatibility\n"); 19674664626SKris Kennaway printf("-new - Just time new connections\n"); 19774664626SKris Kennaway printf("-reuse - Just time connection reuse\n"); 19874664626SKris Kennaway printf("-www page - Retrieve 'page' from the site\n"); 19974664626SKris Kennaway #endif 20074664626SKris Kennaway printf(umsg, SECONDS); 20174664626SKris Kennaway } 20274664626SKris Kennaway 20374664626SKris Kennaway /*********************************************************************** 20474664626SKris Kennaway * parseArgs - Parse command line arguments and initialize data 20574664626SKris Kennaway * 20674664626SKris Kennaway * Returns 0 if ok, -1 on bad args 20774664626SKris Kennaway */ 20874664626SKris Kennaway static int parseArgs(int argc, char **argv) 20974664626SKris Kennaway { 21074664626SKris Kennaway int badop = 0; 21174664626SKris Kennaway 21274664626SKris Kennaway verify_depth = 0; 21374664626SKris Kennaway verify_error = X509_V_OK; 21474664626SKris Kennaway 21574664626SKris Kennaway argc--; 21674664626SKris Kennaway argv++; 21774664626SKris Kennaway 21874664626SKris Kennaway while (argc >= 1) { 2196f9291ceSJung-uk Kim if (strcmp(*argv, "-connect") == 0) { 2206f9291ceSJung-uk Kim if (--argc < 1) 2216f9291ceSJung-uk Kim goto bad; 22274664626SKris Kennaway host = *(++argv); 22374664626SKris Kennaway } 22474664626SKris Kennaway #if 0 2256f9291ceSJung-uk Kim else if (strcmp(*argv, "-host") == 0) { 2266f9291ceSJung-uk Kim if (--argc < 1) 2276f9291ceSJung-uk Kim goto bad; 22874664626SKris Kennaway host = *(++argv); 2296f9291ceSJung-uk Kim } else if (strcmp(*argv, "-port") == 0) { 2306f9291ceSJung-uk Kim if (--argc < 1) 2316f9291ceSJung-uk Kim goto bad; 23274664626SKris Kennaway port = *(++argv); 23374664626SKris Kennaway } 23474664626SKris Kennaway #endif 23574664626SKris Kennaway else if (strcmp(*argv, "-reuse") == 0) 23674664626SKris Kennaway perform = 2; 23774664626SKris Kennaway else if (strcmp(*argv, "-new") == 0) 23874664626SKris Kennaway perform = 1; 23974664626SKris Kennaway else if (strcmp(*argv, "-verify") == 0) { 24074664626SKris Kennaway 24174664626SKris Kennaway tm_verify = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE; 2426f9291ceSJung-uk Kim if (--argc < 1) 2436f9291ceSJung-uk Kim goto bad; 24474664626SKris Kennaway verify_depth = atoi(*(++argv)); 24574664626SKris Kennaway BIO_printf(bio_err, "verify depth is %d\n", verify_depth); 24674664626SKris Kennaway 24774664626SKris Kennaway } else if (strcmp(*argv, "-cert") == 0) { 24874664626SKris Kennaway 2496f9291ceSJung-uk Kim if (--argc < 1) 2506f9291ceSJung-uk Kim goto bad; 25174664626SKris Kennaway t_cert_file = *(++argv); 25274664626SKris Kennaway 25374664626SKris Kennaway } else if (strcmp(*argv, "-key") == 0) { 25474664626SKris Kennaway 2556f9291ceSJung-uk Kim if (--argc < 1) 2566f9291ceSJung-uk Kim goto bad; 25774664626SKris Kennaway t_key_file = *(++argv); 25874664626SKris Kennaway 25974664626SKris Kennaway } else if (strcmp(*argv, "-CApath") == 0) { 26074664626SKris Kennaway 2616f9291ceSJung-uk Kim if (--argc < 1) 2626f9291ceSJung-uk Kim goto bad; 26374664626SKris Kennaway CApath = *(++argv); 26474664626SKris Kennaway 26574664626SKris Kennaway } else if (strcmp(*argv, "-CAfile") == 0) { 26674664626SKris Kennaway 2676f9291ceSJung-uk Kim if (--argc < 1) 2686f9291ceSJung-uk Kim goto bad; 26974664626SKris Kennaway CAfile = *(++argv); 27074664626SKris Kennaway 27174664626SKris Kennaway } else if (strcmp(*argv, "-cipher") == 0) { 27274664626SKris Kennaway 2736f9291ceSJung-uk Kim if (--argc < 1) 2746f9291ceSJung-uk Kim goto bad; 27574664626SKris Kennaway tm_cipher = *(++argv); 27674664626SKris Kennaway } 27774664626SKris Kennaway #ifdef FIONBIO 27874664626SKris Kennaway else if (strcmp(*argv, "-nbio") == 0) { 27974664626SKris Kennaway t_nbio = 1; 28074664626SKris Kennaway } 28174664626SKris Kennaway #endif 2826f9291ceSJung-uk Kim else if (strcmp(*argv, "-www") == 0) { 2836f9291ceSJung-uk Kim if (--argc < 1) 2846f9291ceSJung-uk Kim goto bad; 28574664626SKris Kennaway s_www_path = *(++argv); 2866f9291ceSJung-uk Kim if (strlen(s_www_path) > MYBUFSIZ - 100) { 2875c87c606SMark Murray BIO_printf(bio_err, "-www option too long\n"); 2885c87c606SMark Murray badop = 1; 2895c87c606SMark Murray } 2906f9291ceSJung-uk Kim } else if (strcmp(*argv, "-bugs") == 0) 29174664626SKris Kennaway st_bugs = 1; 2925c87c606SMark Murray #ifndef OPENSSL_NO_SSL2 29374664626SKris Kennaway else if (strcmp(*argv, "-ssl2") == 0) 29474664626SKris Kennaway s_time_meth = SSLv2_client_method(); 29574664626SKris Kennaway #endif 2965c87c606SMark Murray #ifndef OPENSSL_NO_SSL3 29774664626SKris Kennaway else if (strcmp(*argv, "-ssl3") == 0) 29874664626SKris Kennaway s_time_meth = SSLv3_client_method(); 29974664626SKris Kennaway #endif 30074664626SKris Kennaway else if (strcmp(*argv, "-time") == 0) { 30174664626SKris Kennaway 3026f9291ceSJung-uk Kim if (--argc < 1) 3036f9291ceSJung-uk Kim goto bad; 30474664626SKris Kennaway maxTime = atoi(*(++argv)); 3056f9291ceSJung-uk Kim if(maxTime <= 0) { 3066f9291ceSJung-uk Kim BIO_printf(bio_err, "time must be > 0\n"); 3076f9291ceSJung-uk Kim badop = 1; 30874664626SKris Kennaway } 3096f9291ceSJung-uk Kim } else { 31074664626SKris Kennaway BIO_printf(bio_err, "unknown option %s\n", *argv); 31174664626SKris Kennaway badop = 1; 31274664626SKris Kennaway break; 31374664626SKris Kennaway } 31474664626SKris Kennaway 31574664626SKris Kennaway argc--; 31674664626SKris Kennaway argv++; 31774664626SKris Kennaway } 31874664626SKris Kennaway 3196f9291ceSJung-uk Kim if (perform == 0) 3206f9291ceSJung-uk Kim perform = 3; 32174664626SKris Kennaway 32274664626SKris Kennaway if (badop) { 32374664626SKris Kennaway bad: 32474664626SKris Kennaway s_time_usage(); 32574664626SKris Kennaway return -1; 32674664626SKris Kennaway } 32774664626SKris Kennaway 32874664626SKris Kennaway return 0; /* Valid args */ 32974664626SKris Kennaway } 33074664626SKris Kennaway 33174664626SKris Kennaway /*********************************************************************** 33274664626SKris Kennaway * TIME - time functions 33374664626SKris Kennaway */ 33474664626SKris Kennaway #define START 0 33574664626SKris Kennaway #define STOP 1 33674664626SKris Kennaway 33774664626SKris Kennaway static double tm_Time_F(int s) 33874664626SKris Kennaway { 3391f13597dSJung-uk Kim return app_tminterval(s, 1); 34074664626SKris Kennaway } 34174664626SKris Kennaway 34274664626SKris Kennaway /*********************************************************************** 34374664626SKris Kennaway * MAIN - main processing area for client 34474664626SKris Kennaway * real name depends on MONOLITH 34574664626SKris Kennaway */ 346f579bf8eSKris Kennaway int MAIN(int, char **); 347f579bf8eSKris Kennaway 34874664626SKris Kennaway int MAIN(int argc, char **argv) 34974664626SKris Kennaway { 35074664626SKris Kennaway double totalTime = 0.0; 35174664626SKris Kennaway int nConn = 0; 35274664626SKris Kennaway SSL *scon = NULL; 35374664626SKris Kennaway long finishtime = 0; 35474664626SKris Kennaway int ret = 1, i; 35574664626SKris Kennaway MS_STATIC char buf[1024 * 8]; 35674664626SKris Kennaway int ver; 35774664626SKris Kennaway 358f579bf8eSKris Kennaway apps_startup(); 359f579bf8eSKris Kennaway s_time_init(); 360f579bf8eSKris Kennaway 361f579bf8eSKris Kennaway if (bio_err == NULL) 362f579bf8eSKris Kennaway bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); 363f579bf8eSKris Kennaway 36474664626SKris Kennaway s_time_meth = SSLv23_client_method(); 36574664626SKris Kennaway 36674664626SKris Kennaway /* parse the command line arguments */ 36774664626SKris Kennaway if (parseArgs(argc, argv) < 0) 36874664626SKris Kennaway goto end; 36974664626SKris Kennaway 370f579bf8eSKris Kennaway OpenSSL_add_ssl_algorithms(); 3716f9291ceSJung-uk Kim if ((tm_ctx = SSL_CTX_new(s_time_meth)) == NULL) 3726f9291ceSJung-uk Kim return (1); 37374664626SKris Kennaway 37474664626SKris Kennaway SSL_CTX_set_quiet_shutdown(tm_ctx, 1); 37574664626SKris Kennaway 3766f9291ceSJung-uk Kim if (st_bugs) 3776f9291ceSJung-uk Kim SSL_CTX_set_options(tm_ctx, SSL_OP_ALL); 37874664626SKris Kennaway SSL_CTX_set_cipher_list(tm_ctx, tm_cipher); 37974664626SKris Kennaway if (!set_cert_stuff(tm_ctx, t_cert_file, t_key_file)) 38074664626SKris Kennaway goto end; 38174664626SKris Kennaway 38274664626SKris Kennaway SSL_load_error_strings(); 38374664626SKris Kennaway 38474664626SKris Kennaway if ((!SSL_CTX_load_verify_locations(tm_ctx, CAfile, CApath)) || 3856f9291ceSJung-uk Kim (!SSL_CTX_set_default_verify_paths(tm_ctx))) { 3866f9291ceSJung-uk Kim /* 3876f9291ceSJung-uk Kim * BIO_printf(bio_err,"error setting default verify locations\n"); 3886f9291ceSJung-uk Kim */ 38974664626SKris Kennaway ERR_print_errors(bio_err); 39074664626SKris Kennaway /* goto end; */ 39174664626SKris Kennaway } 39274664626SKris Kennaway 39374664626SKris Kennaway if (tm_cipher == NULL) 39474664626SKris Kennaway tm_cipher = getenv("SSL_CIPHER"); 39574664626SKris Kennaway 39674664626SKris Kennaway if (tm_cipher == NULL) { 39774664626SKris Kennaway fprintf(stderr, "No CIPHER specified\n"); 39874664626SKris Kennaway } 39974664626SKris Kennaway 4006f9291ceSJung-uk Kim if (!(perform & 1)) 4016f9291ceSJung-uk Kim goto next; 40274664626SKris Kennaway printf("Collecting connection statistics for %d seconds\n", maxTime); 40374664626SKris Kennaway 40474664626SKris Kennaway /* Loop and time how long it takes to make connections */ 40574664626SKris Kennaway 40674664626SKris Kennaway bytes_read = 0; 40774664626SKris Kennaway finishtime = (long)time(NULL) + maxTime; 40874664626SKris Kennaway tm_Time_F(START); 4096f9291ceSJung-uk Kim for (;;) { 4106f9291ceSJung-uk Kim if (finishtime < (long)time(NULL)) 4116f9291ceSJung-uk Kim break; 41274664626SKris Kennaway #ifdef WIN32_STUFF 41374664626SKris Kennaway 41474664626SKris Kennaway if (flushWinMsgs(0) == -1) 41574664626SKris Kennaway goto end; 41674664626SKris Kennaway 41774664626SKris Kennaway if (waitingToDie || exitNow) /* we're dead */ 41874664626SKris Kennaway goto end; 41974664626SKris Kennaway #endif 42074664626SKris Kennaway 42174664626SKris Kennaway if ((scon = doConnection(NULL)) == NULL) 42274664626SKris Kennaway goto end; 42374664626SKris Kennaway 4246f9291ceSJung-uk Kim if (s_www_path != NULL) { 4256f9291ceSJung-uk Kim BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", 4266f9291ceSJung-uk Kim s_www_path); 42774664626SKris Kennaway SSL_write(scon, buf, strlen(buf)); 42874664626SKris Kennaway while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) 42974664626SKris Kennaway bytes_read += i; 43074664626SKris Kennaway } 43174664626SKris Kennaway #ifdef NO_SHUTDOWN 43274664626SKris Kennaway SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); 43374664626SKris Kennaway #else 43474664626SKris Kennaway SSL_shutdown(scon); 43574664626SKris Kennaway #endif 43674664626SKris Kennaway SHUTDOWN2(SSL_get_fd(scon)); 43774664626SKris Kennaway 43874664626SKris Kennaway nConn += 1; 43974664626SKris Kennaway if (SSL_session_reused(scon)) 44074664626SKris Kennaway ver = 'r'; 4416f9291ceSJung-uk Kim else { 44274664626SKris Kennaway ver = SSL_version(scon); 44374664626SKris Kennaway if (ver == TLS1_VERSION) 44474664626SKris Kennaway ver = 't'; 44574664626SKris Kennaway else if (ver == SSL3_VERSION) 44674664626SKris Kennaway ver = '3'; 44774664626SKris Kennaway else if (ver == SSL2_VERSION) 44874664626SKris Kennaway ver = '2'; 44974664626SKris Kennaway else 45074664626SKris Kennaway ver = '*'; 45174664626SKris Kennaway } 45274664626SKris Kennaway fputc(ver, stdout); 45374664626SKris Kennaway fflush(stdout); 45474664626SKris Kennaway 45574664626SKris Kennaway SSL_free(scon); 45674664626SKris Kennaway scon = NULL; 45774664626SKris Kennaway } 45874664626SKris Kennaway totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ 45974664626SKris Kennaway 4605c87c606SMark Murray i = (int)((long)time(NULL) - finishtime + maxTime); 4616f9291ceSJung-uk Kim printf 4626f9291ceSJung-uk Kim ("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", 4636f9291ceSJung-uk Kim nConn, totalTime, ((double)nConn / totalTime), bytes_read); 4646f9291ceSJung-uk Kim printf 4656f9291ceSJung-uk Kim ("%d connections in %ld real seconds, %ld bytes read per connection\n", 4666f9291ceSJung-uk Kim nConn, (long)time(NULL) - finishtime + maxTime, bytes_read / nConn); 46774664626SKris Kennaway 4686f9291ceSJung-uk Kim /* 4696f9291ceSJung-uk Kim * Now loop and time connections using the same session id over and over 4706f9291ceSJung-uk Kim */ 47174664626SKris Kennaway 47274664626SKris Kennaway next: 4736f9291ceSJung-uk Kim if (!(perform & 2)) 4746f9291ceSJung-uk Kim goto end; 47574664626SKris Kennaway printf("\n\nNow timing with session id reuse.\n"); 47674664626SKris Kennaway 47774664626SKris Kennaway /* Get an SSL object so we can reuse the session id */ 4786f9291ceSJung-uk Kim if ((scon = doConnection(NULL)) == NULL) { 47974664626SKris Kennaway fprintf(stderr, "Unable to get connection\n"); 48074664626SKris Kennaway goto end; 48174664626SKris Kennaway } 48274664626SKris Kennaway 4836f9291ceSJung-uk Kim if (s_www_path != NULL) { 484ced566fdSJacques Vidrine BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", s_www_path); 48574664626SKris Kennaway SSL_write(scon, buf, strlen(buf)); 4866f9291ceSJung-uk Kim while (SSL_read(scon, buf, sizeof(buf)) > 0) ; 48774664626SKris Kennaway } 48874664626SKris Kennaway #ifdef NO_SHUTDOWN 48974664626SKris Kennaway SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); 49074664626SKris Kennaway #else 49174664626SKris Kennaway SSL_shutdown(scon); 49274664626SKris Kennaway #endif 49374664626SKris Kennaway SHUTDOWN2(SSL_get_fd(scon)); 49474664626SKris Kennaway 49574664626SKris Kennaway nConn = 0; 49674664626SKris Kennaway totalTime = 0.0; 49774664626SKris Kennaway 4985c87c606SMark Murray finishtime = (long)time(NULL) + maxTime; 49974664626SKris Kennaway 50074664626SKris Kennaway printf("starting\n"); 50174664626SKris Kennaway bytes_read = 0; 50274664626SKris Kennaway tm_Time_F(START); 50374664626SKris Kennaway 5046f9291ceSJung-uk Kim for (;;) { 5056f9291ceSJung-uk Kim if (finishtime < (long)time(NULL)) 5066f9291ceSJung-uk Kim break; 50774664626SKris Kennaway 50874664626SKris Kennaway #ifdef WIN32_STUFF 50974664626SKris Kennaway if (flushWinMsgs(0) == -1) 51074664626SKris Kennaway goto end; 51174664626SKris Kennaway 51274664626SKris Kennaway if (waitingToDie || exitNow) /* we're dead */ 51374664626SKris Kennaway goto end; 51474664626SKris Kennaway #endif 51574664626SKris Kennaway 51674664626SKris Kennaway if ((doConnection(scon)) == NULL) 51774664626SKris Kennaway goto end; 51874664626SKris Kennaway 5196f9291ceSJung-uk Kim if (s_www_path) { 5206f9291ceSJung-uk Kim BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", 5216f9291ceSJung-uk Kim s_www_path); 52274664626SKris Kennaway SSL_write(scon, buf, strlen(buf)); 52374664626SKris Kennaway while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) 52474664626SKris Kennaway bytes_read += i; 52574664626SKris Kennaway } 52674664626SKris Kennaway #ifdef NO_SHUTDOWN 52774664626SKris Kennaway SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); 52874664626SKris Kennaway #else 52974664626SKris Kennaway SSL_shutdown(scon); 53074664626SKris Kennaway #endif 53174664626SKris Kennaway SHUTDOWN2(SSL_get_fd(scon)); 53274664626SKris Kennaway 53374664626SKris Kennaway nConn += 1; 53474664626SKris Kennaway if (SSL_session_reused(scon)) 53574664626SKris Kennaway ver = 'r'; 5366f9291ceSJung-uk Kim else { 53774664626SKris Kennaway ver = SSL_version(scon); 53874664626SKris Kennaway if (ver == TLS1_VERSION) 53974664626SKris Kennaway ver = 't'; 54074664626SKris Kennaway else if (ver == SSL3_VERSION) 54174664626SKris Kennaway ver = '3'; 54274664626SKris Kennaway else if (ver == SSL2_VERSION) 54374664626SKris Kennaway ver = '2'; 54474664626SKris Kennaway else 54574664626SKris Kennaway ver = '*'; 54674664626SKris Kennaway } 54774664626SKris Kennaway fputc(ver, stdout); 54874664626SKris Kennaway fflush(stdout); 54974664626SKris Kennaway } 55074664626SKris Kennaway totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ 55174664626SKris Kennaway 5526f9291ceSJung-uk Kim printf 5536f9291ceSJung-uk Kim ("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", 5546f9291ceSJung-uk Kim nConn, totalTime, ((double)nConn / totalTime), bytes_read); 5556f9291ceSJung-uk Kim printf 5566f9291ceSJung-uk Kim ("%d connections in %ld real seconds, %ld bytes read per connection\n", 5576f9291ceSJung-uk Kim nConn, (long)time(NULL) - finishtime + maxTime, 5586f9291ceSJung-uk Kim bytes_read / (nConn?nConn:1)); 55974664626SKris Kennaway 56074664626SKris Kennaway ret = 0; 56174664626SKris Kennaway end: 5626f9291ceSJung-uk Kim if (scon != NULL) 5636f9291ceSJung-uk Kim SSL_free(scon); 56474664626SKris Kennaway 5656f9291ceSJung-uk Kim if (tm_ctx != NULL) { 56674664626SKris Kennaway SSL_CTX_free(tm_ctx); 56774664626SKris Kennaway tm_ctx = NULL; 56874664626SKris Kennaway } 5695c87c606SMark Murray apps_shutdown(); 5705c87c606SMark Murray OPENSSL_EXIT(ret); 57174664626SKris Kennaway } 57274664626SKris Kennaway 5736f9291ceSJung-uk Kim /*- 57474664626SKris Kennaway * doConnection - make a connection 57574664626SKris Kennaway * Args: 57674664626SKris Kennaway * scon = earlier ssl connection for session id, or NULL 57774664626SKris Kennaway * Returns: 57874664626SKris Kennaway * SSL * = the connection pointer. 57974664626SKris Kennaway */ 58074664626SKris Kennaway static SSL *doConnection(SSL *scon) 58174664626SKris Kennaway { 58274664626SKris Kennaway BIO *conn; 58374664626SKris Kennaway SSL *serverCon; 58474664626SKris Kennaway int width, i; 58574664626SKris Kennaway fd_set readfds; 58674664626SKris Kennaway 58774664626SKris Kennaway if ((conn = BIO_new(BIO_s_connect())) == NULL) 58874664626SKris Kennaway return (NULL); 58974664626SKris Kennaway 59074664626SKris Kennaway /* BIO_set_conn_port(conn,port);*/ 59174664626SKris Kennaway BIO_set_conn_hostname(conn, host); 59274664626SKris Kennaway 59374664626SKris Kennaway if (scon == NULL) 594f579bf8eSKris Kennaway serverCon = SSL_new(tm_ctx); 5956f9291ceSJung-uk Kim else { 59674664626SKris Kennaway serverCon = scon; 59774664626SKris Kennaway SSL_set_connect_state(serverCon); 59874664626SKris Kennaway } 59974664626SKris Kennaway 60074664626SKris Kennaway SSL_set_bio(serverCon, conn, conn); 60174664626SKris Kennaway 60274664626SKris Kennaway #if 0 60374664626SKris Kennaway if (scon != NULL) 60474664626SKris Kennaway SSL_set_session(serverCon, SSL_get_session(scon)); 60574664626SKris Kennaway #endif 60674664626SKris Kennaway 60774664626SKris Kennaway /* ok, lets connect */ 60874664626SKris Kennaway for (;;) { 60974664626SKris Kennaway i = SSL_connect(serverCon); 6106f9291ceSJung-uk Kim if (BIO_sock_should_retry(i)) { 61174664626SKris Kennaway BIO_printf(bio_err, "DELAY\n"); 61274664626SKris Kennaway 61374664626SKris Kennaway i = SSL_get_fd(serverCon); 61474664626SKris Kennaway width = i + 1; 61574664626SKris Kennaway FD_ZERO(&readfds); 6161f13597dSJung-uk Kim openssl_fdset(i, &readfds); 6176f9291ceSJung-uk Kim /* 6186f9291ceSJung-uk Kim * Note: under VMS with SOCKETSHR the 2nd parameter is currently 6196f9291ceSJung-uk Kim * of type (int *) whereas under other systems it is (void *) if 6206f9291ceSJung-uk Kim * you don't have a cast it will choke the compiler: if you do 6216f9291ceSJung-uk Kim * have a cast then you can either go for (int *) or (void *). 62274664626SKris Kennaway */ 62374664626SKris Kennaway select(width, (void *)&readfds, NULL, NULL, NULL); 62474664626SKris Kennaway continue; 62574664626SKris Kennaway } 62674664626SKris Kennaway break; 62774664626SKris Kennaway } 6286f9291ceSJung-uk Kim if (i <= 0) { 62974664626SKris Kennaway BIO_printf(bio_err, "ERROR\n"); 63074664626SKris Kennaway if (verify_error != X509_V_OK) 63174664626SKris Kennaway BIO_printf(bio_err, "verify error:%s\n", 63274664626SKris Kennaway X509_verify_cert_error_string(verify_error)); 63374664626SKris Kennaway else 63474664626SKris Kennaway ERR_print_errors(bio_err); 63574664626SKris Kennaway if (scon == NULL) 63674664626SKris Kennaway SSL_free(serverCon); 63774664626SKris Kennaway return NULL; 63874664626SKris Kennaway } 63974664626SKris Kennaway 64074664626SKris Kennaway return serverCon; 64174664626SKris Kennaway } 642