Skip to content

fix for TLS 1.3 #63

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions lib/plug/cowboy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,21 @@ defmodule Plug.Cowboy do
:https ->
%{socket_opts: socket_opts} = transport_opts

socket_opts =
socket_opts
|> Keyword.put_new(:next_protocols_advertised, ["h2", "http/1.1"])
|> Keyword.put_new(:alpn_preferred_protocols, ["h2", "http/1.1"])

{:ranch_ssl, :cowboy_tls, %{transport_opts | socket_opts: socket_opts}}
updated_opts =
if socket_opts[:versions] == [:"tlsv1.3"] do
# next_protocols_advertised and alpn_preferred_protocols options are not supported
# by the OTP SSL module when earlier version of TLS are not being used.
# (i.e. TLS1.2 or earlier versions must be specified as it's not supported in TLS1.3)
socket_opts
|> Keyword.delete(:next_protocols_advertised)
|> Keyword.delete(:alpn_preferred_protocols)
else
socket_opts
|> Keyword.put_new(:next_protocols_advertised, ["h2", "http/1.1"])
|> Keyword.put_new(:alpn_preferred_protocols, ["h2", "http/1.1"])
end

{:ranch_ssl, :cowboy_tls, %{transport_opts | socket_opts: updated_opts}}
end

{id, start, restart, shutdown, type, modules} =
Expand Down