Skip to content

fix for TLS 1.3 #1011

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

Closed
wants to merge 2 commits into from
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
15 changes: 12 additions & 3 deletions lib/plug/ssl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,18 @@ defmodule Plug.SSL do
end

defp set_secure_defaults(options) do
options
|> Keyword.put_new(:secure_renegotiate, true)
|> Keyword.put_new(:reuse_sessions, true)
if options[:versions] == [:"tlsv1.3"] do
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it should check whether the options contain earlier versions instead, as I assume that if there will ever be TLSv1.4 it will not support these options as well.

Copy link
Contributor

@voltone voltone Jun 13, 2022

Choose a reason for hiding this comment

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

I agree, this should probably be something like:

Suggested change
if options[:versions] == [:"tlsv1.3"] do
if !Enum.any?([:tlsv1, :"tlsv1.1", :"tlsv1.2"], &(&1 in options[:versions])) do

(Or rather, swap the do and else parts, and remove the negation)

No point in doing a MapSet dance here, is there? This is typically checked just once on server startup...

Copy link
Member

Choose a reason for hiding this comment

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

Does :versions have to be set? I think that may not be the case.

Suggested change
if options[:versions] == [:"tlsv1.3"] do
versions = options[:versions]
if versions && not Enum.any?(...) do

WDYT?

Copy link
Contributor

@voltone voltone Jun 13, 2022

Choose a reason for hiding this comment

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

I was wondering the same thing. But if it's not set, then we don't know whether these options should be set or not. For that I think we'd have to pick up the default with :ssl.versions()[:supported]...

Suggested change
if options[:versions] == [:"tlsv1.3"] do
versions = Keyword.get(options, :versions, :ssl.versions()[:supported])
if not Enum.any?(...) do

Another thing: technically :ssl options are not a proplist, so not sure we're supposed to use Keyword on it?

# secure_renegotiate and reuse_sessions options are not supported
# by the OTP SSL module when earlier versions of TLS are not being used.
# (i.e. TLS1.2 or earlier versions must be specified as it's not supported in TLS1.3)
options
|> Keyword.delete(:secure_renegotiate)
|> Keyword.delete(:reuse_sessions)
else
options
|> Keyword.put_new(:secure_renegotiate, true)
|> Keyword.put_new(:reuse_sessions, true)
end
end

defp configure_managed_tls(options) do
Expand Down