Skip to content

Commit

Permalink
Move should_trigger_renegotiation into its own function
Browse files Browse the repository at this point in the history
The if statement has become quite large and unreadable. Reformat it
and move it to a separate function.

Change-Id: I210fa255921e7115bd66ba5f3e431562552e3335
Signed-off-by: Arne Schwabe <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg29740.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
schwabe authored and cron2 committed Nov 11, 2024
1 parent 648e160 commit a4d0de1
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/openvpn/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2962,8 +2962,42 @@ tls_process_state(struct tls_multi *multi,
return true;
}

/**
* Determines if a renegotiation should be triggerred based on the various
* factors that can trigger one
*/
static bool
should_trigger_renegotiation(const struct tls_session *session, const struct key_state *ks)
{
/* Time limit */
if (session->opt->renegotiate_seconds
&& now >= ks->established + session->opt->renegotiate_seconds)
{
return true;
}

/* Byte limit */
if (session->opt->renegotiate_bytes > 0
&& ks->n_bytes >= session->opt->renegotiate_bytes)
{
return true;
}

/* Packet limit */
if (session->opt->renegotiate_packets
&& ks->n_packets >= session->opt->renegotiate_packets)
{
return true;
}

/* Packet id approach the limit of the packet id */
if (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send))
{
return true;
}

return false;
}
/*
* This is the primary routine for processing TLS stuff inside the
* the main event loop. When this routine exits
Expand Down Expand Up @@ -2991,13 +3025,7 @@ tls_process(struct tls_multi *multi,

/* Should we trigger a soft reset? -- new key, keeps old key for a while */
if (ks->state >= S_GENERATED_KEYS
&& ((session->opt->renegotiate_seconds
&& now >= ks->established + session->opt->renegotiate_seconds)
|| (session->opt->renegotiate_bytes > 0
&& ks->n_bytes >= session->opt->renegotiate_bytes)
|| (session->opt->renegotiate_packets
&& ks->n_packets >= session->opt->renegotiate_packets)
|| (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send))))
&& should_trigger_renegotiation(session, ks))
{
msg(D_TLS_DEBUG_LOW, "TLS: soft reset sec=%d/%d bytes=" counter_format
"/%d pkts=" counter_format "/%d",
Expand Down

0 comments on commit a4d0de1

Please sign in to comment.