diff --git a/lib/tower_rollbar/rollbar/client.ex b/lib/tower_rollbar/rollbar/client.ex index 0513ce6..4742c7c 100644 --- a/lib/tower_rollbar/rollbar/client.ex +++ b/lib/tower_rollbar/rollbar/client.ex @@ -12,10 +12,7 @@ defmodule TowerRollbar.Rollbar.Client do Jason.encode!(payload) }, [ - ssl: [ - verify: :verify_peer, - cacerts: :public_key.cacerts_get() - ] + ssl: tls_client_options() ], [] ) do @@ -29,6 +26,24 @@ defmodule TowerRollbar.Rollbar.Client do end end + if function_exported?(:public_key, :cacerts_get, 0) do + # Included in Erlang 25+ + defp tls_client_options do + [ + verify: :verify_peer, + cacerts: :public_key.cacerts_get() + ] + end + else + # Support Erlang < 25 + defp tls_client_options do + [ + verify: :verify_peer, + cacertfile: CAStore.file_path() + ] + end + end + defp access_token do Application.fetch_env!(:tower_rollbar, :access_token) end diff --git a/mix.exs b/mix.exs index dafa16c..f4a8e6b 100644 --- a/mix.exs +++ b/mix.exs @@ -34,7 +34,8 @@ defmodule TowerRollbar.MixProject do [ {:jason, "~> 1.4"}, {:tower, github: "mimiquate/tower"}, - {:plug, "~> 1.16"} + {:plug, "~> 1.16"}, + {:castore, "~> 1.0"} ] end diff --git a/mix.lock b/mix.lock index 19fb497..881b395 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,5 @@ %{ + "castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "plug": {:hex, :plug, "1.16.0", "1d07d50cb9bb05097fdf187b31cf087c7297aafc3fed8299aac79c128a707e47", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cbf53aa1f5c4d758a7559c0bd6d59e286c2be0c6a1fac8cc3eee2f638243b93e"},