diff --git a/lib/chronoscope/nts/key_establishment_client.ex b/lib/chronoscope/nts/key_establishment_client.ex index bf1b77c..a410b2e 100644 --- a/lib/chronoscope/nts/key_establishment_client.ex +++ b/lib/chronoscope/nts/key_establishment_client.ex @@ -10,7 +10,8 @@ defmodule Chronoscope.NTS.KeyEstablishmentClient do def key_establishment(%{host: host, port: port}) do case ssl_connect(host, port) do {:ok, socket} -> perform_key_establishment(socket) - {:error, {:tls_alert, {:handshake_failure, error}}} -> {:error, to_string(error)} + {:error, {:tls_alert, {:handshake_failure, error}}} -> {:error, String.trim("#{error}")} + {:error, {:tls_alert, {:no_application_protocol, error}}} -> {:error, String.trim("#{error}")} {:error, :timeout} -> {:error, :timeout} {:error, error} -> {:error, inspect(error)} error -> {:error, inspect(error)} @@ -18,7 +19,9 @@ defmodule Chronoscope.NTS.KeyEstablishmentClient do end defp ssl_connect(host, port) do - :ssl.connect(host, port, tls_options(host), @timeout_in_milliseconds) + host + |> String.to_charlist() + |> :ssl.connect(port, tls_options(host), @timeout_in_milliseconds) end defp tls_options(host) do diff --git a/lib/chronoscope_web/controllers/api/v1/nts/key_establishment_controller.ex b/lib/chronoscope_web/controllers/api/v1/nts/key_establishment_controller.ex index 107954d..5a3d27f 100644 --- a/lib/chronoscope_web/controllers/api/v1/nts/key_establishment_controller.ex +++ b/lib/chronoscope_web/controllers/api/v1/nts/key_establishment_controller.ex @@ -8,7 +8,7 @@ defmodule ChronoscopeWeb.API.V1.NTS.KeyEstablishmentController do @default_port "4460" def get(conn, params) do - host = to_charlist(params["host"]) + host = params["host"] port = String.to_integer(params["port"] || @default_port) case NTS.key_establishment(host, port) do