diff options
author | beck <> | 1999-09-29 04:37:45 +0000 |
---|---|---|
committer | beck <> | 1999-09-29 04:37:45 +0000 |
commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libssl/src/ssl/ssltest.c | |
parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libssl/src/ssl/ssltest.c')
-rw-r--r-- | src/lib/libssl/src/ssl/ssltest.c | 510 |
1 files changed, 461 insertions, 49 deletions
diff --git a/src/lib/libssl/src/ssl/ssltest.c b/src/lib/libssl/src/ssl/ssltest.c index f9dca4e3ef..90570f4bee 100644 --- a/src/lib/libssl/src/ssl/ssltest.c +++ b/src/lib/libssl/src/ssl/ssltest.c | |||
@@ -60,51 +60,55 @@ | |||
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <string.h> | 61 | #include <string.h> |
62 | #include <errno.h> | 62 | #include <errno.h> |
63 | #include "e_os.h" | 63 | #include <limits.h> |
64 | #include "bio.h" | 64 | |
65 | #include "crypto.h" | 65 | #include "openssl/e_os.h" |
66 | #include "x509.h" | 66 | |
67 | #include "ssl.h" | 67 | #include <openssl/bio.h> |
68 | #include "err.h" | 68 | #include <openssl/crypto.h> |
69 | #include <openssl/x509.h> | ||
70 | #include <openssl/ssl.h> | ||
71 | #include <openssl/err.h> | ||
69 | #ifdef WINDOWS | 72 | #ifdef WINDOWS |
70 | #include "../crypto/bio/bss_file.c" | 73 | #include "../crypto/bio/bss_file.c" |
71 | #endif | 74 | #endif |
72 | 75 | ||
73 | #define TEST_SERVER_CERT "../apps/server.pem" | 76 | #if defined(NO_RSA) && !defined(NO_SSL2) |
74 | #define TEST_CLIENT_CERT "../apps/client.pem" | 77 | #define NO_SSL2 |
75 | |||
76 | #ifndef NOPROTO | ||
77 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx); | ||
78 | static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export); | ||
79 | #ifndef NO_DSA | ||
80 | static DH *get_dh512(void); | ||
81 | #endif | 78 | #endif |
79 | |||
80 | #ifdef VMS | ||
81 | # define TEST_SERVER_CERT "SYS$DISK:[-.APPS]SERVER.PEM" | ||
82 | # define TEST_CLIENT_CERT "SYS$DISK:[-.APPS]CLIENT.PEM" | ||
82 | #else | 83 | #else |
83 | int MS_CALLBACK verify_callback(); | 84 | # define TEST_SERVER_CERT "../apps/server.pem" |
84 | static RSA MS_CALLBACK *tmp_rsa_cb(); | 85 | # define TEST_CLIENT_CERT "../apps/client.pem" |
85 | #ifndef NO_DSA | ||
86 | static DH *get_dh512(); | ||
87 | #endif | ||
88 | #endif | 86 | #endif |
89 | 87 | ||
88 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx); | ||
89 | #ifndef NO_RSA | ||
90 | static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export,int keylength); | ||
91 | #endif | ||
92 | #ifndef NO_DH | ||
93 | static DH *get_dh512(void); | ||
94 | #endif | ||
90 | BIO *bio_err=NULL; | 95 | BIO *bio_err=NULL; |
91 | BIO *bio_stdout=NULL; | 96 | BIO *bio_stdout=NULL; |
92 | 97 | ||
93 | static char *cipher=NULL; | 98 | static char *cipher=NULL; |
94 | int verbose=0; | 99 | int verbose=0; |
95 | int debug=0; | 100 | int debug=0; |
101 | #if 0 | ||
102 | /* Not used yet. */ | ||
96 | #ifdef FIONBIO | 103 | #ifdef FIONBIO |
97 | static int s_nbio=0; | 104 | static int s_nbio=0; |
98 | #endif | 105 | #endif |
106 | #endif | ||
99 | 107 | ||
100 | 108 | ||
101 | #ifndef NOPROTO | 109 | int doit_biopair(SSL *s_ssl,SSL *c_ssl,long bytes); |
102 | int doit(SSL *s_ssl,SSL *c_ssl,long bytes); | 110 | int doit(SSL *s_ssl,SSL *c_ssl,long bytes); |
103 | #else | 111 | static void sv_usage(void) |
104 | int doit(); | ||
105 | #endif | ||
106 | |||
107 | static void sv_usage() | ||
108 | { | 112 | { |
109 | fprintf(stderr,"usage: ssltest [args ...]\n"); | 113 | fprintf(stderr,"usage: ssltest [args ...]\n"); |
110 | fprintf(stderr,"\n"); | 114 | fprintf(stderr,"\n"); |
@@ -115,6 +119,9 @@ static void sv_usage() | |||
115 | fprintf(stderr," -reuse - use session-id reuse\n"); | 119 | fprintf(stderr," -reuse - use session-id reuse\n"); |
116 | fprintf(stderr," -num <val> - number of connections to perform\n"); | 120 | fprintf(stderr," -num <val> - number of connections to perform\n"); |
117 | fprintf(stderr," -bytes <val> - number of bytes to swap between client/server\n"); | 121 | fprintf(stderr," -bytes <val> - number of bytes to swap between client/server\n"); |
122 | #if !defined NO_DH && !defined NO_DSA | ||
123 | fprintf(stderr," -dhe1024 - generate 1024 bit key for DHE\n"); | ||
124 | #endif | ||
118 | #ifndef NO_SSL2 | 125 | #ifndef NO_SSL2 |
119 | fprintf(stderr," -ssl2 - use SSLv2\n"); | 126 | fprintf(stderr," -ssl2 - use SSLv2\n"); |
120 | #endif | 127 | #endif |
@@ -130,14 +137,16 @@ static void sv_usage() | |||
130 | fprintf(stderr," -s_cert arg - Just the server certificate file\n"); | 137 | fprintf(stderr," -s_cert arg - Just the server certificate file\n"); |
131 | fprintf(stderr," -c_cert arg - Just the client certificate file\n"); | 138 | fprintf(stderr," -c_cert arg - Just the client certificate file\n"); |
132 | fprintf(stderr," -cipher arg - The cipher list\n"); | 139 | fprintf(stderr," -cipher arg - The cipher list\n"); |
140 | fprintf(stderr," -bio_pair - Use BIO pairs\n"); | ||
141 | fprintf(stderr," -f - Test even cases that can't work\n"); | ||
133 | } | 142 | } |
134 | 143 | ||
135 | int main(argc, argv) | 144 | int main(int argc, char *argv[]) |
136 | int argc; | ||
137 | char *argv[]; | ||
138 | { | 145 | { |
139 | char *CApath=NULL,*CAfile=NULL; | 146 | char *CApath=NULL,*CAfile=NULL; |
140 | int badop=0; | 147 | int badop=0; |
148 | int bio_pair=0; | ||
149 | int force=0; | ||
141 | int tls1=0,ssl2=0,ssl3=0,ret=1; | 150 | int tls1=0,ssl2=0,ssl3=0,ret=1; |
142 | int client_auth=0; | 151 | int client_auth=0; |
143 | int server_auth=0,i; | 152 | int server_auth=0,i; |
@@ -150,6 +159,7 @@ char *argv[]; | |||
150 | int number=1,reuse=0; | 159 | int number=1,reuse=0; |
151 | long bytes=1L; | 160 | long bytes=1L; |
152 | SSL_CIPHER *ciph; | 161 | SSL_CIPHER *ciph; |
162 | int dhe1024 = 0; | ||
153 | #ifndef NO_DH | 163 | #ifndef NO_DH |
154 | DH *dh; | 164 | DH *dh; |
155 | #endif | 165 | #endif |
@@ -174,6 +184,8 @@ char *argv[]; | |||
174 | debug=1; | 184 | debug=1; |
175 | else if (strcmp(*argv,"-reuse") == 0) | 185 | else if (strcmp(*argv,"-reuse") == 0) |
176 | reuse=1; | 186 | reuse=1; |
187 | else if (strcmp(*argv,"-dhe1024") == 0) | ||
188 | dhe1024=1; | ||
177 | else if (strcmp(*argv,"-ssl2") == 0) | 189 | else if (strcmp(*argv,"-ssl2") == 0) |
178 | ssl2=1; | 190 | ssl2=1; |
179 | else if (strcmp(*argv,"-tls1") == 0) | 191 | else if (strcmp(*argv,"-tls1") == 0) |
@@ -225,6 +237,14 @@ char *argv[]; | |||
225 | if (--argc < 1) goto bad; | 237 | if (--argc < 1) goto bad; |
226 | CAfile= *(++argv); | 238 | CAfile= *(++argv); |
227 | } | 239 | } |
240 | else if (strcmp(*argv,"-bio_pair") == 0) | ||
241 | { | ||
242 | bio_pair = 1; | ||
243 | } | ||
244 | else if (strcmp(*argv,"-f") == 0) | ||
245 | { | ||
246 | force = 1; | ||
247 | } | ||
228 | else | 248 | else |
229 | { | 249 | { |
230 | fprintf(stderr,"unknown option %s\n",*argv); | 250 | fprintf(stderr,"unknown option %s\n",*argv); |
@@ -241,9 +261,20 @@ bad: | |||
241 | goto end; | 261 | goto end; |
242 | } | 262 | } |
243 | 263 | ||
264 | if (!ssl2 && !ssl3 && !tls1 && number > 1 && !reuse && !force) | ||
265 | { | ||
266 | fprintf(stderr, "This case cannot work. Use -f switch to perform " | ||
267 | "the test anyway\n" | ||
268 | "(and -d to see what happens, " | ||
269 | "and -bio_pair to really make it happen :-)\n" | ||
270 | "or add one of -ssl2, -ssl3, -tls1, -reuse to " | ||
271 | "avoid protocol mismatch.\n"); | ||
272 | exit(1); | ||
273 | } | ||
274 | |||
244 | /* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */ | 275 | /* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */ |
245 | 276 | ||
246 | SSLeay_add_ssl_algorithms(); | 277 | SSL_library_init(); |
247 | SSL_load_error_strings(); | 278 | SSL_load_error_strings(); |
248 | 279 | ||
249 | #if !defined(NO_SSL2) && !defined(NO_SSL3) | 280 | #if !defined(NO_SSL2) && !defined(NO_SSL3) |
@@ -280,7 +311,29 @@ bad: | |||
280 | } | 311 | } |
281 | 312 | ||
282 | #ifndef NO_DH | 313 | #ifndef NO_DH |
283 | dh=get_dh512(); | 314 | # ifndef NO_DSA |
315 | if (dhe1024) | ||
316 | { | ||
317 | DSA *dsa; | ||
318 | |||
319 | if (verbose) | ||
320 | { | ||
321 | fprintf(stdout, "Creating 1024 bit DHE parameters ..."); | ||
322 | fflush(stdout); | ||
323 | } | ||
324 | |||
325 | dsa = DSA_generate_parameters(1024, NULL, 0, NULL, NULL, 0, NULL); | ||
326 | dh = DSA_dup_DH(dsa); | ||
327 | DSA_free(dsa); | ||
328 | /* important: SSL_OP_SINGLE_DH_USE to avoid small subgroup attacks */ | ||
329 | SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE); | ||
330 | |||
331 | if (verbose) | ||
332 | fprintf(stdout, " done\n"); | ||
333 | } | ||
334 | else | ||
335 | # endif | ||
336 | dh=get_dh512(); | ||
284 | SSL_CTX_set_tmp_dh(s_ctx,dh); | 337 | SSL_CTX_set_tmp_dh(s_ctx,dh); |
285 | DH_free(dh); | 338 | DH_free(dh); |
286 | #endif | 339 | #endif |
@@ -338,7 +391,10 @@ bad: | |||
338 | for (i=0; i<number; i++) | 391 | for (i=0; i<number; i++) |
339 | { | 392 | { |
340 | if (!reuse) SSL_set_session(c_ssl,NULL); | 393 | if (!reuse) SSL_set_session(c_ssl,NULL); |
341 | ret=doit(s_ssl,c_ssl,bytes); | 394 | if (bio_pair) |
395 | ret=doit_biopair(s_ssl,c_ssl,bytes); | ||
396 | else | ||
397 | ret=doit(s_ssl,c_ssl,bytes); | ||
342 | } | 398 | } |
343 | 399 | ||
344 | if (!verbose) | 400 | if (!verbose) |
@@ -361,20 +417,382 @@ end: | |||
361 | 417 | ||
362 | if (bio_stdout != NULL) BIO_free(bio_stdout); | 418 | if (bio_stdout != NULL) BIO_free(bio_stdout); |
363 | 419 | ||
420 | ERR_free_strings(); | ||
364 | ERR_remove_state(0); | 421 | ERR_remove_state(0); |
365 | EVP_cleanup(); | 422 | EVP_cleanup(); |
366 | CRYPTO_mem_leaks(bio_err); | 423 | CRYPTO_mem_leaks(bio_err); |
367 | EXIT(ret); | 424 | EXIT(ret); |
368 | } | 425 | } |
369 | 426 | ||
427 | int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count) | ||
428 | { | ||
429 | long cw_num = count, cr_num = count, sw_num = count, sr_num = count; | ||
430 | BIO *s_ssl_bio = NULL, *c_ssl_bio = NULL; | ||
431 | BIO *server = NULL, *server_io = NULL, *client = NULL, *client_io = NULL; | ||
432 | SSL_CIPHER *ciph; | ||
433 | int ret = 1; | ||
434 | |||
435 | size_t bufsiz = 256; /* small buffer for testing */ | ||
436 | |||
437 | if (!BIO_new_bio_pair(&server, bufsiz, &server_io, bufsiz)) | ||
438 | goto err; | ||
439 | if (!BIO_new_bio_pair(&client, bufsiz, &client_io, bufsiz)) | ||
440 | goto err; | ||
441 | |||
442 | s_ssl_bio = BIO_new(BIO_f_ssl()); | ||
443 | if (!s_ssl_bio) | ||
444 | goto err; | ||
445 | |||
446 | c_ssl_bio = BIO_new(BIO_f_ssl()); | ||
447 | if (!c_ssl_bio) | ||
448 | goto err; | ||
449 | |||
450 | SSL_set_connect_state(c_ssl); | ||
451 | SSL_set_bio(c_ssl, client, client); | ||
452 | (void)BIO_set_ssl(c_ssl_bio, c_ssl, BIO_NOCLOSE); | ||
453 | |||
454 | SSL_set_accept_state(s_ssl); | ||
455 | SSL_set_bio(s_ssl, server, server); | ||
456 | (void)BIO_set_ssl(s_ssl_bio, s_ssl, BIO_NOCLOSE); | ||
457 | |||
458 | do | ||
459 | { | ||
460 | /* c_ssl_bio: SSL filter BIO | ||
461 | * | ||
462 | * client: pseudo-I/O for SSL library | ||
463 | * | ||
464 | * client_io: client's SSL communication; usually to be | ||
465 | * relayed over some I/O facility, but in this | ||
466 | * test program, we're the server, too: | ||
467 | * | ||
468 | * server_io: server's SSL communication | ||
469 | * | ||
470 | * server: pseudo-I/O for SSL library | ||
471 | * | ||
472 | * s_ssl_bio: SSL filter BIO | ||
473 | * | ||
474 | * The client and the server each employ a "BIO pair": | ||
475 | * client + client_io, server + server_io. | ||
476 | * BIO pairs are symmetric. A BIO pair behaves similar | ||
477 | * to a non-blocking socketpair (but both endpoints must | ||
478 | * be handled by the same thread). | ||
479 | * [Here we could connect client and server to the ends | ||
480 | * of a single BIO pair, but then this code would be less | ||
481 | * suitable as an example for BIO pairs in general.] | ||
482 | * | ||
483 | * Useful functions for querying the state of BIO pair endpoints: | ||
484 | * | ||
485 | * BIO_ctrl_pending(bio) number of bytes we can read now | ||
486 | * BIO_ctrl_get_read_request(bio) number of bytes needed to fulfil | ||
487 | * other side's read attempt | ||
488 | * BIO_ctrl_get_write_gurantee(bio) number of bytes we can write now | ||
489 | * | ||
490 | * ..._read_request is never more than ..._write_guarantee; | ||
491 | * it depends on the application which one you should use. | ||
492 | */ | ||
493 | |||
494 | /* We have non-blocking behaviour throughout this test program, but | ||
495 | * can be sure that there is *some* progress in each iteration; so | ||
496 | * we don't have to worry about ..._SHOULD_READ or ..._SHOULD_WRITE | ||
497 | * -- we just try everything in each iteration | ||
498 | */ | ||
499 | |||
500 | { | ||
501 | /* CLIENT */ | ||
502 | |||
503 | MS_STATIC char cbuf[1024*8]; | ||
504 | int i, r; | ||
505 | |||
506 | if (debug) | ||
507 | if (SSL_in_init(c_ssl)) | ||
508 | printf("client waiting in SSL_connect - %s\n", | ||
509 | SSL_state_string_long(c_ssl)); | ||
510 | |||
511 | if (cw_num > 0) | ||
512 | { | ||
513 | /* Write to server. */ | ||
514 | |||
515 | if (cw_num > (long)sizeof cbuf) | ||
516 | i = sizeof cbuf; | ||
517 | else | ||
518 | i = (int)cw_num; | ||
519 | r = BIO_write(c_ssl_bio, cbuf, i); | ||
520 | if (r == -1) | ||
521 | { | ||
522 | if (!BIO_should_retry(c_ssl_bio)) | ||
523 | { | ||
524 | fprintf(stderr,"ERROR in CLIENT\n"); | ||
525 | goto err; | ||
526 | } | ||
527 | /* BIO_should_retry(...) can just be ignored here. | ||
528 | * The library expects us to call BIO_write with | ||
529 | * the same arguments again, and that's what we will | ||
530 | * do in the next iteration. */ | ||
531 | } | ||
532 | else if (r == 0) | ||
533 | { | ||
534 | fprintf(stderr,"SSL CLIENT STARTUP FAILED\n"); | ||
535 | goto err; | ||
536 | } | ||
537 | else | ||
538 | { | ||
539 | if (debug) | ||
540 | printf("client wrote %d\n", r); | ||
541 | cw_num -= r; | ||
542 | } | ||
543 | } | ||
544 | |||
545 | if (cr_num > 0) | ||
546 | { | ||
547 | /* Read from server. */ | ||
548 | |||
549 | r = BIO_read(c_ssl_bio, cbuf, sizeof(cbuf)); | ||
550 | if (r < 0) | ||
551 | { | ||
552 | if (!BIO_should_retry(c_ssl_bio)) | ||
553 | { | ||
554 | fprintf(stderr,"ERROR in CLIENT\n"); | ||
555 | goto err; | ||
556 | } | ||
557 | /* Again, "BIO_should_retry" can be ignored. */ | ||
558 | } | ||
559 | else if (r == 0) | ||
560 | { | ||
561 | fprintf(stderr,"SSL CLIENT STARTUP FAILED\n"); | ||
562 | goto err; | ||
563 | } | ||
564 | else | ||
565 | { | ||
566 | if (debug) | ||
567 | printf("client read %d\n", r); | ||
568 | cr_num -= r; | ||
569 | } | ||
570 | } | ||
571 | } | ||
572 | |||
573 | { | ||
574 | /* SERVER */ | ||
575 | |||
576 | MS_STATIC char sbuf[1024*8]; | ||
577 | int i, r; | ||
578 | |||
579 | if (debug) | ||
580 | if (SSL_in_init(s_ssl)) | ||
581 | printf("server waiting in SSL_accept - %s\n", | ||
582 | SSL_state_string_long(s_ssl)); | ||
583 | |||
584 | if (sw_num > 0) | ||
585 | { | ||
586 | /* Write to client. */ | ||
587 | |||
588 | if (sw_num > (long)sizeof sbuf) | ||
589 | i = sizeof sbuf; | ||
590 | else | ||
591 | i = (int)sw_num; | ||
592 | r = BIO_write(s_ssl_bio, sbuf, i); | ||
593 | if (r == -1) | ||
594 | { | ||
595 | if (!BIO_should_retry(s_ssl_bio)) | ||
596 | { | ||
597 | fprintf(stderr,"ERROR in SERVER\n"); | ||
598 | goto err; | ||
599 | } | ||
600 | /* Ignore "BIO_should_retry". */ | ||
601 | } | ||
602 | else if (r == 0) | ||
603 | { | ||
604 | fprintf(stderr,"SSL SERVER STARTUP FAILED\n"); | ||
605 | goto err; | ||
606 | } | ||
607 | else | ||
608 | { | ||
609 | if (debug) | ||
610 | printf("server wrote %d\n", r); | ||
611 | sw_num -= r; | ||
612 | } | ||
613 | } | ||
614 | |||
615 | if (sr_num > 0) | ||
616 | { | ||
617 | /* Read from client. */ | ||
618 | |||
619 | r = BIO_read(s_ssl_bio, sbuf, sizeof(sbuf)); | ||
620 | if (r < 0) | ||
621 | { | ||
622 | if (!BIO_should_retry(s_ssl_bio)) | ||
623 | { | ||
624 | fprintf(stderr,"ERROR in SERVER\n"); | ||
625 | goto err; | ||
626 | } | ||
627 | /* blah, blah */ | ||
628 | } | ||
629 | else if (r == 0) | ||
630 | { | ||
631 | fprintf(stderr,"SSL SERVER STARTUP FAILED\n"); | ||
632 | goto err; | ||
633 | } | ||
634 | else | ||
635 | { | ||
636 | if (debug) | ||
637 | printf("server read %d\n", r); | ||
638 | sr_num -= r; | ||
639 | } | ||
640 | } | ||
641 | } | ||
642 | |||
643 | { | ||
644 | /* "I/O" BETWEEN CLIENT AND SERVER. */ | ||
645 | |||
646 | #define RELAYBUFSIZ 200 | ||
647 | static char buf[RELAYBUFSIZ]; | ||
648 | |||
649 | /* RELAYBUF is arbitrary. When writing data over some real | ||
650 | * network, use a buffer of the same size as in the BIO_pipe | ||
651 | * and make that size large (for reading from the network | ||
652 | * small buffers usually won't hurt). | ||
653 | * Here sizes differ for testing. */ | ||
654 | |||
655 | size_t r1, r2; | ||
656 | size_t num; | ||
657 | int r; | ||
658 | static int prev_progress = 1; | ||
659 | int progress = 0; | ||
660 | |||
661 | /* client to server */ | ||
662 | do | ||
663 | { | ||
664 | r1 = BIO_ctrl_pending(client_io); | ||
665 | r2 = BIO_ctrl_get_write_guarantee(server_io); | ||
666 | |||
667 | num = r1; | ||
668 | if (r2 < num) | ||
669 | num = r2; | ||
670 | if (num) | ||
671 | { | ||
672 | if (sizeof buf < num) | ||
673 | num = sizeof buf; | ||
674 | if (INT_MAX < num) /* yeah, right */ | ||
675 | num = INT_MAX; | ||
676 | |||
677 | r = BIO_read(client_io, buf, (int)num); | ||
678 | if (r != (int)num) /* can't happen */ | ||
679 | { | ||
680 | fprintf(stderr, "ERROR: BIO_read could not read " | ||
681 | "BIO_ctrl_pending() bytes"); | ||
682 | goto err; | ||
683 | } | ||
684 | r = BIO_write(server_io, buf, (int)num); | ||
685 | if (r != (int)num) /* can't happen */ | ||
686 | { | ||
687 | fprintf(stderr, "ERROR: BIO_write could not write " | ||
688 | "BIO_ctrl_get_write_guarantee() bytes"); | ||
689 | goto err; | ||
690 | } | ||
691 | progress = 1; | ||
692 | |||
693 | if (debug) | ||
694 | printf("C->S relaying: %d bytes\n", (int)num); | ||
695 | } | ||
696 | } | ||
697 | while (r1 && r2); | ||
698 | |||
699 | /* server to client */ | ||
700 | do | ||
701 | { | ||
702 | r1 = BIO_ctrl_pending(server_io); | ||
703 | r2 = BIO_ctrl_get_write_guarantee(client_io); | ||
704 | |||
705 | num = r1; | ||
706 | if (r2 < num) | ||
707 | num = r2; | ||
708 | if (num) | ||
709 | { | ||
710 | if (sizeof buf < num) | ||
711 | num = sizeof buf; | ||
712 | if (INT_MAX < num) | ||
713 | num = INT_MAX; | ||
714 | |||
715 | r = BIO_read(server_io, buf, (int)num); | ||
716 | if (r != (int)num) /* can't happen */ | ||
717 | { | ||
718 | fprintf(stderr, "ERROR: BIO_read could not read " | ||
719 | "BIO_ctrl_pending() bytes"); | ||
720 | goto err; | ||
721 | } | ||
722 | r = BIO_write(client_io, buf, (int)num); | ||
723 | if (r != (int)num) /* can't happen */ | ||
724 | { | ||
725 | fprintf(stderr, "ERROR: BIO_write could not write " | ||
726 | "BIO_ctrl_get_write_guarantee() bytes"); | ||
727 | goto err; | ||
728 | } | ||
729 | progress = 1; | ||
730 | |||
731 | if (debug) | ||
732 | printf("S->C relaying: %d bytes\n", (int)num); | ||
733 | } | ||
734 | } | ||
735 | while (r1 && r2); | ||
736 | |||
737 | if (!progress && !prev_progress) | ||
738 | if (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0) | ||
739 | { | ||
740 | fprintf(stderr, "ERROR: got stuck\n"); | ||
741 | if (strcmp("SSLv2", SSL_get_version(c_ssl)) == 0) | ||
742 | { | ||
743 | fprintf(stderr, "This can happen for SSL2 because " | ||
744 | "CLIENT-FINISHED and SERVER-VERIFY are written \n" | ||
745 | "concurrently ..."); | ||
746 | if (strncmp("2SCF", SSL_state_string(c_ssl), 4) == 0 | ||
747 | && strncmp("2SSV", SSL_state_string(s_ssl), 4) == 0) | ||
748 | { | ||
749 | fprintf(stderr, " ok.\n"); | ||
750 | goto end; | ||
751 | } | ||
752 | } | ||
753 | fprintf(stderr, " ERROR.\n"); | ||
754 | goto err; | ||
755 | } | ||
756 | prev_progress = progress; | ||
757 | } | ||
758 | } | ||
759 | while (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0); | ||
760 | |||
761 | ciph = SSL_get_current_cipher(c_ssl); | ||
762 | if (verbose) | ||
763 | fprintf(stdout,"DONE via BIO pair, protocol %s, cipher %s, %s\n", | ||
764 | SSL_get_version(c_ssl), | ||
765 | SSL_CIPHER_get_version(ciph), | ||
766 | SSL_CIPHER_get_name(ciph)); | ||
767 | end: | ||
768 | ret = 0; | ||
769 | |||
770 | err: | ||
771 | ERR_print_errors(bio_err); | ||
772 | |||
773 | if (server) | ||
774 | BIO_free(server); | ||
775 | if (server_io) | ||
776 | BIO_free(server_io); | ||
777 | if (client) | ||
778 | BIO_free(client); | ||
779 | if (client_io) | ||
780 | BIO_free(client_io); | ||
781 | if (s_ssl_bio) | ||
782 | BIO_free(s_ssl_bio); | ||
783 | if (c_ssl_bio) | ||
784 | BIO_free(c_ssl_bio); | ||
785 | |||
786 | return ret; | ||
787 | } | ||
788 | |||
789 | |||
370 | #define W_READ 1 | 790 | #define W_READ 1 |
371 | #define W_WRITE 2 | 791 | #define W_WRITE 2 |
372 | #define C_DONE 1 | 792 | #define C_DONE 1 |
373 | #define S_DONE 2 | 793 | #define S_DONE 2 |
374 | 794 | ||
375 | int doit(s_ssl,c_ssl,count) | 795 | int doit(SSL *s_ssl, SSL *c_ssl, long count) |
376 | SSL *s_ssl,*c_ssl; | ||
377 | long count; | ||
378 | { | 796 | { |
379 | MS_STATIC char cbuf[1024*8],sbuf[1024*8]; | 797 | MS_STATIC char cbuf[1024*8],sbuf[1024*8]; |
380 | long cw_num=count,cr_num=count; | 798 | long cw_num=count,cr_num=count; |
@@ -673,9 +1091,7 @@ err: | |||
673 | return(ret); | 1091 | return(ret); |
674 | } | 1092 | } |
675 | 1093 | ||
676 | int MS_CALLBACK verify_callback(ok, ctx) | 1094 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) |
677 | int ok; | ||
678 | X509_STORE_CTX *ctx; | ||
679 | { | 1095 | { |
680 | char *s,buf[256]; | 1096 | char *s,buf[256]; |
681 | 1097 | ||
@@ -716,7 +1132,7 @@ static unsigned char dh512_g[]={ | |||
716 | 0x02, | 1132 | 0x02, |
717 | }; | 1133 | }; |
718 | 1134 | ||
719 | static DH *get_dh512() | 1135 | static DH *get_dh512(void) |
720 | { | 1136 | { |
721 | DH *dh=NULL; | 1137 | DH *dh=NULL; |
722 | 1138 | ||
@@ -729,23 +1145,19 @@ static DH *get_dh512() | |||
729 | } | 1145 | } |
730 | #endif | 1146 | #endif |
731 | 1147 | ||
732 | static RSA MS_CALLBACK *tmp_rsa_cb(s,export) | 1148 | #ifndef NO_RSA |
733 | SSL *s; | 1149 | static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength) |
734 | int export; | ||
735 | { | 1150 | { |
736 | static RSA *rsa_tmp=NULL; | 1151 | static RSA *rsa_tmp=NULL; |
737 | 1152 | ||
738 | if (rsa_tmp == NULL) | 1153 | if (rsa_tmp == NULL) |
739 | { | 1154 | { |
740 | BIO_printf(bio_err,"Generating temp (512 bit) RSA key..."); | 1155 | BIO_printf(bio_err,"Generating temp (%d bit) RSA key...",keylength); |
741 | BIO_flush(bio_err); | 1156 | (void)BIO_flush(bio_err); |
742 | #ifndef NO_RSA | 1157 | rsa_tmp=RSA_generate_key(keylength,RSA_F4,NULL,NULL); |
743 | rsa_tmp=RSA_generate_key(512,RSA_F4,NULL,NULL); | ||
744 | #endif | ||
745 | BIO_printf(bio_err,"\n"); | 1158 | BIO_printf(bio_err,"\n"); |
746 | BIO_flush(bio_err); | 1159 | (void)BIO_flush(bio_err); |
747 | } | 1160 | } |
748 | return(rsa_tmp); | 1161 | return(rsa_tmp); |
749 | } | 1162 | } |
750 | 1163 | #endif | |
751 | |||