From 6c10fd5e3e563791008a22803a536e7436fee073 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Mon, 8 Jun 2020 01:20:31 +0200 Subject: log_bin2hex_sodium cares about logging prio set, fixed missing cleanup on bufferevent failure Signed-off-by: Toni Uhlig --- common-sodium.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'common-sodium.c') diff --git a/common-sodium.c b/common-sodium.c index a69196d..1f3c88e 100644 --- a/common-sodium.c +++ b/common-sodium.c @@ -4,11 +4,15 @@ #include "logging.h" #include "protocol.h" -void log_bin2hex_sodium(char const * const prefix, uint8_t const * const buffer, size_t size) +void log_bin2hex_sodium(enum log_priority log_prio, char const * const prefix, + uint8_t const * const buffer, size_t size) { char hexstr[2 * size + 1]; - LOG(NOTICE, "%s: %s", prefix, sodium_bin2hex(hexstr, sizeof(hexstr), buffer, size)); - sodium_memzero(hexstr, sizeof(hexstr)); + + if (log_prio >= lower_prio) { + LOG(log_prio, "%s: %s", prefix, sodium_bin2hex(hexstr, sizeof(hexstr), buffer, size)); + sodium_memzero(hexstr, sizeof(hexstr)); + } } struct longterm_keypair * generate_keypair_sodium(void) @@ -84,8 +88,8 @@ int generate_session_keypair_sodium(struct connection * const state) return 1; } - log_bin2hex_sodium("Generated session rx key", state->session_keys->rx, crypto_kx_SESSIONKEYBYTES); - log_bin2hex_sodium("Generated session tx key", state->session_keys->tx, crypto_kx_SESSIONKEYBYTES); + log_bin2hex_sodium(NOTICE, "Generated session rx key", state->session_keys->rx, crypto_kx_SESSIONKEYBYTES); + log_bin2hex_sodium(NOTICE, "Generated session tx key", state->session_keys->tx, crypto_kx_SESSIONKEYBYTES); return 0; } -- cgit v1.2.3