diff --git a/Makefile b/Makefile index bd5a664..f275d14 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ clean: rm -f $(OBJS) $(OBJS_CFG) luksrku test: luksrku - ./luksrku -v --server-mode -k server_key.bin + ./luksrku server -vv base gdb: luksrku gdb --args ./luksrku -v --server-mode -k server_key.bin diff --git a/log.c b/log.c index 1ce4984..5e9dbc1 100644 --- a/log.c +++ b/log.c @@ -30,7 +30,7 @@ #include "log.h" -static enum loglvl_t current_loglvl = LLVL_INFO; +static enum loglvl_t current_loglvl = LOGLEVEL_DEFAULT; static const char *loglvl_names[] = { [LLVL_FATAL] = "FATAL", [LLVL_ERROR] = "ERROR", diff --git a/log.h b/log.h index bf5c57e..703dc6b 100644 --- a/log.h +++ b/log.h @@ -24,6 +24,8 @@ #ifndef __LOG_H__ #define __LOG_H__ +#define LOGLEVEL_DEFAULT LLVL_INFO + enum loglvl_t { LLVL_FATAL = 0, LLVL_ERROR = 1, diff --git a/luksrku.c b/luksrku.c index dd16028..bd53a5c 100644 --- a/luksrku.c +++ b/luksrku.c @@ -37,10 +37,12 @@ #endif static int main_edit(const struct pgmopts_edit_t *opts) { + log_setlvl(LOGLEVEL_DEFAULT + opts->verbosity); return editor_start(opts) ? 0 : 1; } static int main_server(const struct pgmopts_server_t *opts) { + log_setlvl(LOGLEVEL_DEFAULT + opts->verbosity); return keyserver_start(opts) ? 0 : 1; } diff --git a/pgmopts.c b/pgmopts.c index ab1d6b9..80f4cbb 100644 --- a/pgmopts.c +++ b/pgmopts.c @@ -30,8 +30,7 @@ #include "argparse_edit.h" #include "argparse_server.h" -static struct pgmopts_t pgmopts_rw = { -}; +static struct pgmopts_t pgmopts_rw; const struct pgmopts_t *pgmopts = &pgmopts_rw; static void show_syntax(const char *errmsg, int argc, char **argv) { @@ -48,9 +47,6 @@ static void show_syntax(const char *errmsg, int argc, char **argv) { } static bool edit_callback(enum argparse_edit_option_t option, const char *value, argparse_edit_errmsg_callback_t errmsg_callback) { - pgmopts_rw.edit = (struct pgmopts_edit_t){ - .verbosity = ARGPARSE_EDIT_DEFAULT_VERBOSE, - }; switch (option) { case ARG_EDIT_FILENAME: pgmopts_rw.edit.filename = value; @@ -64,11 +60,6 @@ static bool edit_callback(enum argparse_edit_option_t option, const char *value, } static bool server_callback(enum argparse_server_option_t option, const char *value, argparse_server_errmsg_callback_t errmsg_callback) { - pgmopts_rw.server = (struct pgmopts_server_t){ - .port = ARGPARSE_SERVER_DEFAULT_PORT, - .verbosity = ARGPARSE_SERVER_DEFAULT_VERBOSE, - .answer_udp_queries = true, - }; switch (option) { case ARG_SERVER_FILENAME: pgmopts_rw.server.filename = value; @@ -90,10 +81,18 @@ static bool server_callback(enum argparse_server_option_t option, const char *va } static void parse_pgmopts_edit(int argc, char **argv) { + pgmopts_rw.edit = (struct pgmopts_edit_t){ + .verbosity = ARGPARSE_EDIT_DEFAULT_VERBOSE, + }; argparse_edit_parse_or_quit(argc - 1, argv + 1, edit_callback, NULL); } static void parse_pgmopts_server(int argc, char **argv) { + pgmopts_rw.server = (struct pgmopts_server_t){ + .port = ARGPARSE_SERVER_DEFAULT_PORT, + .verbosity = ARGPARSE_SERVER_DEFAULT_VERBOSE, + .answer_udp_queries = true, + }; argparse_server_parse_or_quit(argc - 1, argv + 1, server_callback, NULL); } diff --git a/server.c b/server.c index 22a41f6..e71258c 100644 --- a/server.c +++ b/server.c @@ -355,26 +355,33 @@ static int psk_server_callback(SSL *ssl, const unsigned char *identity, size_t i return 0; } - if (!SSL_SESSION_set1_master_key(sess, ctx->host->tls_psk, PSK_SIZE_BYTES)) { - log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK master key."); - SSL_SESSION_free(sess); - return 0; - } + int return_value = 1; + do { + if (!SSL_SESSION_set1_master_key(sess, ctx->host->tls_psk, PSK_SIZE_BYTES)) { + log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK master key."); + return_value = 0; + break; + } - if (!SSL_SESSION_set_cipher(sess, cipher)) { - log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK cipher."); - SSL_SESSION_free(sess); - return 0; - } + if (!SSL_SESSION_set_cipher(sess, cipher)) { + log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK cipher."); + return_value = 0; + break; + } - if (!SSL_SESSION_set_protocol_version(sess, TLS1_3_VERSION)) { - log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK protocol version."); - SSL_SESSION_free(sess); - return 0; - } + if (!SSL_SESSION_set_protocol_version(sess, TLS1_3_VERSION)) { + log_openssl(LLVL_ERROR, "Failed to set TLSv1.3-PSK protocol version."); + return_value = 0; + break; + } + } while (false); - *sessptr = sess; - return 1; + if (return_value) { + *sessptr = sess; + } else { + SSL_SESSION_free(sess); + } + return return_value; } static void client_handler_thread(void *vctx) { @@ -388,7 +395,7 @@ static void client_handler_thread(void *vctx) { ERR_print_errors_fp(stderr); } else { if (client->host) { - log_msg(LLVL_DEBUG, "Client \"%s\" connected, sending unlock data for %d volumes...", client->host->host_name, client->host->volume_count); + log_msg(LLVL_DEBUG, "Client \"%s\" connected, sending unlock data for %d volumes.", client->host->host_name, client->host->volume_count); for (unsigned int i = 0; i < client->host->volume_count; i++) { const struct volume_entry_t *volume = &client->host->volumes[i];