From 5797027e9f1610376eddd0f221fb20e11b89148a Mon Sep 17 00:00:00 2001 From: Aaron Jones Date: Fri, 16 Sep 2016 13:32:30 +0000 Subject: [PATCH] GNUTLS: Add dedicated socket send/recv functions This avoids a compiler warning regarding casting a file descriptor to a pointer (as input to gnutls_transport_set_ptr()), and also ensures that the pointer is valid for the lifetime of the session. --- libratbox/src/gnutls.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libratbox/src/gnutls.c b/libratbox/src/gnutls.c index 55211b8b..a2416f9f 100644 --- a/libratbox/src/gnutls.c +++ b/libratbox/src/gnutls.c @@ -73,6 +73,9 @@ struct ssl_connect static void rb_ssl_connect_realcb(rb_fde_t *, int, struct ssl_connect *); +static ssize_t rb_sock_net_recv(gnutls_transport_ptr_t, void *, size_t); +static ssize_t rb_sock_net_xmit(gnutls_transport_ptr_t, const void *, size_t); + /* @@ -111,6 +114,22 @@ rb_ssl_cert_auth_cb(gnutls_session_t session, return 0; } +static ssize_t +rb_sock_net_recv(gnutls_transport_ptr_t context_ptr, void *const buf, const size_t count) +{ + const int fd = rb_get_fd((rb_fde_t *)context_ptr); + + return recv(fd, buf, count, 0); +} + +static ssize_t +rb_sock_net_xmit(gnutls_transport_ptr_t context_ptr, const void *const buf, const size_t count) +{ + const int fd = rb_get_fd((rb_fde_t *)context_ptr); + + return send(fd, buf, count, 0); +} + static void rb_ssl_init_fd(rb_fde_t *const F, const rb_fd_tls_direction dir) { @@ -141,6 +160,10 @@ rb_ssl_init_fd(rb_fde_t *const F, const rb_fd_tls_direction dir) gnutls_dh_set_prime_bits(SSL_P(F), 1024); gnutls_priority_set(SSL_P(F), default_priority); + gnutls_transport_set_ptr(SSL_P(F), (gnutls_transport_ptr_t) F); + gnutls_transport_set_pull_function(SSL_P(F), rb_sock_net_recv); + gnutls_transport_set_push_function(SSL_P(F), rb_sock_net_xmit); + if(dir == RB_FD_TLS_DIRECTION_IN) gnutls_certificate_server_set_request(SSL_P(F), GNUTLS_CERT_REQUEST); }