Skip to content

Commit f21c34b

Browse files
committed
tests: EmbedRecvFrom/EmbedSendTo error if ipv6 w/o ipv6 compiled in
1 parent 640f9cf commit f21c34b

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/api.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66022,6 +66022,85 @@ static int test_dtls_msg_from_other_peer(void)
6602266022
#endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
6602366023
* !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
6602466024
* !defined(SINGLE_THREADED) */
66025+
#if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
66026+
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
66027+
defined(HAVE_IO_TESTS_DEPENDENCIES)
66028+
static int test_dtls_ipv6_check(void)
66029+
{
66030+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
66031+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
66032+
SOCKADDR_IN fake_addr6;
66033+
int sockfd;
66034+
int ret;
66035+
66036+
ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method());
66037+
if (ctx_c == NULL)
66038+
return TEST_FAIL;
66039+
ssl_c = wolfSSL_new(ctx_c);
66040+
if (ssl_c == NULL)
66041+
return TEST_FAIL;
66042+
ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
66043+
if (ctx_s == NULL)
66044+
return TEST_FAIL;
66045+
ret = wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
66046+
WOLFSSL_FILETYPE_PEM);
66047+
if (ret != WOLFSSL_SUCCESS)
66048+
return- -1;
66049+
ret = wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
66050+
WOLFSSL_FILETYPE_PEM);
66051+
if (ret != WOLFSSL_SUCCESS)
66052+
return -1;
66053+
ssl_s = wolfSSL_new(ctx_s);
66054+
if (ssl_s == NULL)
66055+
return TEST_FAIL;
66056+
XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
66057+
/* mimic a sockaddr_in6 struct, this way we can't test without
66058+
* WOLFSSL_IPV6 */
66059+
fake_addr6.sin_family = WOLFSSL_IP6;
66060+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
66061+
if (sockfd == -1)
66062+
return TEST_FAIL;
66063+
ret = wolfSSL_set_fd(ssl_c, sockfd);
66064+
if (ret != WOLFSSL_SUCCESS)
66065+
return TEST_FAIL;
66066+
/* can't return error here, as the peer is opaque for wolfssl library at
66067+
* this point */
66068+
ret = wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6));
66069+
if (ret != WOLFSSL_SUCCESS)
66070+
return TEST_FAIL;
66071+
ret = fcntl(sockfd, F_SETFL, O_NONBLOCK);
66072+
if (ret == -1)
66073+
return TEST_FAIL;
66074+
wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
66075+
ret = wolfSSL_connect(ssl_c);
66076+
if (ret != WOLFSSL_FAILURE && ssl_c->error != SOCKET_ERROR_E)
66077+
return TEST_FAIL;
66078+
66079+
ret = wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6));
66080+
if (ret != WOLFSSL_SUCCESS)
66081+
return TEST_FAIL;
66082+
/* re-use the socket */
66083+
ret = wolfSSL_set_fd(ssl_c, sockfd);
66084+
if (ret != WOLFSSL_SUCCESS)
66085+
return TEST_FAIL;
66086+
wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
66087+
ret = wolfSSL_accept(ssl_s);
66088+
if (ret != WOLFSSL_FAILURE && ssl_s->error != SOCKET_ERROR_E)
66089+
return TEST_FAIL;
66090+
close(sockfd);
66091+
66092+
wolfSSL_free(ssl_c);
66093+
wolfSSL_CTX_free(ctx_c);
66094+
wolfSSL_free(ssl_s);
66095+
wolfSSL_CTX_free(ctx_s);
66096+
return TEST_SUCCESS;
66097+
}
66098+
#else
66099+
static int test_dtls_ipv6_check(void)
66100+
{
66101+
return TEST_SKIPPED;
66102+
}
66103+
#endif
6602566104
/*----------------------------------------------------------------------------*
6602666105
| Main
6602766106
*----------------------------------------------------------------------------*/
@@ -67061,6 +67140,7 @@ TEST_CASE testCases[] = {
6706167140
TEST_DECL(test_dtls13_bad_epoch_ch),
6706267141
TEST_DECL(test_wolfSSL_dtls13_null_cipher),
6706367142
TEST_DECL(test_dtls_msg_from_other_peer),
67143+
TEST_DECL(test_dtls_ipv6_check),
6706467144
/* If at some point a stub get implemented this test should fail indicating
6706567145
* a need to implement a new test case
6706667146
*/

0 commit comments

Comments
 (0)