From 13fb362d12a7b6d83e53a6e45a911814a0d25a5b Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 11 Dec 2020 16:38:17 +0100 Subject: [PATCH] Implemented BIOs --- src/client.c | 5 +++++ src/necronda-server.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/client.c b/src/client.c index 65c60d7..33e0c8b 100644 --- a/src/client.c +++ b/src/client.c @@ -47,6 +47,8 @@ int client_connection_handler(sock *client) { if (client->enc) { client->ssl = SSL_new(client->ctx); SSL_set_fd(client->ssl, client->socket); + SSL_set_accept_state(client->ssl); + SSL_set_bio(client->ssl, client->bio_in, client->bio_out); ret = SSL_accept(client->ssl); if (ret <= 0) { @@ -58,6 +60,9 @@ int client_connection_handler(sock *client) { close: if (client->enc) { SSL_shutdown(client->ssl); + SSL_free(client->ssl); + BIO_free(client->bio_in); + BIO_free(client->bio_out); } shutdown(client->socket, SHUT_RDWR); close(client->socket); diff --git a/src/necronda-server.c b/src/necronda-server.c index 66971e5..37e8e87 100644 --- a/src/necronda-server.c +++ b/src/necronda-server.c @@ -200,6 +200,11 @@ int main(int argc, const char *argv[]) { return 1; } + client.bio_in = BIO_new(BIO_s_mem()); + client.bio_out = BIO_new(BIO_s_mem()); + BIO_set_mem_eof_return(client.bio_in, -1); + BIO_set_mem_eof_return(client.bio_out, -1); + for (int i = 0; i < NUM_SOCKETS; i++) { if (listen(SOCKETS[i], LISTEN_BACKLOG) == -1) { fprintf(stderr, ERR_STR "Unable to listen on socket %i: %s" CLR_STR "\n", i, strerror(errno));