Simplify self-signed certificate verification

This commit is contained in:
Mike Cifelli 2024-05-04 15:25:44 -04:00
parent dcfd38bd27
commit 6e9af773a8
Signed by: mike
GPG Key ID: 6B08C6BE47D08E4C
1 changed files with 6 additions and 10 deletions

View File

@ -29,19 +29,15 @@ defmodule Chronoscope.Gemini.ConnectionClient do
defp tls_options(host) do defp tls_options(host) do
host host
|> :tls_certificate_check.options() |> :tls_certificate_check.options()
|> Keyword.put(:verify_fun, {verify_fun(host), []}) |> Keyword.put(:verify_fun, {&verify_fun/3, [check_hostname: String.to_charlist(host)]})
end end
defp verify_fun(hostname) do defp verify_fun(certificate, {:bad_cert, :selfsigned_peer}, state) do
hostname_charlist = String.to_charlist(hostname) :ssl_verify_hostname.verify_fun(certificate, :valid_peer, state)
end
fn defp verify_fun(certificate, event, state) do
certificate, {:bad_cert, :selfsigned_peer}, _state -> :ssl_verify_hostname.verify_fun(certificate, event, state)
:ssl_verify_hostname.verify_fun(certificate, :valid_peer, check_hostname: hostname_charlist)
certificate, event, _state ->
:ssl_verify_hostname.verify_fun(certificate, event, check_hostname: hostname_charlist)
end
end end
defp make_request(socket, url) do defp make_request(socket, url) do