OLD | NEW |
1 /* ssl/bio_ssl.c */ | 1 /* ssl/bio_ssl.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 case BIO_C_SET_SSL_RENEGOTIATE_BYTES: | 341 case BIO_C_SET_SSL_RENEGOTIATE_BYTES: |
342 ret=bs->renegotiate_count; | 342 ret=bs->renegotiate_count; |
343 if ((long)num >=512) | 343 if ((long)num >=512) |
344 bs->renegotiate_count=(unsigned long)num; | 344 bs->renegotiate_count=(unsigned long)num; |
345 break; | 345 break; |
346 case BIO_C_GET_SSL_NUM_RENEGOTIATES: | 346 case BIO_C_GET_SSL_NUM_RENEGOTIATES: |
347 ret=bs->num_renegotiates; | 347 ret=bs->num_renegotiates; |
348 break; | 348 break; |
349 case BIO_C_SET_SSL: | 349 case BIO_C_SET_SSL: |
350 if (ssl != NULL) | 350 if (ssl != NULL) |
| 351 { |
351 ssl_free(b); | 352 ssl_free(b); |
| 353 if (!ssl_new(b)) |
| 354 return 0; |
| 355 } |
352 b->shutdown=(int)num; | 356 b->shutdown=(int)num; |
353 ssl=(SSL *)ptr; | 357 ssl=(SSL *)ptr; |
354 ((BIO_SSL *)b->ptr)->ssl=ssl; | 358 ((BIO_SSL *)b->ptr)->ssl=ssl; |
355 bio=SSL_get_rbio(ssl); | 359 bio=SSL_get_rbio(ssl); |
356 if (bio != NULL) | 360 if (bio != NULL) |
357 { | 361 { |
358 if (b->next_bio != NULL) | 362 if (b->next_bio != NULL) |
359 BIO_push(bio,b->next_bio); | 363 BIO_push(bio,b->next_bio); |
360 b->next_bio=bio; | 364 b->next_bio=bio; |
361 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO); | 365 CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO); |
(...skipping 29 matching lines...) Expand all Loading... |
391 BIO_copy_next_retry(b); | 395 BIO_copy_next_retry(b); |
392 break; | 396 break; |
393 case BIO_CTRL_PUSH: | 397 case BIO_CTRL_PUSH: |
394 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) | 398 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) |
395 { | 399 { |
396 SSL_set_bio(ssl,b->next_bio,b->next_bio); | 400 SSL_set_bio(ssl,b->next_bio,b->next_bio); |
397 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | 401 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); |
398 } | 402 } |
399 break; | 403 break; |
400 case BIO_CTRL_POP: | 404 case BIO_CTRL_POP: |
401 » » /* ugly bit of a hack */ | 405 » » /* Only detach if we are the BIO explicitly being popped */ |
402 » » if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */ | 406 » » if (b == ptr) |
403 { | 407 { |
404 » » » BIO_free_all(ssl->wbio); | 408 » » » /* Shouldn't happen in practice because the |
| 409 » » » * rbio and wbio are the same when pushed. |
| 410 » » » */ |
| 411 » » » if (ssl->rbio != ssl->wbio) |
| 412 » » » » BIO_free_all(ssl->wbio); |
| 413 » » » if (b->next_bio != NULL) |
| 414 » » » » CRYPTO_add(&b->next_bio->references,-1,CRYPTO_LO
CK_BIO); |
| 415 » » » ssl->wbio=NULL; |
| 416 » » » ssl->rbio=NULL; |
405 } | 417 } |
406 if (b->next_bio != NULL) | |
407 { | |
408 CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | |
409 } | |
410 ssl->wbio=NULL; | |
411 ssl->rbio=NULL; | |
412 break; | 418 break; |
413 case BIO_C_DO_STATE_MACHINE: | 419 case BIO_C_DO_STATE_MACHINE: |
414 BIO_clear_retry_flags(b); | 420 BIO_clear_retry_flags(b); |
415 | 421 |
416 b->retry_reason=0; | 422 b->retry_reason=0; |
417 ret=(int)SSL_do_handshake(ssl); | 423 ret=(int)SSL_do_handshake(ssl); |
418 | 424 |
419 switch (SSL_get_error(ssl,(int)ret)) | 425 switch (SSL_get_error(ssl,(int)ret)) |
420 { | 426 { |
421 case SSL_ERROR_WANT_READ: | 427 case SSL_ERROR_WANT_READ: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 542 |
537 if ((con=BIO_new(BIO_s_connect())) == NULL) | 543 if ((con=BIO_new(BIO_s_connect())) == NULL) |
538 return(NULL); | 544 return(NULL); |
539 if ((ssl=BIO_new_ssl(ctx,1)) == NULL) | 545 if ((ssl=BIO_new_ssl(ctx,1)) == NULL) |
540 goto err; | 546 goto err; |
541 if ((ret=BIO_push(ssl,con)) == NULL) | 547 if ((ret=BIO_push(ssl,con)) == NULL) |
542 goto err; | 548 goto err; |
543 return(ret); | 549 return(ret); |
544 err: | 550 err: |
545 if (con != NULL) BIO_free(con); | 551 if (con != NULL) BIO_free(con); |
546 if (ret != NULL) BIO_free(ret); | |
547 return(NULL); | 552 return(NULL); |
548 } | 553 } |
549 | 554 |
550 BIO *BIO_new_ssl(SSL_CTX *ctx, int client) | 555 BIO *BIO_new_ssl(SSL_CTX *ctx, int client) |
551 { | 556 { |
552 BIO *ret; | 557 BIO *ret; |
553 SSL *ssl; | 558 SSL *ssl; |
554 | 559 |
555 if ((ret=BIO_new(BIO_f_ssl())) == NULL) | 560 if ((ret=BIO_new(BIO_f_ssl())) == NULL) |
556 return(NULL); | 561 return(NULL); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 { | 594 { |
590 if (b->method->type == BIO_TYPE_SSL) | 595 if (b->method->type == BIO_TYPE_SSL) |
591 { | 596 { |
592 s=((BIO_SSL *)b->ptr)->ssl; | 597 s=((BIO_SSL *)b->ptr)->ssl; |
593 SSL_shutdown(s); | 598 SSL_shutdown(s); |
594 break; | 599 break; |
595 } | 600 } |
596 b=b->next_bio; | 601 b=b->next_bio; |
597 } | 602 } |
598 } | 603 } |
OLD | NEW |