Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid misleading error information for delayed TLS 1.3 alerts #341

Open
JeppeTh opened this issue Nov 5, 2024 · 8 comments
Open

Avoid misleading error information for delayed TLS 1.3 alerts #341

JeppeTh opened this issue Nov 5, 2024 · 8 comments
Milestone

Comments

@JeppeTh
Copy link

JeppeTh commented Nov 5, 2024

When it comes to mTLS TLS 1.3 is not very well designed since the client considers the handshake to be successful before the server has performed it's verification of the client.

If that verification fails it means that the client will receive the TLS alert after ssl:connect has successfully returned.
For such case socket operations like send, setopts etc. will return {error, closed | einval} instead of the tls_alert().
This all leads to that the Gun users get misleading failures.

This can be solved by letting gun check it's message queue for {ssl_error, Socket, tls_alert()} when failing with closed | einval.
Needs to be done with a short timeout since the error can be returned before the process receives the alert.

Requires active mode from the start (at least it makes things simpler).

To avoid delay of normal close this can be avoided if TLS 1.3 isn't a candidate, or if the socket has been confirmed (=data received).

@essen
Copy link
Member

essen commented Nov 5, 2024

Can you prepare a small example using only the ssl application?

@JeppeTh
Copy link
Author

JeppeTh commented Nov 5, 2024

You meant how to reproduce right? I made some simple example
delayed_tls_alert.tar.gz

Example output:

48> delayed_tls_alert:run(4004).
delayed_tls_alert:run(4004).
Client successfully connected
send result: ok
send result: ok
send result: ok
Server Handshake result:{error,
{tls_alert,
{certificate_required,
"TLS server: In state wait_cert at tls_handshake_1_3.erl:1485 generated SERVER ALERT: Fatal - Certificate required\n certificate_required"}}}
send result: {error,closed}
{error,closed}

@essen
Copy link
Member

essen commented Nov 5, 2024

Yes, thank you.

@essen
Copy link
Member

essen commented Nov 6, 2024

I don't think we need to do anything about this, as this has been fixed in OTP in erlang/otp#8823

@JeppeTh
Copy link
Author

JeppeTh commented Nov 6, 2024 via email

@essen
Copy link
Member

essen commented Nov 6, 2024

Let me see with OTP team if this should be done for more functions.

@JeppeTh
Copy link
Author

JeppeTh commented Nov 6, 2024 via email

@JeppeTh
Copy link
Author

JeppeTh commented Nov 6, 2024

I updated my example a bit - additional example output of some function calls. I also added a receive in the end to check if there's an alert in the queue

59> delayed_tls_alert:run(4004).
delayed_tls_alert:run(4004).
Client successfully connected
Server Handshake result:{error,
{tls_alert,
{certificate_required,
"TLS server: In state wait_cert at tls_handshake_1_3.erl:1485 generated SERVER ALERT: Fatal - Certificate required\n certificate_required"}}}
ssl:negotiated_protocol returned {error,closed}
ssl:setopts returned {error,closed}
ssl:connection_information returned: {error,closed}
ssl:send returned {error,closed}
Received {tls_alert,{certificate_required,[84,76,83,32,99,108,105,101,110,116,58,32,73,110,32,115,116,97,116,101,32,99,111,110,110,101,99,116,105,111,110,32,114,101,99,101,105,118,101,100,32,83,69,82,86,69,82,32,65,76,69,82,84,58,32,70,97,116,97,108,32,45,32,67,101,114,116,105,102,105,99,97,116,101,32,114,101,113,117,105,114,101,100,10]}} after 0ms

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

No branches or pull requests

2 participants