Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to using Erlang certificates store #435

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
{"lib/mint/tunnel_proxy.ex", :call_with_opaque, 49},
{"lib/mint/http1.ex", :improper_list_constr},
~r{test/support},
~r{Function ExUnit.Assertion.* does not exist}
~r{Function ExUnit.Assertion.* does not exist},
~r{Call to missing or private function :public_key.cacerts_get/0}
]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

## Installation

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.
To install Mint, add it to your `mix.exs` file:

```elixir
defp deps do
[
{:castore, "~> 1.0"},
{:mint, "~> 1.0"}
]
end
Expand Down Expand Up @@ -83,7 +82,7 @@ For more information, see [the documentation][documentation].

### SSL certificates

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.
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.

```elixir
defp deps do
Expand Down
9 changes: 7 additions & 2 deletions lib/mint/core/transport/ssl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,13 @@ defmodule Mint.Core.Transport.SSL do
if Keyword.has_key?(opts, :cacertfile) or Keyword.has_key?(opts, :cacerts) do
opts
else
raise_on_missing_castore!()
Keyword.put(opts, :cacertfile, CAStore.file_path())
try do
Keyword.put(opts, :cacerts, :public_key.cacerts_get())
rescue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we catch UndefinedFunctionError specifically?

Copy link
Contributor

@wojtekmach wojtekmach Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is for when running OTP 25 but OS happens not to have certs, cacerts_get() raises then.

_ ->
raise_on_missing_castore!()
Keyword.put(opts, :cacertfile, CAStore.file_path())
end
end
end

Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Mint.MixProject do
exclude: [
:persistent_term,
{:ssl, :cipher_suites, 1},
{:public_key, :cacerts_get, 0},
CAStore
]
],
Expand Down
Loading