diff --git a/src/internal.c b/src/internal.c index c6bb0d1db..3b097aaa7 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3387,7 +3387,8 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT; ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX; ssl->dtls_timeout = ssl->dtls_timeout_init; - ssl->buffers.dtlsCtx.fd = -1; + ssl->buffers.dtlsCtx.rfd = -1; + ssl->buffers.dtlsCtx.wfd = -1; #endif #ifndef NO_OLD_TLS diff --git a/src/io.c b/src/io.c index a37052b3a..c861350d1 100644 --- a/src/io.c +++ b/src/io.c @@ -398,7 +398,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) WOLFSSL_DTLS_CTX* dtlsCtx = (WOLFSSL_DTLS_CTX*)ctx; int recvd; int err; - int sd = dtlsCtx->fd; + int sd = dtlsCtx->rfd; int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl); struct sockaddr_storage peer; XSOCKLENT peerSz = sizeof(peer); @@ -477,7 +477,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx) { WOLFSSL_DTLS_CTX* dtlsCtx = (WOLFSSL_DTLS_CTX*)ctx; - int sd = dtlsCtx->fd; + int sd = dtlsCtx->wfd; int sent; int len = sz; int err; diff --git a/src/ssl.c b/src/ssl.c index b976852a7..4dc82bd8a 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -431,29 +431,64 @@ int wolfSSL_use_old_poly(WOLFSSL* ssl, int value) } #endif + int wolfSSL_set_fd(WOLFSSL* ssl, int fd) { + int ret; + WOLFSSL_ENTER("SSL_set_fd"); + ret = wolfSSL_set_read_fd(ssl, fd); + if (ret == SSL_SUCCESS) { + ret = wolfSSL_set_write_fd(ssl, fd); + } + + return ret; +} + + +int wolfSSL_set_read_fd(WOLFSSL* ssl, int fd) +{ + WOLFSSL_ENTER("SSL_set_read_fd"); + if (ssl == NULL) { return BAD_FUNC_ARG; } ssl->rfd = fd; /* not used directly to allow IO callbacks */ - ssl->wfd = fd; - ssl->IOCB_ReadCtx = &ssl->rfd; - ssl->IOCB_WriteCtx = &ssl->wfd; #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { ssl->IOCB_ReadCtx = &ssl->buffers.dtlsCtx; - ssl->IOCB_WriteCtx = &ssl->buffers.dtlsCtx; - ssl->buffers.dtlsCtx.fd = fd; + ssl->buffers.dtlsCtx.rfd = fd; } #endif - WOLFSSL_LEAVE("SSL_set_fd", SSL_SUCCESS); + WOLFSSL_LEAVE("SSL_set_read_fd", SSL_SUCCESS); + return SSL_SUCCESS; +} + + +int wolfSSL_set_write_fd(WOLFSSL* ssl, int fd) +{ + WOLFSSL_ENTER("SSL_set_write_fd"); + + if (ssl == NULL) { + return BAD_FUNC_ARG; + } + + ssl->wfd = fd; /* not used directly to allow IO callbacks */ + ssl->IOCB_WriteCtx = &ssl->wfd; + + #ifdef WOLFSSL_DTLS + if (ssl->options.dtls) { + ssl->IOCB_WriteCtx = &ssl->buffers.dtlsCtx; + ssl->buffers.dtlsCtx.wfd = fd; + } + #endif + + WOLFSSL_LEAVE("SSL_set_write_fd", SSL_SUCCESS); return SSL_SUCCESS; } diff --git a/wolfssl/internal.h b/wolfssl/internal.h index 6e9b5f559..a6a229d2d 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -1585,7 +1585,8 @@ struct WOLFSSL_SOCKADDR { typedef struct WOLFSSL_DTLS_CTX { WOLFSSL_SOCKADDR peer; - int fd; + int rfd; + int wfd; } WOLFSSL_DTLS_CTX; diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 8404ccff2..b68669e16 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -328,6 +328,8 @@ WOLFSSL_API int wolfSSL_use_RSAPrivateKey_file(WOLFSSL*, const char*, int); WOLFSSL_API WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*); WOLFSSL_API WOLFSSL* wolfSSL_new(WOLFSSL_CTX*); WOLFSSL_API int wolfSSL_set_fd (WOLFSSL*, int); +WOLFSSL_API int wolfSSL_set_write_fd (WOLFSSL*, int); +WOLFSSL_API int wolfSSL_set_read_fd (WOLFSSL*, int); WOLFSSL_API char* wolfSSL_get_cipher_list(int priority); WOLFSSL_API int wolfSSL_get_ciphers(char*, int); WOLFSSL_API const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);