s_time.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /* apps/s_time.c */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. #define NO_SHUTDOWN
  59. /* ----------------------------------------
  60. s_time - SSL client connection timer program
  61. Written and donated by Larry Streepy <streepy@healthcare.com>
  62. -----------------------------------------*/
  63. #include <stdio.h>
  64. #include <stdlib.h>
  65. #include <string.h>
  66. #define USE_SOCKETS
  67. #include "apps.h"
  68. #ifdef OPENSSL_NO_STDIO
  69. # define APPS_WIN16
  70. #endif
  71. #include <openssl/x509.h>
  72. #include <openssl/ssl.h>
  73. #include <openssl/pem.h>
  74. #include "s_apps.h"
  75. #include <openssl/err.h>
  76. #ifdef WIN32_STUFF
  77. # include "winmain.h"
  78. # include "wintext.h"
  79. #endif
  80. #if !defined(OPENSSL_SYS_MSDOS)
  81. # include OPENSSL_UNISTD
  82. #endif
  83. #if !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
  84. # define TIMES
  85. #endif
  86. #ifndef _IRIX
  87. # include <time.h>
  88. #endif
  89. #ifdef TIMES
  90. # include <sys/types.h>
  91. # include <sys/times.h>
  92. #endif
  93. /*
  94. * Depending on the VMS version, the tms structure is perhaps defined. The
  95. * __TMS macro will show if it was. If it wasn't defined, we should undefine
  96. * TIMES, since that tells the rest of the program how things should be
  97. * handled. -- Richard Levitte
  98. */
  99. #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
  100. # undef TIMES
  101. #endif
  102. #if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
  103. # include <sys/timeb.h>
  104. #endif
  105. #if defined(sun) || defined(__ultrix)
  106. # define _POSIX_SOURCE
  107. # include <limits.h>
  108. # include <sys/param.h>
  109. #endif
  110. /*
  111. * The following if from times(3) man page. It may need to be changed
  112. */
  113. #ifndef HZ
  114. # ifdef _SC_CLK_TCK
  115. # define HZ ((double)sysconf(_SC_CLK_TCK))
  116. # else
  117. # ifndef CLK_TCK
  118. # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
  119. # define HZ 100.0
  120. # else /* _BSD_CLK_TCK_ */
  121. # define HZ ((double)_BSD_CLK_TCK_)
  122. # endif
  123. # else /* CLK_TCK */
  124. # define HZ ((double)CLK_TCK)
  125. # endif
  126. # endif
  127. #endif
  128. #undef PROG
  129. #define PROG s_time_main
  130. #undef ioctl
  131. #define ioctl ioctlsocket
  132. #define SSL_CONNECT_NAME "localhost:4433"
  133. /* no default cert. */
  134. /*
  135. * #define TEST_CERT "client.pem"
  136. */
  137. #undef BUFSIZZ
  138. #define BUFSIZZ 1024*10
  139. #define MYBUFSIZ 1024*8
  140. #undef min
  141. #undef max
  142. #define min(a,b) (((a) < (b)) ? (a) : (b))
  143. #define max(a,b) (((a) > (b)) ? (a) : (b))
  144. #undef SECONDS
  145. #define SECONDS 30
  146. extern int verify_depth;
  147. extern int verify_error;
  148. static void s_time_usage(void);
  149. static int parseArgs(int argc, char **argv);
  150. static SSL *doConnection(SSL *scon);
  151. static void s_time_init(void);
  152. /***********************************************************************
  153. * Static data declarations
  154. */
  155. /* static char *port=PORT_STR;*/
  156. static char *host = SSL_CONNECT_NAME;
  157. static char *t_cert_file = NULL;
  158. static char *t_key_file = NULL;
  159. static char *CApath = NULL;
  160. static char *CAfile = NULL;
  161. static char *tm_cipher = NULL;
  162. static int tm_verify = SSL_VERIFY_NONE;
  163. static int maxTime = SECONDS;
  164. static SSL_CTX *tm_ctx = NULL;
  165. static SSL_METHOD *s_time_meth = NULL;
  166. static char *s_www_path = NULL;
  167. static long bytes_read = 0;
  168. static int st_bugs = 0;
  169. static int perform = 0;
  170. #ifdef FIONBIO
  171. static int t_nbio = 0;
  172. #endif
  173. #ifdef OPENSSL_SYS_WIN32
  174. static int exitNow = 0; /* Set when it's time to exit main */
  175. #endif
  176. static void s_time_init(void)
  177. {
  178. host = SSL_CONNECT_NAME;
  179. t_cert_file = NULL;
  180. t_key_file = NULL;
  181. CApath = NULL;
  182. CAfile = NULL;
  183. tm_cipher = NULL;
  184. tm_verify = SSL_VERIFY_NONE;
  185. maxTime = SECONDS;
  186. tm_ctx = NULL;
  187. s_time_meth = NULL;
  188. s_www_path = NULL;
  189. bytes_read = 0;
  190. st_bugs = 0;
  191. perform = 0;
  192. #ifdef FIONBIO
  193. t_nbio = 0;
  194. #endif
  195. #ifdef OPENSSL_SYS_WIN32
  196. exitNow = 0; /* Set when it's time to exit main */
  197. #endif
  198. }
  199. /***********************************************************************
  200. * usage - display usage message
  201. */
  202. static void s_time_usage(void)
  203. {
  204. static char umsg[] = "\
  205. -time arg - max number of seconds to collect data, default %d\n\
  206. -verify arg - turn on peer certificate verification, arg == depth\n\
  207. -cert arg - certificate file to use, PEM format assumed\n\
  208. -key arg - RSA file to use, PEM format assumed, key is in cert file\n\
  209. file if not specified by this option\n\
  210. -CApath arg - PEM format directory of CA's\n\
  211. -CAfile arg - PEM format file of CA's\n\
  212. -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
  213. printf("usage: s_time <args>\n\n");
  214. printf("-connect host:port - host:port to connect to (default is %s)\n",
  215. SSL_CONNECT_NAME);
  216. #ifdef FIONBIO
  217. printf("-nbio - Run with non-blocking IO\n");
  218. printf("-ssl2 - Just use SSLv2\n");
  219. printf("-ssl3 - Just use SSLv3\n");
  220. printf("-bugs - Turn on SSL bug compatibility\n");
  221. printf("-new - Just time new connections\n");
  222. printf("-reuse - Just time connection reuse\n");
  223. printf("-www page - Retrieve 'page' from the site\n");
  224. #endif
  225. printf(umsg, SECONDS);
  226. }
  227. /***********************************************************************
  228. * parseArgs - Parse command line arguments and initialize data
  229. *
  230. * Returns 0 if ok, -1 on bad args
  231. */
  232. static int parseArgs(int argc, char **argv)
  233. {
  234. int badop = 0;
  235. verify_depth = 0;
  236. verify_error = X509_V_OK;
  237. argc--;
  238. argv++;
  239. while (argc >= 1) {
  240. if (strcmp(*argv, "-connect") == 0) {
  241. if (--argc < 1)
  242. goto bad;
  243. host = *(++argv);
  244. }
  245. #if 0
  246. else if (strcmp(*argv, "-host") == 0) {
  247. if (--argc < 1)
  248. goto bad;
  249. host = *(++argv);
  250. } else if (strcmp(*argv, "-port") == 0) {
  251. if (--argc < 1)
  252. goto bad;
  253. port = *(++argv);
  254. }
  255. #endif
  256. else if (strcmp(*argv, "-reuse") == 0)
  257. perform = 2;
  258. else if (strcmp(*argv, "-new") == 0)
  259. perform = 1;
  260. else if (strcmp(*argv, "-verify") == 0) {
  261. tm_verify = SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;
  262. if (--argc < 1)
  263. goto bad;
  264. verify_depth = atoi(*(++argv));
  265. BIO_printf(bio_err, "verify depth is %d\n", verify_depth);
  266. } else if (strcmp(*argv, "-cert") == 0) {
  267. if (--argc < 1)
  268. goto bad;
  269. t_cert_file = *(++argv);
  270. } else if (strcmp(*argv, "-key") == 0) {
  271. if (--argc < 1)
  272. goto bad;
  273. t_key_file = *(++argv);
  274. } else if (strcmp(*argv, "-CApath") == 0) {
  275. if (--argc < 1)
  276. goto bad;
  277. CApath = *(++argv);
  278. } else if (strcmp(*argv, "-CAfile") == 0) {
  279. if (--argc < 1)
  280. goto bad;
  281. CAfile = *(++argv);
  282. } else if (strcmp(*argv, "-cipher") == 0) {
  283. if (--argc < 1)
  284. goto bad;
  285. tm_cipher = *(++argv);
  286. }
  287. #ifdef FIONBIO
  288. else if (strcmp(*argv, "-nbio") == 0) {
  289. t_nbio = 1;
  290. }
  291. #endif
  292. else if (strcmp(*argv, "-www") == 0) {
  293. if (--argc < 1)
  294. goto bad;
  295. s_www_path = *(++argv);
  296. if (strlen(s_www_path) > MYBUFSIZ - 100) {
  297. BIO_printf(bio_err, "-www option too long\n");
  298. badop = 1;
  299. }
  300. } else if (strcmp(*argv, "-bugs") == 0)
  301. st_bugs = 1;
  302. #ifndef OPENSSL_NO_SSL2
  303. else if (strcmp(*argv, "-ssl2") == 0)
  304. s_time_meth = SSLv2_client_method();
  305. #endif
  306. #ifndef OPENSSL_NO_SSL3
  307. else if (strcmp(*argv, "-ssl3") == 0)
  308. s_time_meth = SSLv3_client_method();
  309. #endif
  310. else if (strcmp(*argv, "-time") == 0) {
  311. if (--argc < 1)
  312. goto bad;
  313. maxTime = atoi(*(++argv));
  314. } else {
  315. BIO_printf(bio_err, "unknown option %s\n", *argv);
  316. badop = 1;
  317. break;
  318. }
  319. argc--;
  320. argv++;
  321. }
  322. if (perform == 0)
  323. perform = 3;
  324. if (badop) {
  325. bad:
  326. s_time_usage();
  327. return -1;
  328. }
  329. return 0; /* Valid args */
  330. }
  331. /***********************************************************************
  332. * TIME - time functions
  333. */
  334. #define START 0
  335. #define STOP 1
  336. static double tm_Time_F(int s)
  337. {
  338. static double ret;
  339. #ifdef TIMES
  340. static struct tms tstart, tend;
  341. if (s == START) {
  342. times(&tstart);
  343. return (0);
  344. } else {
  345. times(&tend);
  346. ret = ((double)(tend.tms_utime - tstart.tms_utime)) / HZ;
  347. return ((ret == 0.0) ? 1e-6 : ret);
  348. }
  349. #elif defined(OPENSSL_SYS_NETWARE)
  350. static clock_t tstart, tend;
  351. if (s == START) {
  352. tstart = clock();
  353. return (0);
  354. } else {
  355. tend = clock();
  356. ret = (double)((double)(tend) - (double)(tstart));
  357. return ((ret < 0.001) ? 0.001 : ret);
  358. }
  359. #elif defined(OPENSSL_SYS_VXWORKS)
  360. {
  361. static unsigned long tick_start, tick_end;
  362. if (s == START) {
  363. tick_start = tickGet();
  364. return 0;
  365. } else {
  366. tick_end = tickGet();
  367. ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
  368. return ((ret == 0.0) ? 1e-6 : ret);
  369. }
  370. }
  371. #else /* !times() */
  372. static struct timeb tstart, tend;
  373. long i;
  374. if (s == START) {
  375. ftime(&tstart);
  376. return (0);
  377. } else {
  378. ftime(&tend);
  379. i = (long)tend.millitm - (long)tstart.millitm;
  380. ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1000.0;
  381. return ((ret == 0.0) ? 1e-6 : ret);
  382. }
  383. #endif
  384. }
  385. /***********************************************************************
  386. * MAIN - main processing area for client
  387. * real name depends on MONOLITH
  388. */
  389. int MAIN(int, char **);
  390. int MAIN(int argc, char **argv)
  391. {
  392. double totalTime = 0.0;
  393. int nConn = 0;
  394. SSL *scon = NULL;
  395. long finishtime = 0;
  396. int ret = 1, i;
  397. MS_STATIC char buf[1024 * 8];
  398. int ver;
  399. apps_startup();
  400. s_time_init();
  401. if (bio_err == NULL)
  402. bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
  403. #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
  404. s_time_meth = SSLv23_client_method();
  405. #elif !defined(OPENSSL_NO_SSL3)
  406. s_time_meth = SSLv3_client_method();
  407. #elif !defined(OPENSSL_NO_SSL2)
  408. s_time_meth = SSLv2_client_method();
  409. #endif
  410. /* parse the command line arguments */
  411. if (parseArgs(argc, argv) < 0)
  412. goto end;
  413. OpenSSL_add_ssl_algorithms();
  414. if ((tm_ctx = SSL_CTX_new(s_time_meth)) == NULL)
  415. return (1);
  416. SSL_CTX_set_quiet_shutdown(tm_ctx, 1);
  417. if (st_bugs)
  418. SSL_CTX_set_options(tm_ctx, SSL_OP_ALL);
  419. SSL_CTX_set_cipher_list(tm_ctx, tm_cipher);
  420. if (!set_cert_stuff(tm_ctx, t_cert_file, t_key_file))
  421. goto end;
  422. SSL_load_error_strings();
  423. if ((!SSL_CTX_load_verify_locations(tm_ctx, CAfile, CApath)) ||
  424. (!SSL_CTX_set_default_verify_paths(tm_ctx))) {
  425. /*
  426. * BIO_printf(bio_err,"error setting default verify locations\n");
  427. */
  428. ERR_print_errors(bio_err);
  429. /* goto end; */
  430. }
  431. if (tm_cipher == NULL)
  432. tm_cipher = getenv("SSL_CIPHER");
  433. if (tm_cipher == NULL) {
  434. fprintf(stderr, "No CIPHER specified\n");
  435. }
  436. if (!(perform & 1))
  437. goto next;
  438. printf("Collecting connection statistics for %d seconds\n", maxTime);
  439. /* Loop and time how long it takes to make connections */
  440. bytes_read = 0;
  441. finishtime = (long)time(NULL) + maxTime;
  442. tm_Time_F(START);
  443. for (;;) {
  444. if (finishtime < (long)time(NULL))
  445. break;
  446. #ifdef WIN32_STUFF
  447. if (flushWinMsgs(0) == -1)
  448. goto end;
  449. if (waitingToDie || exitNow) /* we're dead */
  450. goto end;
  451. #endif
  452. if ((scon = doConnection(NULL)) == NULL)
  453. goto end;
  454. if (s_www_path != NULL) {
  455. BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n",
  456. s_www_path);
  457. SSL_write(scon, buf, strlen(buf));
  458. while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)
  459. bytes_read += i;
  460. }
  461. #ifdef NO_SHUTDOWN
  462. SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
  463. #else
  464. SSL_shutdown(scon);
  465. #endif
  466. SHUTDOWN2(SSL_get_fd(scon));
  467. nConn += 1;
  468. if (SSL_session_reused(scon))
  469. ver = 'r';
  470. else {
  471. ver = SSL_version(scon);
  472. if (ver == TLS1_VERSION)
  473. ver = 't';
  474. else if (ver == SSL3_VERSION)
  475. ver = '3';
  476. else if (ver == SSL2_VERSION)
  477. ver = '2';
  478. else
  479. ver = '*';
  480. }
  481. fputc(ver, stdout);
  482. fflush(stdout);
  483. SSL_free(scon);
  484. scon = NULL;
  485. }
  486. totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
  487. i = (int)((long)time(NULL) - finishtime + maxTime);
  488. printf
  489. ("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n",
  490. nConn, totalTime, ((double)nConn / totalTime), bytes_read);
  491. printf
  492. ("%d connections in %ld real seconds, %ld bytes read per connection\n",
  493. nConn, (long)time(NULL) - finishtime + maxTime, bytes_read / nConn);
  494. /*
  495. * Now loop and time connections using the same session id over and over
  496. */
  497. next:
  498. if (!(perform & 2))
  499. goto end;
  500. printf("\n\nNow timing with session id reuse.\n");
  501. /* Get an SSL object so we can reuse the session id */
  502. if ((scon = doConnection(NULL)) == NULL) {
  503. fprintf(stderr, "Unable to get connection\n");
  504. goto end;
  505. }
  506. if (s_www_path != NULL) {
  507. BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n", s_www_path);
  508. SSL_write(scon, buf, strlen(buf));
  509. while (SSL_read(scon, buf, sizeof(buf)) > 0) ;
  510. }
  511. #ifdef NO_SHUTDOWN
  512. SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
  513. #else
  514. SSL_shutdown(scon);
  515. #endif
  516. SHUTDOWN2(SSL_get_fd(scon));
  517. nConn = 0;
  518. totalTime = 0.0;
  519. finishtime = (long)time(NULL) + maxTime;
  520. printf("starting\n");
  521. bytes_read = 0;
  522. tm_Time_F(START);
  523. for (;;) {
  524. if (finishtime < (long)time(NULL))
  525. break;
  526. #ifdef WIN32_STUFF
  527. if (flushWinMsgs(0) == -1)
  528. goto end;
  529. if (waitingToDie || exitNow) /* we're dead */
  530. goto end;
  531. #endif
  532. if ((doConnection(scon)) == NULL)
  533. goto end;
  534. if (s_www_path) {
  535. BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\r\n\r\n",
  536. s_www_path);
  537. SSL_write(scon, buf, strlen(buf));
  538. while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)
  539. bytes_read += i;
  540. }
  541. #ifdef NO_SHUTDOWN
  542. SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
  543. #else
  544. SSL_shutdown(scon);
  545. #endif
  546. SHUTDOWN2(SSL_get_fd(scon));
  547. nConn += 1;
  548. if (SSL_session_reused(scon))
  549. ver = 'r';
  550. else {
  551. ver = SSL_version(scon);
  552. if (ver == TLS1_VERSION)
  553. ver = 't';
  554. else if (ver == SSL3_VERSION)
  555. ver = '3';
  556. else if (ver == SSL2_VERSION)
  557. ver = '2';
  558. else
  559. ver = '*';
  560. }
  561. fputc(ver, stdout);
  562. fflush(stdout);
  563. }
  564. totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
  565. printf
  566. ("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n",
  567. nConn, totalTime, ((double)nConn / totalTime), bytes_read);
  568. printf
  569. ("%d connections in %ld real seconds, %ld bytes read per connection\n",
  570. nConn, (long)time(NULL) - finishtime + maxTime, bytes_read / nConn);
  571. ret = 0;
  572. end:
  573. if (scon != NULL)
  574. SSL_free(scon);
  575. if (tm_ctx != NULL) {
  576. SSL_CTX_free(tm_ctx);
  577. tm_ctx = NULL;
  578. }
  579. apps_shutdown();
  580. OPENSSL_EXIT(ret);
  581. }
  582. /*-
  583. * doConnection - make a connection
  584. * Args:
  585. * scon = earlier ssl connection for session id, or NULL
  586. * Returns:
  587. * SSL * = the connection pointer.
  588. */
  589. static SSL *doConnection(SSL *scon)
  590. {
  591. BIO *conn;
  592. SSL *serverCon;
  593. int width, i;
  594. fd_set readfds;
  595. if ((conn = BIO_new(BIO_s_connect())) == NULL)
  596. return (NULL);
  597. /* BIO_set_conn_port(conn,port);*/
  598. BIO_set_conn_hostname(conn, host);
  599. if (scon == NULL)
  600. serverCon = SSL_new(tm_ctx);
  601. else {
  602. serverCon = scon;
  603. SSL_set_connect_state(serverCon);
  604. }
  605. SSL_set_bio(serverCon, conn, conn);
  606. #if 0
  607. if (scon != NULL)
  608. SSL_set_session(serverCon, SSL_get_session(scon));
  609. #endif
  610. /* ok, lets connect */
  611. for (;;) {
  612. i = SSL_connect(serverCon);
  613. if (BIO_sock_should_retry(i)) {
  614. BIO_printf(bio_err, "DELAY\n");
  615. i = SSL_get_fd(serverCon);
  616. width = i + 1;
  617. FD_ZERO(&readfds);
  618. FD_SET(i, &readfds);
  619. /*
  620. * Note: under VMS with SOCKETSHR the 2nd parameter is currently
  621. * of type (int *) whereas under other systems it is (void *) if
  622. * you don't have a cast it will choke the compiler: if you do
  623. * have a cast then you can either go for (int *) or (void *).
  624. */
  625. select(width, (void *)&readfds, NULL, NULL, NULL);
  626. continue;
  627. }
  628. break;
  629. }
  630. if (i <= 0) {
  631. BIO_printf(bio_err, "ERROR\n");
  632. if (verify_error != X509_V_OK)
  633. BIO_printf(bio_err, "verify error:%s\n",
  634. X509_verify_cert_error_string(verify_error));
  635. else
  636. ERR_print_errors(bio_err);
  637. if (scon == NULL)
  638. SSL_free(serverCon);
  639. return NULL;
  640. }
  641. return serverCon;
  642. }