tls: make state progression monotonic

In TLS 1.2 and 1.3 the Finished message precedes the application
data on both directions. The DATA milestone write is keyed on the
parsed certificate subjects and runs on every record, so the first
record after the handshake - for a session that ends with a fatal
alert, the alert itself - moved the tracks backwards (client 4->3,
server 5->4). The completion states were therefore not absorbing:
the finished hook windows were transient in decryption mode, and a
keyword registered at progress >= 3 would have its eof revoked and
be suppressed by the stored CANT_MATCH flag.

The setters now only move a state forward, so post-terminal writes
are no-ops and the finished states absorb.

Ticket: #9047.
pull/16368/head
Victor Julien 2 months ago
parent 819c61265d
commit d286197519

@ -348,24 +348,30 @@ static uint64_t SSLGetTxCnt(void *state)
static void UpdateClientState(SSLState *ssl_state, enum TlsStateClient s)
{
/* monotonic: a late app-data write must not move the state back */
if (s > ssl_state->client_state) {
#ifdef DEBUG
enum TlsStateClient old = ssl_state->client_state;
enum TlsStateClient old = ssl_state->client_state;
#endif
ssl_state->client_state = s;
ssl_state->client_state = s;
#ifdef DEBUG
SCLogDebug("toserver: state updated to %u from %u", s, old);
SCLogDebug("toserver: state updated to %u from %u", s, old);
#endif
}
}
static void UpdateServerState(SSLState *ssl_state, enum TlsStateServer s)
{
/* monotonic: a late app-data write must not move the state back */
if (s > ssl_state->server_state) {
#ifdef DEBUG
enum TlsStateServer old = ssl_state->server_state;
enum TlsStateServer old = ssl_state->server_state;
#endif
ssl_state->server_state = s;
ssl_state->server_state = s;
#ifdef DEBUG
SCLogDebug("toclient: state updated to %u from %u", s, old);
SCLogDebug("toclient: state updated to %u from %u", s, old);
#endif
}
}
static int SSLGetAlstateProgress(void *tx, uint8_t direction)

Loading…
Cancel
Save