From 7ef2fe7f7b21e295c296fa384df9f40a19ab0b18 Mon Sep 17 00:00:00 2001 From: Jon Simons Date: Wed, 24 Apr 2019 10:09:03 -0700 Subject: [PATCH] packet: log when data-based rekeying needed Log an SSH_LOG_PACKET debug message when rekeying is necessary due to the cipher max_blocks configuration. Signed-off-by: Jon Simons Reviewed-by: Andreas Schneider --- src/packet.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/packet.c b/src/packet.c index 6acd2835..9ae26289 100644 --- a/src/packet.c +++ b/src/packet.c @@ -961,6 +961,7 @@ ssh_packet_get_current_crypto(ssh_session session, static bool ssh_packet_need_rekey(ssh_session session, const uint32_t payloadsize) { + bool data_rekey_needed = false; struct ssh_crypto_struct *crypto = NULL; struct ssh_cipher_struct *out_cipher = NULL, *in_cipher = NULL; uint32_t next_blocks; @@ -1009,10 +1010,18 @@ static bool ssh_packet_need_rekey(ssh_session session, * signalize our intention to rekey */ next_blocks = payloadsize / out_cipher->blocksize; - return (out_cipher->max_blocks != 0 && - out_cipher->blocks + next_blocks > out_cipher->max_blocks) || - (in_cipher->max_blocks != 0 && - in_cipher->blocks + next_blocks > in_cipher->max_blocks); + data_rekey_needed = (out_cipher->max_blocks != 0 && + out_cipher->blocks + next_blocks > out_cipher->max_blocks) || + (in_cipher->max_blocks != 0 && + in_cipher->blocks + next_blocks > in_cipher->max_blocks); + + SSH_LOG(SSH_LOG_PACKET, + "packet: [data_rekey_needed=%d, out_blocks=%" PRIu64 ", in_blocks=%" PRIu64, + data_rekey_needed, + out_cipher->blocks + next_blocks, + in_cipher->blocks + next_blocks); + + return data_rekey_needed; } /* in nonblocking mode, socket_read will read as much as it can, and return */