@@ -110,7 +110,8 @@ defmodule RustlerPrecompiled do
110110 * `HTTPS_PROXY` or `https_proxy` - Sets the HTTPS proxy configuration.
111111
112112 * `HEX_CACERTS_PATH` - Sets the path for a custom CA certificates file.
113- If unset, defaults to `CAStore.file_path/0`.
113+ If unset, defaults to `:public.cacerts_get/0` (OTP >= 25) if available.
114+ In case it's running on an old OTP version, a warning is emitted.
114115
115116 * `MIX_XDG` - If present, sets the OS as `:linux` for the `:filename.basedir/3` when getting
116117 an user cache dir.
@@ -926,21 +927,17 @@ defmodule RustlerPrecompiled do
926927 :httpc . set_options ( [ { :https_proxy , { { String . to_charlist ( host ) , port } , [ ] } } ] )
927928 end
928929
929- # https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/inets
930- # respects the user provided ca certs via Hex env var
931- cacertfile = System . get_env ( "HEX_CACERTS_PATH" , CAStore . file_path ( ) )
932-
933930 http_options = [
934- ssl: [
935- verify: :verify_peer ,
936- cacertfile: cacertfile |> String . to_charlist ( ) ,
937- # We need to increase depth because the default value is 1.
938- # See: https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl
939- depth: 3 ,
940- customize_hostname_check: [
941- match_fun: :public_key . pkix_verify_hostname_match_fun ( :https )
942- ]
943- ]
931+ ssl:
932+ [
933+ verify: :verify_peer ,
934+ # We need to increase depth because the default value is 1.
935+ # See: https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl
936+ depth: 3 ,
937+ customize_hostname_check: [
938+ match_fun: :public_key . pkix_verify_hostname_match_fun ( :https )
939+ ]
940+ ] ++ cacerts_options ( )
944941 ]
945942
946943 options = [ body_format: :binary ]
@@ -957,6 +954,52 @@ defmodule RustlerPrecompiled do
957954 end
958955 end
959956
957+ # https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/inets
958+ defp cacerts_options do
959+ cond do
960+ path = System . get_env ( "HEX_CACERTS_PATH" ) ->
961+ [ cacertfile: path ]
962+
963+ certs = otp_cacerts ( ) ->
964+ [ cacerts: certs ]
965+
966+ true ->
967+ warn_no_cacerts ( )
968+ [ ]
969+ end
970+ end
971+
972+ defp otp_cacerts do
973+ if System . otp_release ( ) >= "25" do
974+ # cacerts_get/0 raises if no certs found
975+ try do
976+ :public_key . cacerts_get ( )
977+ rescue
978+ _ -> nil
979+ end
980+ end
981+ end
982+
983+ defp warn_no_cacerts do
984+ Logger . warning ( """
985+ No certificate trust store was found.
986+
987+ A certificate trust store is required in
988+ order to download locales for your configuration.
989+ Since rustler_precompiled could not detect a system
990+ installed certificate trust store one of the
991+ following actions may be taken:
992+
993+ 1. Specify the location of a certificate trust store
994+ by configuring it in environment variable:
995+
996+ export HEX_CACERTS_PATH="/path/to/cacerts.pem"
997+
998+ 2. Use OTP 25+ on an OS that has built-in certificate
999+ trust store.
1000+ """ )
1001+ end
1002+
9601003 # Download a list of files from URLs and calculate its checksum.
9611004 # Returns a list with details of the download and the checksum of each file.
9621005 @ doc false
0 commit comments