diff --git a/Makefile b/Makefile index d7a2cbd..e037cf6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ INSTALL_PREFIX := /usr/local/ CFLAGS := -Wall -Wextra -Wshadow -Wswitch -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Werror=implicit-function-declaration -Werror=format -Wno-unused-parameter CFLAGS += -O3 -std=c11 -pthread -D_POSIX_SOURCE -D_XOPEN_SOURCE=500 -DBUILD_REVISION='"$(BUILD_REVISION)"' CFLAGS += `pkg-config --cflags openssl` -CFLAGS += -ggdb3 -DDEBUG -fsanitize=address -fsanitize=undefined -fsanitize=leak +#CFLAGS += -ggdb3 -DDEBUG -fsanitize=address -fsanitize=undefined -fsanitize=leak PYPGMOPTS := ../Python/pypgmopts/pypgmopts LDFLAGS := `pkg-config --libs openssl` diff --git a/openssl.c b/openssl.c index 4337043..7881412 100644 --- a/openssl.c +++ b/openssl.c @@ -91,21 +91,15 @@ bool create_generic_tls_context(struct generic_tls_ctx_t *gctx, bool server) { return false; } - /* In the cipher suite we're using, none of these should be used anyways - * (PSK); however for the future we want to have proper crypto here as - * well. */ -#if 0 - if (!SSL_CTX_set1_sigalgs_list(gctx->ctx, "ECDSA+SHA256:RSA+SHA256:ECDSA+SHA384:RSA+SHA384:ECDSA+SHA512:RSA+SHA512")) { + if (!SSL_CTX_set1_sigalgs_list(gctx->ctx, "ed448:ed25519")) { log_openssl(LLVL_FATAL, "Cannot set TLS generic context signature algorithms."); return false; } -#endif if (!SSL_CTX_set1_curves_list(gctx->ctx, "X448:X25519")) { log_openssl(LLVL_FATAL, "Cannot set TLS generic context ECDHE curves."); return false; } - return true; } diff --git a/server.c b/server.c index 4c31b63..e0f711c 100644 --- a/server.c +++ b/server.c @@ -308,9 +308,12 @@ static int psk_server_callback(SSL *ssl, const unsigned char *identity, size_t i fprintf(stderr, "PSK server SSL %p identity %s len %ld sess %p\n", ssl, identity, identity_len, *sessptr); SSL_SESSION *sess = SSL_SESSION_new(); SSL_SESSION_set1_master_key(sess, (const unsigned char*)"\x00\x11\x22", 3); - SSL_SESSION_set_cipher(sess, SSL_get_pending_cipher(ssl)); - //const SSL_CIPHER *cipher = SSL_CIPHER_find(ssl, TLS13_AES_256_GCM_SHA384_BYTES); - //SSL_SESSION_set_cipher(sess, cipher); + const unsigned char tls13_aes128gcmsha256_id[] = { 0x13, 0x01 }; + const SSL_CIPHER *cipher = SSL_CIPHER_find(ssl, tls13_aes128gcmsha256_id); + if (!cipher) { + return 0; + } + SSL_SESSION_set_cipher(sess, cipher); SSL_SESSION_set_protocol_version(sess, TLS1_3_VERSION); *sessptr = sess; return 1; @@ -331,8 +334,18 @@ static void *client_handler_thread(void *vctx) { ERR_print_errors_fp(stderr); } else { log_msg(LLVL_DEBUG, "Client connected, waiting for data..."); + while (true) { + struct msg_t msg; + int rxlen = SSL_read(ssl, &msg, sizeof(msg)); + if (rxlen != sizeof(msg)) { + log_msg(LLVL_WARNING, "Tried to read message of %d bytes, recevied %d. Severing connection to client.", sizeof(msg), rxlen); + break; + } + } + fprintf(stderr, "done\n"); } + SSL_free(ssl); shutdown(client->fd, SHUT_RDWR); close(client->fd); free(client); @@ -348,6 +361,9 @@ bool keyserver_start(const struct pgmopts_server_t *opts) { SSL_CTX_set_psk_find_session_callback(gctx.ctx, psk_server_callback); + if (!SSL_CTX_use_psk_identity_hint(gctx.ctx, "watwatwat")) { + } + int tcp_sock = create_tcp_server_socket(opts->port); if (tcp_sock == -1) { log_msg(LLVL_ERROR, "Cannot start server without server socket.");