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 system certificate store #682

Closed
Closed
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
30 changes: 22 additions & 8 deletions lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
Keyword.pop(opts, :ssl_opts, [])

{ssl_opts, opts} when is_list(ssl_opts) ->
{Keyword.merge(default_ssl_opts(), ssl_opts), opts}
{ssl_opts(ssl_opts), opts}
end

transactions =
Expand Down Expand Up @@ -142,13 +142,27 @@
connect_endpoints(endpoints, sock_opts ++ @sock_opts, connect_timeout, s, status, [])
end

defp default_ssl_opts do
[
verify: :verify_peer,
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
]
defp ssl_opts(user_opts) do
opts =
Keyword.merge(
[
verify: :verify_peer,
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
],
user_opts
)

if Keyword.has_key?(opts, :cacertfile) or Keyword.has_key?(opts, :cacerts) do
opts
else
try do
Keyword.put(opts, :cacerts, :public_key.cacerts_get())

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (9.4, skip_wal, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (9.5, skip_wal, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (9.6, skip_wal, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (10, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (11, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (12, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (13, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private

Check warning on line 161 in lib/postgrex/protocol.ex

View workflow job for this annotation

GitHub Actions / test (14, 1.11.4, 23.3.3)

:public_key.cacerts_get/0 is undefined or private
rescue
_ -> opts
end
end
end

defp endpoints(opts) do
Expand Down
Loading