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

fix: fast fail on invalid ssl options #191

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/esockd.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, esockd,
[{description, "General Non-blocking TCP/SSL and UDP/DTLS Server"},
{id, "esockd"},
{vsn, "5.9.7"},
{vsn, git},
{modules, []},
{registered, []},
{applications, [kernel, stdlib, sasl, ssl, public_key]},
Expand Down
6 changes: 5 additions & 1 deletion src/esockd_acceptor_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ ssl_upgrade_fun(Type, Opts) ->
end,
case proplists:get_value(Key, Opts) of
undefined -> [];
SslOpts -> [esockd_transport:ssl_upgrade_fun(SslOpts)]
SslOpts ->
%% validate ssl options and prevent the listener from starting if
%% validation failed
_ = ssl:handle_options(SslOpts, server, undefined),
[esockd_transport:ssl_upgrade_fun(SslOpts)]
end.

tune_socket(Sock, []) ->
Expand Down
7 changes: 4 additions & 3 deletions test/esockd_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,10 @@ t_update_tls_options(Config) ->
[{ssl_options, SslOpts1}, {connection_mfargs, echo_server}]),
{ok, Sock1} = ssl:connect("localhost", LPort, ClientSslOpts, 1000),

ok = esockd:set_options({echo_tls, LPort}, [{ssl_options, [{verify, verify_peer}]}]),
?assertEqual( {error, closed}
, ssl:connect("localhost", LPort, ClientSslOpts, 1000)),
?assertError(
{badmatch, _},
esockd:set_options({echo_tls, LPort}, [{ssl_options, [{verify, verify_peer}]}])
),

ok = esockd:set_options({echo_tls, LPort}, [{ssl_options, SslOpts2}]),
{ok, Sock2} = ssl:connect("localhost", LPort, ClientSslOpts, 1000),
Expand Down