Skip to content

Commit

Permalink
default ssl store
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Rychlewski authored and Greg Rychlewski committed Jun 26, 2024
1 parent f06c79b commit a92f562
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ defmodule Postgrex.Protocol do
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,18 +142,26 @@ defmodule Postgrex.Protocol do
connect_endpoints(endpoints, sock_opts ++ @sock_opts, connect_timeout, s, status, [])
end

defp default_ssl_opts do
opts = [
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
)

try do
Keyword.put(opts, :cacerts, :public_key.cacerts_get())
rescue
_ -> 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

Expand Down

0 comments on commit a92f562

Please sign in to comment.