Simplify self-signed certificate verification
This commit is contained in:
parent
dcfd38bd27
commit
6e9af773a8
|
@ -29,19 +29,15 @@ defmodule Chronoscope.Gemini.ConnectionClient do
|
|||
defp tls_options(host) do
|
||||
host
|
||||
|> :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
|
||||
|
||||
defp verify_fun(hostname) do
|
||||
hostname_charlist = String.to_charlist(hostname)
|
||||
|
||||
fn
|
||||
certificate, {:bad_cert, :selfsigned_peer}, _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)
|
||||
defp verify_fun(certificate, {:bad_cert, :selfsigned_peer}, state) do
|
||||
:ssl_verify_hostname.verify_fun(certificate, :valid_peer, state)
|
||||
end
|
||||
|
||||
defp verify_fun(certificate, event, state) do
|
||||
:ssl_verify_hostname.verify_fun(certificate, event, state)
|
||||
end
|
||||
|
||||
defp make_request(socket, url) do
|
||||
|
|
Loading…
Reference in New Issue