jgfdjgfd
Ranch: TLS 1.3 connections are successful even though handshake fails
Hi! I have an issue with a Ranch listener with client verification. In short, when using tls 1.2 it works as expected, but when using tls 1.3 clients always receive {:ok, socket}, even when the handshake process fails (i would have expected to receive {:error, {tls_alert, …}}. However, when trying to send to this socket, {:error, :closed} is received. Below is an example.
Listener:
def start_listener(opts) do
versions = Keyword.get(opts, :versions)
verify_fun = Keyword.get(opts, :verify_fun)
key = key()
cacerts = cacerts()
crt = cert()
socket_opts =
[
cacerts: cacerts,
key: key,
cert: crt,
versions: versions,
verify: :verify_peer,
fail_if_no_peer_cert: true,
verify_fun: {verify_fun, []},
port: 49665,
ciphers: :ssl.cipher_suites(:all,:'tlsv1.2') ++ :ssl.cipher_suites(:all,:'tlsv1.3')
]
opts = %{
connection_type: :supervisor,
socket_opts: socket_opts,
}
{:ok, _} = :ranch.start_listener(:Tls, :ranch_ssl, opts, Prot, cert_verification: true)
end
Client connection:
def connect(tls_versions) do
client_ca_cert = client_ca_cert()
{client_cert, client_key} = generate_cert()
:ssl.connect(
{127, 0, 0, 1},
49_665,
[
versions: tls_versions,
ciphers: :ssl.cipher_suites(:all,:'tlsv1.2') ++ :ssl.cipher_suites(:all,:'tlsv1.3'),
cacerts: [client_ca_cert],
key: {:RSAPrivateKey, client_key},
cert: client_cert,
]
)
end
When i try to connect with TLS 1.2 and a verify function that is guaranteed to fail it works as expected:
iex(1)> Listener.start_listener([versions: [:"tlsv1.2"], verify_fun: fn(_c, _r, _s) -> {:fail, :internal_error} end])
{:ok, #PID<0.207.0>}
iex(2)> Listener.connect([:"tlsv1.2"])
11:40:44.558 [warn] Description: 'Authenticity is not established by certificate path validation'
Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'
11:40:44.607 [info] TLS :server: In state :certify at ssl_handshake.erl:2017 generated SERVER ALERT: Fatal - Handshake Failure
- :internal_error
11:40:44.617 [info] TLS :client: In state :cipher received SERVER ALERT: Fatal - Handshake Failure
{:error,
{:tls_alert,
{:handshake_failure,
'TLS client: In state cipher received SERVER ALERT: Fatal - Handshake Failure\n'}}}
However, when doing the same with TLS 1.3, i get the successful message. It seems to be received before the handshake has failed:
iex(1)> Listener.start_listener([versions: [:"tlsv1.3"], verify_fun: fn(_c, _r, _s) -> {:fail, :internal_error} end])
{:ok, #PID<0.221.0>}
iex(2)> Listener.connect([:"tlsv1.3"])
11:42:51.559 [warn] Description: 'Authenticity is not established by certificate path validation'
Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'
{:ok,
{:sslsocket, {:gen_tcp, #Port<0.7>, :tls_connection, :undefined},
[#PID<0.240.0>, #PID<0.238.0>]}}
iex(3)>
11:42:51.640 [info] TLS :server: In state :wait_cert at ssl_handshake.erl:2017 generated SERVER ALERT: Fatal - Handshake Failure
- :internal_error
11:42:51.665 [info] TLS :client: In state :connection received SERVER ALERT: Fatal - Handshake Failure
Popular in Questions
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New







