@@ -286,141 +286,8 @@ defmodule ElixirMake.Artefact do
286286 end
287287 end
288288
289- ## Download
290-
291- def download ( url ) do
292- url_charlist = String . to_charlist ( url )
293-
294- # TODO: Remove me when we require Elixir v1.15
295- { :ok , _ } = Application . ensure_all_started ( :inets )
296- { :ok , _ } = Application . ensure_all_started ( :ssl )
297- { :ok , _ } = Application . ensure_all_started ( :public_key )
298-
299- if proxy = System . get_env ( "HTTP_PROXY" ) || System . get_env ( "http_proxy" ) do
300- Mix . shell ( ) . info ( "Using HTTP_PROXY: #{ proxy } " )
301- % { host: host , port: port } = URI . parse ( proxy )
302-
303- :httpc . set_options ( [ { :proxy , { { String . to_charlist ( host ) , port } , [ ] } } ] )
304- end
305-
306- if proxy = System . get_env ( "HTTPS_PROXY" ) || System . get_env ( "https_proxy" ) do
307- Mix . shell ( ) . info ( "Using HTTPS_PROXY: #{ proxy } " )
308- % { host: host , port: port } = URI . parse ( proxy )
309- :httpc . set_options ( [ { :https_proxy , { { String . to_charlist ( host ) , port } , [ ] } } ] )
310- end
311-
312- # https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/inets
313- # TODO: This may no longer be necessary from Erlang/OTP 25.0 or later.
314- https_options = [
315- ssl:
316- [
317- verify: :verify_peer ,
318- customize_hostname_check: [
319- match_fun: :public_key . pkix_verify_hostname_match_fun ( :https )
320- ]
321- ] ++ cacerts_options ( )
322- ]
323-
324- options = [ body_format: :binary ]
325-
326- case :httpc . request ( :get , { url_charlist , [ ] } , https_options , options ) do
327- { :ok , { { _ , 200 , _ } , _headers , body } } ->
328- { :ok , body }
329-
330- other ->
331- { :error , "couldn't fetch NIF from #{ url } : #{ inspect ( other ) } " }
332- end
333- end
334-
335- defp cacerts_options do
336- cond do
337- path = System . get_env ( "ELIXIR_MAKE_CACERT" ) ->
338- [ cacertfile: path ]
339-
340- certs = otp_cacerts ( ) ->
341- [ cacerts: certs ]
342-
343- Application . spec ( :castore , :vsn ) ->
344- [ cacertfile: Application . app_dir ( :castore , "priv/cacerts.pem" ) ]
345-
346- Application . spec ( :certifi , :vsn ) ->
347- [ cacertfile: Application . app_dir ( :certifi , "priv/cacerts.pem" ) ]
348-
349- path = cacerts_from_os ( ) ->
350- [ cacertfile: path ]
351-
352- true ->
353- warn_no_cacerts ( )
354- [ ]
355- end
356- end
357-
358- defp otp_cacerts do
359- if System . otp_release ( ) >= "25" do
360- # cacerts_get/0 raises if no certs found
361- try do
362- :public_key . cacerts_get ( )
363- rescue
364- _ ->
365- nil
366- end
367- end
368- end
369-
370- # https_opts and related code are taken from
371- # https://github.com/elixir-cldr/cldr_utils/blob/v2.19.1/lib/cldr/http/http.ex
372- @ certificate_locations [
373- # Debian/Ubuntu/Gentoo etc.
374- "/etc/ssl/certs/ca-certificates.crt" ,
375-
376- # Fedora/RHEL 6
377- "/etc/pki/tls/certs/ca-bundle.crt" ,
378-
379- # OpenSUSE
380- "/etc/ssl/ca-bundle.pem" ,
381-
382- # OpenELEC
383- "/etc/pki/tls/cacert.pem" ,
384-
385- # CentOS/RHEL 7
386- "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" ,
387-
388- # Open SSL on MacOS
389- "/usr/local/etc/openssl/cert.pem" ,
390-
391- # MacOS & Alpine Linux
392- "/etc/ssl/cert.pem"
393- ]
394-
395- defp cacerts_from_os do
396- Enum . find ( @ certificate_locations , & File . exists? / 1 )
397- end
398-
399- defp warn_no_cacerts do
400- Mix . shell ( ) . error ( """
401- No certificate trust store was found.
402-
403- Tried looking for: #{ inspect ( @ certificate_locations ) }
404-
405- A certificate trust store is required in
406- order to download locales for your configuration.
407- Since elixir_make could not detect a system
408- installed certificate trust store one of the
409- following actions may be taken:
410-
411- 1. Install the hex package `castore`. It will
412- be automatically detected after recompilation.
413-
414- 2. Install the hex package `certifi`. It will
415- be automatically detected after recompilation.
416-
417- 3. Specify the location of a certificate trust store
418- by configuring it in environment variable:
419-
420- export ELIXIR_MAKE_CACERT="/path/to/cacerts.pem"
421-
422- 4. Use OTP 25+ on an OS that has built-in certificate
423- trust store.
424- """ )
289+ def download ( config , url ) do
290+ downloader = config [ :make_precompiler_downloader ] || ElixirMake.Downloader.Httpc
291+ downloader . download ( url )
425292 end
426293end
0 commit comments