fix(http): keep admin CAs, secure HTTPS proxies, make insecure explicit

- An admin-set cacerts no longer gets the CAStore cacertfile added;
  Hackney drops cacerts when both are set.
- Set proxy_ssl_options too: with an HTTPS proxy, Hackney 4 uses them
  for the proxy connection and falls back to certifi.
- Hackney 4 ignores the top-level insecure option and uses certifi.
  Turn it into an explicit verify_none.
This commit is contained in:
Lain Soykaf 2026-10-22 15:31:30 +04:00
commit 302039e437
No known key found for this signature in database
3 changed files with 42 additions and 16 deletions

View file

@ -15,16 +15,21 @@ defmodule Pleroma.HTTP.TLS do
@spec ssl_options(keyword()) :: keyword()
def ssl_options(overrides \\ []) do
Keyword.merge(
[
verify: :verify_peer,
cacertfile: CAStore.file_path(),
depth: 20,
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)],
partial_chain: &__MODULE__.reject_partial_chain/1
],
overrides
)
defaults = [
verify: :verify_peer,
cacertfile: CAStore.file_path(),
depth: 20,
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)],
partial_chain: &__MODULE__.reject_partial_chain/1
]
# Hackney drops cacerts when cacertfile is set too.
defaults =
if Keyword.has_key?(overrides, :cacerts),
do: Keyword.delete(defaults, :cacertfile),
else: defaults
Keyword.merge(defaults, overrides)
end
@doc false
@ -32,10 +37,13 @@ defmodule Pleroma.HTTP.TLS do
@spec put_hackney_ssl_options(keyword()) :: keyword()
def put_hackney_ssl_options(opts) do
# Hackney 4 ignores the top-level insecure option and falls back to certifi.
if opts[:insecure] do
opts
Keyword.put(opts, :ssl_options, verify: :verify_none)
else
Keyword.put(opts, :ssl_options, ssl_options(Keyword.get(opts, :ssl_options, [])))
opts
|> Keyword.put(:ssl_options, ssl_options(Keyword.get(opts, :ssl_options, [])))
|> Keyword.put(:proxy_ssl_options, ssl_options(Keyword.get(opts, :proxy_ssl_options, [])))
end
end
end