Skip to content

Commit cec7786

Browse files
authored
Default to using Erlang certificates store (#435)
The OTP team no longer supports Erlang versions earlier than 25+, so we can assuming that `:public_key.cacerts_get/0` is available and only fallback to `CAStore` if not. This also solves a bug in that Req/Finch/Mint do not work inside escripts by default (because inside an escript you cannot access the priv dir of an application).
1 parent f83b897 commit cec7786

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

.dialyzer_ignore.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
{"lib/mint/tunnel_proxy.ex", :call_with_opaque, 49},
33
{"lib/mint/http1.ex", :improper_list_constr},
44
~r{test/support},
5-
~r{Function ExUnit.Assertion.* does not exist}
5+
~r{Function ExUnit.Assertion.* does not exist},
6+
~r{Call to missing or private function :public_key.cacerts_get/0}
67
]

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
1010
## Installation
1111

12-
To install Mint, add it to your `mix.exs` file. Unless you're using your own SSL certificate store, also add the [CAStore][castore] library to your dependencies.
12+
To install Mint, add it to your `mix.exs` file:
1313

1414
```elixir
1515
defp deps do
1616
[
17-
{:castore, "~> 1.0"},
1817
{:mint, "~> 1.0"}
1918
]
2019
end
@@ -83,7 +82,7 @@ For more information, see [the documentation][documentation].
8382

8483
### SSL certificates
8584

86-
When using SSL, you can pass in your own CA certificate store or use one provided by Mint. Mint doesn't ship with the certificate store itself, but it has an optional dependency on [CAStore][castore], which provides an up-to-date certificate store. If you don't want to use your own certificate store, just add `:castore` to your dependencies.
85+
When using SSL, you can pass in your own CA certificate store. If one is not provided, Mint will use the one in your system, as long as you are using Erlang/OTP 25+. If none of these conditions are true, just add `:castore` to your dependencies.
8786

8887
```elixir
8988
defp deps do

lib/mint/core/transport/ssl.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,13 @@ defmodule Mint.Core.Transport.SSL do
572572
if Keyword.has_key?(opts, :cacertfile) or Keyword.has_key?(opts, :cacerts) do
573573
opts
574574
else
575-
raise_on_missing_castore!()
576-
Keyword.put(opts, :cacertfile, CAStore.file_path())
575+
try do
576+
Keyword.put(opts, :cacerts, :public_key.cacerts_get())
577+
rescue
578+
_ ->
579+
raise_on_missing_castore!()
580+
Keyword.put(opts, :cacertfile, CAStore.file_path())
581+
end
577582
end
578583
end
579584

mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule Mint.MixProject do
1818
exclude: [
1919
:persistent_term,
2020
{:ssl, :cipher_suites, 1},
21+
{:public_key, :cacerts_get, 0},
2122
CAStore
2223
]
2324
],

0 commit comments

Comments
 (0)