Skip to content

Always use system certificates #13052

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

Merged
merged 3 commits into from
Nov 1, 2023
Merged
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
24 changes: 7 additions & 17 deletions lib/mix/lib/mix/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -655,23 +655,13 @@ defmodule Mix.Utils do
headers = [{~c"user-agent", ~c"Mix/#{System.version()}"}]
request = {:binary.bin_to_list(path), headers}

# Use the system certificates if available, otherwise skip peer verification
# TODO: Always use system certificates when OTP >= 25.1 is required
ssl_options =
if Code.ensure_loaded?(:httpc) and function_exported?(:httpc, :ssl_verify_host_options, 1) do
try do
apply(:httpc, :ssl_verify_host_options, [true])
rescue
_ ->
Mix.shell().error(
"warning: failed to load system certificates. SSL peer verification will be skipped but downloads are still verified with a checksum"
)

[verify: :verify_none]
end
else
[verify: :verify_none]
end
# Use the system certificates
# TODO: use `ssl_options = :httpc.ssl_verify_host_options(true)` on Erlang/OTP 26+
ssl_options = [
verify: :verify_peer,
cacerts: :public_key.cacerts_get(),
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]
]
Comment on lines +660 to +664
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original for comparison:

ssl_verify_host_options(WildcardHostName) ->
    WildCard = case WildcardHostName of
                   true ->
                       Fun = public_key:pkix_verify_hostname_match_fun(https),
                       [{customize_hostname_check,[{match_fun, Fun}]}];
                   false ->
                       []
               end,
    [{verify, verify_peer}, {cacerts, public_key:cacerts_get()} | WildCard].


# We are using relaxed: true because some servers is returning a Location
# header with relative paths, which does not follow the spec. This would
Expand Down