s_time.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  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. #ifdef OPENSSL_NO_STDIO
  67. #define APPS_WIN16
  68. #endif
  69. #define USE_SOCKETS
  70. #include <openssl/x509.h>
  71. #include <openssl/ssl.h>
  72. #include <openssl/pem.h>
  73. #include "apps.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) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
  81. #define TIMES
  82. #endif
  83. #ifndef _IRIX
  84. #include <time.h>
  85. #endif
  86. #ifdef TIMES
  87. #include <sys/types.h>
  88. #include <sys/times.h>
  89. #endif
  90. /* Depending on the VMS version, the tms structure is perhaps defined.
  91. The __TMS macro will show if it was. If it wasn't defined, we should
  92. undefine TIMES, since that tells the rest of the program how things
  93. should be handled. -- Richard Levitte */
  94. #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
  95. #undef TIMES
  96. #endif
  97. #ifndef TIMES
  98. #include <sys/timeb.h>
  99. #endif
  100. #ifdef _AIX
  101. #include <sys/select.h>
  102. #endif
  103. #if defined(sun) || defined(__ultrix)
  104. #define _POSIX_SOURCE
  105. #include <limits.h>
  106. #include <sys/param.h>
  107. #endif
  108. /* The following if from times(3) man page. It may need to be changed
  109. */
  110. #ifndef HZ
  111. #ifndef CLK_TCK
  112. #define HZ 100.0
  113. #else /* CLK_TCK */
  114. #define HZ ((double)CLK_TCK)
  115. #endif
  116. #endif
  117. #undef PROG
  118. #define PROG s_time_main
  119. #undef ioctl
  120. #define ioctl ioctlsocket
  121. #define SSL_CONNECT_NAME "localhost:4433"
  122. /*#define TEST_CERT "client.pem" */ /* no default cert. */
  123. #undef BUFSIZZ
  124. #define BUFSIZZ 1024*10
  125. #define min(a,b) (((a) < (b)) ? (a) : (b))
  126. #define max(a,b) (((a) > (b)) ? (a) : (b))
  127. #undef SECONDS
  128. #define SECONDS 30
  129. extern int verify_depth;
  130. extern int verify_error;
  131. static void s_time_usage(void);
  132. static int parseArgs( int argc, char **argv );
  133. static SSL *doConnection( SSL *scon );
  134. static void s_time_init(void);
  135. /***********************************************************************
  136. * Static data declarations
  137. */
  138. /* static char *port=PORT_STR;*/
  139. static char *host=SSL_CONNECT_NAME;
  140. static char *t_cert_file=NULL;
  141. static char *t_key_file=NULL;
  142. static char *CApath=NULL;
  143. static char *CAfile=NULL;
  144. static char *tm_cipher=NULL;
  145. static int tm_verify = SSL_VERIFY_NONE;
  146. static int maxTime = SECONDS;
  147. static SSL_CTX *tm_ctx=NULL;
  148. static SSL_METHOD *s_time_meth=NULL;
  149. static char *s_www_path=NULL;
  150. static long bytes_read=0;
  151. static int st_bugs=0;
  152. static int perform=0;
  153. #ifdef FIONBIO
  154. static int t_nbio=0;
  155. #endif
  156. #ifdef OPENSSL_SYS_WIN32
  157. static int exitNow = 0; /* Set when it's time to exit main */
  158. #endif
  159. static void s_time_init(void)
  160. {
  161. host=SSL_CONNECT_NAME;
  162. t_cert_file=NULL;
  163. t_key_file=NULL;
  164. CApath=NULL;
  165. CAfile=NULL;
  166. tm_cipher=NULL;
  167. tm_verify = SSL_VERIFY_NONE;
  168. maxTime = SECONDS;
  169. tm_ctx=NULL;
  170. s_time_meth=NULL;
  171. s_www_path=NULL;
  172. bytes_read=0;
  173. st_bugs=0;
  174. perform=0;
  175. #ifdef FIONBIO
  176. t_nbio=0;
  177. #endif
  178. #ifdef OPENSSL_SYS_WIN32
  179. exitNow = 0; /* Set when it's time to exit main */
  180. #endif
  181. }
  182. /***********************************************************************
  183. * usage - display usage message
  184. */
  185. static void s_time_usage(void)
  186. {
  187. static char umsg[] = "\
  188. -time arg - max number of seconds to collect data, default %d\n\
  189. -verify arg - turn on peer certificate verification, arg == depth\n\
  190. -cert arg - certificate file to use, PEM format assumed\n\
  191. -key arg - RSA file to use, PEM format assumed, key is in cert file\n\
  192. file if not specified by this option\n\
  193. -CApath arg - PEM format directory of CA's\n\
  194. -CAfile arg - PEM format file of CA's\n\
  195. -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n";
  196. printf( "usage: s_time <args>\n\n" );
  197. printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME);
  198. #ifdef FIONBIO
  199. printf("-nbio - Run with non-blocking IO\n");
  200. printf("-ssl2 - Just use SSLv2\n");
  201. printf("-ssl3 - Just use SSLv3\n");
  202. printf("-bugs - Turn on SSL bug compatibility\n");
  203. printf("-new - Just time new connections\n");
  204. printf("-reuse - Just time connection reuse\n");
  205. printf("-www page - Retrieve 'page' from the site\n");
  206. #endif
  207. printf( umsg,SECONDS );
  208. }
  209. /***********************************************************************
  210. * parseArgs - Parse command line arguments and initialize data
  211. *
  212. * Returns 0 if ok, -1 on bad args
  213. */
  214. static int parseArgs(int argc, char **argv)
  215. {
  216. int badop = 0;
  217. verify_depth=0;
  218. verify_error=X509_V_OK;
  219. argc--;
  220. argv++;
  221. while (argc >= 1) {
  222. if (strcmp(*argv,"-connect") == 0)
  223. {
  224. if (--argc < 1) goto bad;
  225. host= *(++argv);
  226. }
  227. #if 0
  228. else if( strcmp(*argv,"-host") == 0)
  229. {
  230. if (--argc < 1) goto bad;
  231. host= *(++argv);
  232. }
  233. else if( strcmp(*argv,"-port") == 0)
  234. {
  235. if (--argc < 1) goto bad;
  236. port= *(++argv);
  237. }
  238. #endif
  239. else if (strcmp(*argv,"-reuse") == 0)
  240. perform=2;
  241. else if (strcmp(*argv,"-new") == 0)
  242. perform=1;
  243. else if( strcmp(*argv,"-verify") == 0) {
  244. tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
  245. if (--argc < 1) goto bad;
  246. verify_depth=atoi(*(++argv));
  247. BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
  248. } else if( strcmp(*argv,"-cert") == 0) {
  249. if (--argc < 1) goto bad;
  250. t_cert_file= *(++argv);
  251. } else if( strcmp(*argv,"-key") == 0) {
  252. if (--argc < 1) goto bad;
  253. t_key_file= *(++argv);
  254. } else if( strcmp(*argv,"-CApath") == 0) {
  255. if (--argc < 1) goto bad;
  256. CApath= *(++argv);
  257. } else if( strcmp(*argv,"-CAfile") == 0) {
  258. if (--argc < 1) goto bad;
  259. CAfile= *(++argv);
  260. } else if( strcmp(*argv,"-cipher") == 0) {
  261. if (--argc < 1) goto bad;
  262. tm_cipher= *(++argv);
  263. }
  264. #ifdef FIONBIO
  265. else if(strcmp(*argv,"-nbio") == 0) {
  266. t_nbio=1;
  267. }
  268. #endif
  269. else if(strcmp(*argv,"-www") == 0)
  270. {
  271. if (--argc < 1) goto bad;
  272. s_www_path= *(++argv);
  273. }
  274. else if(strcmp(*argv,"-bugs") == 0)
  275. st_bugs=1;
  276. #ifndef OPENSSL_NO_SSL2
  277. else if(strcmp(*argv,"-ssl2") == 0)
  278. s_time_meth=SSLv2_client_method();
  279. #endif
  280. #ifndef OPENSSL_NO_SSL3
  281. else if(strcmp(*argv,"-ssl3") == 0)
  282. s_time_meth=SSLv3_client_method();
  283. #endif
  284. else if( strcmp(*argv,"-time") == 0) {
  285. if (--argc < 1) goto bad;
  286. maxTime= atoi(*(++argv));
  287. }
  288. else {
  289. BIO_printf(bio_err,"unknown option %s\n",*argv);
  290. badop=1;
  291. break;
  292. }
  293. argc--;
  294. argv++;
  295. }
  296. if (perform == 0) perform=3;
  297. if(badop) {
  298. bad:
  299. s_time_usage();
  300. return -1;
  301. }
  302. return 0; /* Valid args */
  303. }
  304. /***********************************************************************
  305. * TIME - time functions
  306. */
  307. #define START 0
  308. #define STOP 1
  309. static double tm_Time_F(int s)
  310. {
  311. static double ret;
  312. #ifdef TIMES
  313. static struct tms tstart,tend;
  314. if(s == START) {
  315. times(&tstart);
  316. return(0);
  317. } else {
  318. times(&tend);
  319. ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  320. return((ret == 0.0)?1e-6:ret);
  321. }
  322. #else /* !times() */
  323. static struct timeb tstart,tend;
  324. long i;
  325. if(s == START) {
  326. ftime(&tstart);
  327. return(0);
  328. } else {
  329. ftime(&tend);
  330. i=(long)tend.millitm-(long)tstart.millitm;
  331. ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
  332. return((ret == 0.0)?1e-6:ret);
  333. }
  334. #endif
  335. }
  336. /***********************************************************************
  337. * MAIN - main processing area for client
  338. * real name depends on MONOLITH
  339. */
  340. int MAIN(int, char **);
  341. int MAIN(int argc, char **argv)
  342. {
  343. double totalTime = 0.0;
  344. int nConn = 0;
  345. SSL *scon=NULL;
  346. long finishtime=0;
  347. int ret=1,i;
  348. MS_STATIC char buf[1024*8];
  349. int ver;
  350. apps_startup();
  351. s_time_init();
  352. if (bio_err == NULL)
  353. bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
  354. #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
  355. s_time_meth=SSLv23_client_method();
  356. #elif !defined(OPENSSL_NO_SSL3)
  357. s_time_meth=SSLv3_client_method();
  358. #elif !defined(OPENSSL_NO_SSL2)
  359. s_time_meth=SSLv2_client_method();
  360. #endif
  361. /* parse the command line arguments */
  362. if( parseArgs( argc, argv ) < 0 )
  363. goto end;
  364. OpenSSL_add_ssl_algorithms();
  365. if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);
  366. SSL_CTX_set_quiet_shutdown(tm_ctx,1);
  367. if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);
  368. SSL_CTX_set_cipher_list(tm_ctx,tm_cipher);
  369. if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))
  370. goto end;
  371. SSL_load_error_strings();
  372. if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||
  373. (!SSL_CTX_set_default_verify_paths(tm_ctx)))
  374. {
  375. /* BIO_printf(bio_err,"error setting default verify locations\n"); */
  376. ERR_print_errors(bio_err);
  377. /* goto end; */
  378. }
  379. if (tm_cipher == NULL)
  380. tm_cipher = getenv("SSL_CIPHER");
  381. if (tm_cipher == NULL ) {
  382. fprintf( stderr, "No CIPHER specified\n" );
  383. /* EXIT(1); */
  384. }
  385. if (!(perform & 1)) goto next;
  386. printf( "Collecting connection statistics for %d seconds\n", maxTime );
  387. /* Loop and time how long it takes to make connections */
  388. bytes_read=0;
  389. finishtime=(long)time(NULL)+maxTime;
  390. tm_Time_F(START);
  391. for (;;)
  392. {
  393. if (finishtime < time(NULL)) break;
  394. #ifdef WIN32_STUFF
  395. if( flushWinMsgs(0) == -1 )
  396. goto end;
  397. if( waitingToDie || exitNow ) /* we're dead */
  398. goto end;
  399. #endif
  400. if( (scon = doConnection( NULL )) == NULL )
  401. goto end;
  402. if (s_www_path != NULL)
  403. {
  404. sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
  405. SSL_write(scon,buf,strlen(buf));
  406. while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
  407. bytes_read+=i;
  408. }
  409. #ifdef NO_SHUTDOWN
  410. SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
  411. #else
  412. SSL_shutdown(scon);
  413. #endif
  414. SHUTDOWN2(SSL_get_fd(scon));
  415. nConn += 1;
  416. if (SSL_session_reused(scon))
  417. ver='r';
  418. else
  419. {
  420. ver=SSL_version(scon);
  421. if (ver == TLS1_VERSION)
  422. ver='t';
  423. else if (ver == SSL3_VERSION)
  424. ver='3';
  425. else if (ver == SSL2_VERSION)
  426. ver='2';
  427. else
  428. ver='*';
  429. }
  430. fputc(ver,stdout);
  431. fflush(stdout);
  432. SSL_free( scon );
  433. scon=NULL;
  434. }
  435. totalTime += tm_Time_F(STOP); /* Add the time for this iteration */
  436. i=(int)(time(NULL)-finishtime+maxTime);
  437. printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
  438. printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
  439. /* Now loop and time connections using the same session id over and over */
  440. next:
  441. if (!(perform & 2)) goto end;
  442. printf( "\n\nNow timing with session id reuse.\n" );
  443. /* Get an SSL object so we can reuse the session id */
  444. if( (scon = doConnection( NULL )) == NULL )
  445. {
  446. fprintf( stderr, "Unable to get connection\n" );
  447. goto end;
  448. }
  449. if (s_www_path != NULL)
  450. {
  451. sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
  452. SSL_write(scon,buf,strlen(buf));
  453. while (SSL_read(scon,buf,sizeof(buf)) > 0)
  454. ;
  455. }
  456. #ifdef NO_SHUTDOWN
  457. SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
  458. #else
  459. SSL_shutdown(scon);
  460. #endif
  461. SHUTDOWN2(SSL_get_fd(scon));
  462. nConn = 0;
  463. totalTime = 0.0;
  464. finishtime=time(NULL)+maxTime;
  465. printf( "starting\n" );
  466. bytes_read=0;
  467. tm_Time_F(START);
  468. for (;;)
  469. {
  470. if (finishtime < time(NULL)) break;
  471. #ifdef WIN32_STUFF
  472. if( flushWinMsgs(0) == -1 )
  473. goto end;
  474. if( waitingToDie || exitNow ) /* we're dead */
  475. goto end;
  476. #endif
  477. if( (doConnection( scon )) == NULL )
  478. goto end;
  479. if (s_www_path)
  480. {
  481. sprintf(buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path);
  482. SSL_write(scon,buf,strlen(buf));
  483. while ((i=SSL_read(scon,buf,sizeof(buf))) > 0)
  484. bytes_read+=i;
  485. }
  486. #ifdef NO_SHUTDOWN
  487. SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
  488. #else
  489. SSL_shutdown(scon);
  490. #endif
  491. SHUTDOWN2(SSL_get_fd(scon));
  492. nConn += 1;
  493. if (SSL_session_reused(scon))
  494. ver='r';
  495. else
  496. {
  497. ver=SSL_version(scon);
  498. if (ver == TLS1_VERSION)
  499. ver='t';
  500. else if (ver == SSL3_VERSION)
  501. ver='3';
  502. else if (ver == SSL2_VERSION)
  503. ver='2';
  504. else
  505. ver='*';
  506. }
  507. fputc(ver,stdout);
  508. fflush(stdout);
  509. }
  510. totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/
  511. printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);
  512. printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);
  513. ret=0;
  514. end:
  515. if (scon != NULL) SSL_free(scon);
  516. if (tm_ctx != NULL)
  517. {
  518. SSL_CTX_free(tm_ctx);
  519. tm_ctx=NULL;
  520. }
  521. EXIT(ret);
  522. }
  523. /***********************************************************************
  524. * doConnection - make a connection
  525. * Args:
  526. * scon = earlier ssl connection for session id, or NULL
  527. * Returns:
  528. * SSL * = the connection pointer.
  529. */
  530. static SSL *doConnection(SSL *scon)
  531. {
  532. BIO *conn;
  533. SSL *serverCon;
  534. int width, i;
  535. fd_set readfds;
  536. if ((conn=BIO_new(BIO_s_connect())) == NULL)
  537. return(NULL);
  538. /* BIO_set_conn_port(conn,port);*/
  539. BIO_set_conn_hostname(conn,host);
  540. if (scon == NULL)
  541. serverCon=SSL_new(tm_ctx);
  542. else
  543. {
  544. serverCon=scon;
  545. SSL_set_connect_state(serverCon);
  546. }
  547. SSL_set_bio(serverCon,conn,conn);
  548. #if 0
  549. if( scon != NULL )
  550. SSL_set_session(serverCon,SSL_get_session(scon));
  551. #endif
  552. /* ok, lets connect */
  553. for(;;) {
  554. i=SSL_connect(serverCon);
  555. if (BIO_sock_should_retry(i))
  556. {
  557. BIO_printf(bio_err,"DELAY\n");
  558. i=SSL_get_fd(serverCon);
  559. width=i+1;
  560. FD_ZERO(&readfds);
  561. FD_SET(i,&readfds);
  562. /* Note: under VMS with SOCKETSHR the 2nd parameter
  563. * is currently of type (int *) whereas under other
  564. * systems it is (void *) if you don't have a cast it
  565. * will choke the compiler: if you do have a cast then
  566. * you can either go for (int *) or (void *).
  567. */
  568. select(width,(void *)&readfds,NULL,NULL,NULL);
  569. continue;
  570. }
  571. break;
  572. }
  573. if(i <= 0)
  574. {
  575. BIO_printf(bio_err,"ERROR\n");
  576. if (verify_error != X509_V_OK)
  577. BIO_printf(bio_err,"verify error:%s\n",
  578. X509_verify_cert_error_string(verify_error));
  579. else
  580. ERR_print_errors(bio_err);
  581. if (scon == NULL)
  582. SSL_free(serverCon);
  583. return NULL;
  584. }
  585. return serverCon;
  586. }