Skip to content

Catch post-handshake TLS 1.3 alerts#350

Closed
essen wants to merge 1 commit intomasterfrom
tls_alert_delayed
Closed

Catch post-handshake TLS 1.3 alerts#350
essen wants to merge 1 commit intomasterfrom
tls_alert_delayed

Conversation

@essen
Copy link
Copy Markdown
Member

@essen essen commented Apr 3, 2025

@essen essen force-pushed the tls_alert_delayed branch 5 times, most recently from c832f58 to b9d233c Compare April 9, 2025 14:45
When TLS 1.3 is used and `fail_if_no_peer_cert` (or equivalent)
is configured on the server, such as in mTLS scenarios, and
the client certificate is missing or invalid, the TLS 1.3 alert
will be sent after the handshake has completed.

The same is true for post-handshake authentication in TLS 1.3
which Erlang/OTP doesn't yet support, but will at some point in
the future.

Due to the asynchronous nature of some `ssl` socket operations,
such as sending, the alert may not always be returned from a
socket call. When the ssl socket is active we would receive
it as a message instead, so when Gun gets `{error,closed}`
it must look for the active message and see if an alert
occurred. When the ssl socket is passive we don't, so we
must query the socket for it (trying to set the socket active
at that point gets us the alert in the return value). There
is a span between handshake and the initial active mode set
where the socket is passive and may send data (the HTTP/2
preface) so we must account for both cases.

Because we sometimes have to wait for the alert as a message,
and we don't want to wait for a very long time (200ms), we
sometimes may lose the alert. Perhaps in the future this wait
time can be made configurable for users that really require
getting the alert.

The tests are only enabled on Linux because other OSes have
intermittent failures (likely due to timing).
@essen essen force-pushed the tls_alert_delayed branch from b9d233c to d4ef485 Compare April 9, 2025 15:07
@essen essen closed this Apr 9, 2025
@essen essen deleted the tls_alert_delayed branch April 9, 2025 15:19
@essen
Copy link
Copy Markdown
Member Author

essen commented Apr 9, 2025

Merged!!

@essen essen added this to the 2.2.0 milestone Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant