add verify tls_opts only when we open connection
for other requests tesla will add tls_opts
This commit is contained in:
parent
426f5ee48a
commit
f39e1b9eff
5 changed files with 66 additions and 60 deletions
|
|
@ -45,21 +45,11 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
|||
|
||||
defp add_scheme_opts(opts, %URI{scheme: "http"}), do: opts
|
||||
|
||||
defp add_scheme_opts(opts, %URI{scheme: "https", host: host}) do
|
||||
adapter_opts = [
|
||||
certificates_verification: true,
|
||||
transport: :tls,
|
||||
tls_opts: [
|
||||
verify: :verify_peer,
|
||||
cacertfile: CAStore.file_path(),
|
||||
depth: 20,
|
||||
reuse_sessions: false,
|
||||
verify_fun: {&:ssl_verify_hostname.verify_fun/3, [check_hostname: format_host(host)]},
|
||||
log_level: :warning
|
||||
]
|
||||
]
|
||||
|
||||
Keyword.merge(opts, adapter_opts)
|
||||
defp add_scheme_opts(opts, %URI{scheme: "https"}) do
|
||||
opts
|
||||
|> Keyword.put(:certificates_verification, true)
|
||||
|> Keyword.put(:transport, :tls)
|
||||
|> Keyword.put(:tls_opts, log_level: :warning)
|
||||
end
|
||||
|
||||
defp maybe_get_conn(adapter_opts, uri, connection_opts) do
|
||||
|
|
@ -93,17 +83,4 @@ defmodule Pleroma.HTTP.AdapterHelper.Gun do
|
|||
|> Keyword.put(:close_conn, false)
|
||||
end
|
||||
end
|
||||
|
||||
@spec format_host(String.t()) :: charlist()
|
||||
def format_host(host) do
|
||||
host_charlist = to_charlist(host)
|
||||
|
||||
case :inet.parse_address(host_charlist) do
|
||||
{:error, :einval} ->
|
||||
:idna.encode(host_charlist)
|
||||
|
||||
{:ok, _ip} ->
|
||||
host_charlist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -106,4 +106,17 @@ defmodule Pleroma.HTTP.Connection do
|
|||
{:ok, ip} -> ip
|
||||
end
|
||||
end
|
||||
|
||||
@spec format_host(String.t()) :: charlist()
|
||||
def format_host(host) do
|
||||
host_charlist = to_charlist(host)
|
||||
|
||||
case :inet.parse_address(host_charlist) do
|
||||
{:error, :einval} ->
|
||||
:idna.encode(host_charlist)
|
||||
|
||||
{:ok, _ip} ->
|
||||
host_charlist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue