Skip to content
Closed
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
25 changes: 24 additions & 1 deletion src/ranch_ssl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ do_listen(SocketOpts0, Logger) ->
SocketOpts1 = ranch:set_option_default(SocketOpts0, backlog, 1024),
SocketOpts2 = ranch:set_option_default(SocketOpts1, nodelay, true),
SocketOpts3 = ranch:set_option_default(SocketOpts2, send_timeout, 30000),
SocketOpts = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
SocketOpts4 = ranch:set_option_default(SocketOpts3, send_timeout_close, true),
SocketOpts = strip_unsupported_options(SocketOpts4),
%% We set the port to 0 because it is given in the Opts directly.
%% The port in the options takes precedence over the one in the
%% first argument.
Expand Down Expand Up @@ -296,3 +297,25 @@ cleanup(#{socket_opts:=SocketOpts}) ->
end;
cleanup(_) ->
ok.

-spec strip_unsupported_options(opts()) -> opts().
strip_unsupported_options(SocketOpts) ->
Versions1 = lists:keyfind(versions, 1, SocketOpts),
Versions2 = lists:keyfind(protocol_versions, 1, SocketOpts),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protocol_versions is not in SocketOpts but in the environment of the ssl application

application:get_env(ssl, protocol_versions)

If versions is given in SocketOpts, it overrides protocol_versions from the application environment.

if
(Versions1 == {versions, ['tlsv1.3']}) or (Versions2 == {protocol_versions, ['tlsv1.3']}) ->
NewSocketOpts = lists:filter(fun({X, _}) ->
(X /= secure_renegotiate) and (X /= reuse_sessions) and (X /= next_protocols_advertised) and (X /= alpn_preferred_protocols);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to do it this way (and I'm pretty sure that @essen will object 😅), you should use andalso. But it may be better to have individual clauses for each, so you could log what you found and dropped along the way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to log what is dropped indeed.

(_) ->
true
end, SocketOpts),
if
NewSocketOpts /= SocketOpts ->
error_logger:warning_msg("~p~n dropping options unsupported by TLS1.3-only ssl sockets: " ++
"secure_renegotiate, reuse_sessions, next_protocols_advertised and/or alpn_preferred_protocols from ~p~n", [?MODULE, SocketOpts])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not use error_logger directly here (or logger, for that matter), but ranch:log/3 with the value from the logger key in TransOpts (as given to ranch_ssl: listen).

Also, the message is at the same time very verbose and doesn't tell very much, ie which options were actually dropped.

end,
NewSocketOpts;
true ->
SocketOpts
end.