Add an SSL_dup test
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12245)
Matt Caswell
3 years ago
6577 | 6577 | return testresult; |
6578 | 6578 | } |
6579 | 6579 | |
6580 | #ifndef OPENSSL_NO_TLS1_2 | |
6581 | static int test_ssl_dup(void) | |
6582 | { | |
6583 | SSL_CTX *cctx = NULL, *sctx = NULL; | |
6584 | SSL *clientssl = NULL, *serverssl = NULL, *client2ssl = NULL; | |
6585 | int testresult = 0; | |
6586 | BIO *rbio = NULL, *wbio = NULL; | |
6587 | ||
6588 | if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), | |
6589 | TLS_client_method(), | |
6590 | 0, | |
6591 | 0, | |
6592 | &sctx, &cctx, cert, privkey))) | |
6593 | goto end; | |
6594 | ||
6595 | if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl, | |
6596 | NULL, NULL))) | |
6597 | goto end; | |
6598 | ||
6599 | if (!TEST_true(SSL_set_min_proto_version(clientssl, TLS1_2_VERSION)) | |
6600 | || !TEST_true(SSL_set_max_proto_version(clientssl, TLS1_2_VERSION))) | |
6601 | goto end; | |
6602 | ||
6603 | client2ssl = SSL_dup(clientssl); | |
6604 | rbio = SSL_get_rbio(clientssl); | |
6605 | if (!TEST_ptr(rbio) | |
6606 | || !TEST_true(BIO_up_ref(rbio))) | |
6607 | goto end; | |
6608 | SSL_set0_rbio(client2ssl, rbio); | |
6609 | rbio = NULL; | |
6610 | ||
6611 | wbio = SSL_get_wbio(clientssl); | |
6612 | if (!TEST_ptr(wbio) || !TEST_true(BIO_up_ref(wbio))) | |
6613 | goto end; | |
6614 | SSL_set0_wbio(client2ssl, wbio); | |
6615 | rbio = NULL; | |
6616 | ||
6617 | if (!TEST_ptr(client2ssl) | |
6618 | /* Handshake not started so pointers should be different */ | |
6619 | || !TEST_ptr_ne(clientssl, client2ssl)) | |
6620 | goto end; | |
6621 | ||
6622 | if (!TEST_int_eq(SSL_get_min_proto_version(client2ssl), TLS1_2_VERSION) | |
6623 | || !TEST_int_eq(SSL_get_max_proto_version(client2ssl), TLS1_2_VERSION)) | |
6624 | goto end; | |
6625 | ||
6626 | if (!TEST_true(create_ssl_connection(serverssl, client2ssl, SSL_ERROR_NONE))) | |
6627 | goto end; | |
6628 | ||
6629 | SSL_free(clientssl); | |
6630 | clientssl = SSL_dup(client2ssl); | |
6631 | if (!TEST_ptr(clientssl) | |
6632 | /* Handshake has finished so pointers should be the same */ | |
6633 | || !TEST_ptr_eq(clientssl, client2ssl)) | |
6634 | goto end; | |
6635 | ||
6636 | testresult = 1; | |
6637 | ||
6638 | end: | |
6639 | SSL_free(serverssl); | |
6640 | SSL_free(clientssl); | |
6641 | SSL_free(client2ssl); | |
6642 | SSL_CTX_free(sctx); | |
6643 | SSL_CTX_free(cctx); | |
6644 | ||
6645 | return testresult; | |
6646 | } | |
6647 | #endif | |
6648 | ||
6580 | 6649 | int setup_tests(void) |
6581 | 6650 | { |
6582 | 6651 | if (!TEST_ptr(certsdir = test_get_argument(0)) |
6697 | 6766 | ADD_ALL_TESTS(test_client_cert_cb, 2); |
6698 | 6767 | ADD_ALL_TESTS(test_ca_names, 3); |
6699 | 6768 | ADD_ALL_TESTS(test_servername, 10); |
6769 | #ifndef OPENSSL_NO_TLS1_2 | |
6770 | ADD_TEST(test_ssl_dup); | |
6771 | #endif | |
6700 | 6772 | return 1; |
6701 | 6773 | } |
6702 | 6774 |