From 61763955ba47e7b269c6144d98eaee36d477e7e7 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Thu, 28 Mar 2024 09:43:37 -0400 Subject: [PATCH] Keep hostname as a string --- lib/chronoscope/nts/key_establishment_client.ex | 7 +++++-- .../controllers/api/v1/nts/key_establishment_controller.ex | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) 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