PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/crypto/openssl/apps/s_time.c

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