Skip to content

Commit 536aa68

Browse files
committed
Fix DTLS
Options invalid for DTLS were given to ssl. Now they are only given for TLS. The {packet,raw} option is no longer set because the default for TLS is the equivalent {packet,0} and DTLS doesn't accept it.
1 parent 7335184 commit 536aa68

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/ranch_ssl.erl

+13-5
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,25 @@ listen(TransOpts) ->
135135
end.
136136

137137
do_listen(SocketOpts0, Logger) ->
138-
SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
139-
SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
140-
SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
141-
SocketOpts = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
138+
SocketOpts = set_default_options(SocketOpts0),
142139
DisallowedOpts0 = disallowed_listen_options(),
143140
DisallowedOpts = unsupported_tls_options(SocketOpts) ++ DisallowedOpts0,
144141
%% We set the port to 0 because it is given in the Opts directly.
145142
%% The port in the options takes precedence over the one in the
146143
%% first argument.
147144
ssl:listen(0, ranch:filter_options(SocketOpts, DisallowedOpts,
148-
[binary, {active, false}, {packet, raw}, {reuseaddr, true}], Logger)).
145+
[binary, {active, false}, {reuseaddr, true}], Logger)).
146+
147+
set_default_options(SocketOpts0) ->
148+
case proplists:get_value(protocol, SocketOpts0, tls) of
149+
tls ->
150+
SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
151+
SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
152+
SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
153+
ranch:set_option_default(SocketOpts3, send_timeout_close, true);
154+
dtls ->
155+
SocketOpts0
156+
end.
149157

150158
%% 'binary' and 'list' are disallowed but they are handled
151159
%% specifically as they do not have 2-tuple equivalents.

test/acceptor_SUITE.erl

+22
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ groups() ->
8383
ssl_active_n_echo,
8484
ssl_echo,
8585
ssl_local_echo,
86+
ssl_dtls_echo,
8687
ssl_graceful,
8788
ssl_handshake,
8889
ssl_handshake_error,
@@ -840,6 +841,27 @@ ssl_echo(_) ->
840841
{'EXIT', _} = begin catch ranch:get_port(Name) end,
841842
ok.
842843

844+
ssl_dtls_echo(_) ->
845+
doc("Ensure that passive mode works with SSL transport."),
846+
Name = name(),
847+
%% We are using DTLS so the version should be 'dtlsv1.2'.
848+
%% But since we don't really need it we simply don't set 'versions'.
849+
Opts = ct_helper:get_certs_from_ets() -- [{versions, ['tlsv1.2']}],
850+
{ok, _} = ranch:start_listener(Name,
851+
ranch_ssl, Opts ++ [{protocol, dtls}, {verify, verify_none}],
852+
echo_protocol, []),
853+
Port = ranch:get_port(Name),
854+
{ok, Socket} = ssl:connect("localhost", Port, [
855+
binary, {active, false}, {protocol, dtls},
856+
{verify, verify_none}]),
857+
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
858+
{ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
859+
ok = ranch:stop_listener(Name),
860+
{error, closed} = ssl:recv(Socket, 0, 1000),
861+
%% Make sure the listener stopped.
862+
{'EXIT', _} = begin catch ranch:get_port(Name) end,
863+
ok.
864+
843865
ssl_handshake(_) ->
844866
doc("Ensure that multiple steps handshake works with SSL transport."),
845867
Name = name(),

0 commit comments

Comments
 (0)