Skip to content

Commit 2b9d8b7

Browse files
moogle19josevalim
authored andcommitted
Add explicit :verify_none for httpc (#12485)
1 parent 4687556 commit 2b9d8b7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/mix/lib/mix/utils.ex

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,31 @@ defmodule Mix.Utils do
654654
headers = [{'user-agent', 'Mix/#{System.version()}'}]
655655
request = {:binary.bin_to_list(path), headers}
656656

657+
# Use the system certificates if available, otherwise skip peer verification
658+
# TODO: Always use system certificates when OTP >= 25 is required
659+
ssl_options =
660+
if Code.ensure_loaded?(:public_key) and function_exported?(:public_key, :cacerts_get, 0) do
661+
try do
662+
[cacerts: apply(:public_key, :cacerts_get, [])]
663+
rescue
664+
_ ->
665+
msg =
666+
"warning: Failed to load system certificates. Falling back to skip SSL peer verification."
667+
668+
Mix.shell().error(msg)
669+
[verify: :verify_none]
670+
end
671+
else
672+
[verify: :verify_none]
673+
end
674+
657675
# We are using relaxed: true because some servers is returning a Location
658676
# header with relative paths, which does not follow the spec. This would
659677
# cause the request to fail with {:error, :no_scheme} unless :relaxed
660678
# is given.
661679
#
662680
# If a proxy environment variable was supplied add a proxy to httpc.
663-
http_options = [relaxed: true] ++ proxy_config(path)
681+
http_options = [relaxed: true, ssl: ssl_options] ++ proxy_config(path)
664682

665683
# Silence the warning from OTP as we verify the contents
666684
level = Logger.level()

0 commit comments

Comments
 (0)