Read aead and next protocol as lists
This commit is contained in:
parent
0fa4d93f6e
commit
ec308c1fd4
|
@ -5,6 +5,13 @@ defmodule Chronoscope.NTS.KeyEstablishment do
|
||||||
@aead_algorithm_negotiation <<0x80, 0x04, 0x00, 0x04, 0x00, 0x1E, 0x00, 0x0F>>
|
@aead_algorithm_negotiation <<0x80, 0x04, 0x00, 0x04, 0x00, 0x1E, 0x00, 0x0F>>
|
||||||
@end_of_message <<0x80, 0x00, 0x00, 0x00>>
|
@end_of_message <<0x80, 0x00, 0x00, 0x00>>
|
||||||
|
|
||||||
|
@aead_alogorithms %{
|
||||||
|
15 => "AEAD_AES_SIV_CMAC_256",
|
||||||
|
30 => "AEAD_AES_128_GCM_SIV"
|
||||||
|
}
|
||||||
|
|
||||||
|
@next_protocols %{0 => "NTPv4"}
|
||||||
|
|
||||||
def request() do
|
def request() do
|
||||||
@next_protocol_negotiation <> @aead_algorithm_negotiation <> @end_of_message
|
@next_protocol_negotiation <> @aead_algorithm_negotiation <> @end_of_message
|
||||||
end
|
end
|
||||||
|
@ -27,7 +34,7 @@ defmodule Chronoscope.NTS.KeyEstablishment do
|
||||||
|
|
||||||
do_parse_response(
|
do_parse_response(
|
||||||
remaining,
|
remaining,
|
||||||
Map.put(acc, :next_protocols, parse_next_protocol(next_protocols))
|
Map.put(acc, :next_protocols, parse_next_protocol_list(next_protocols))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +45,7 @@ defmodule Chronoscope.NTS.KeyEstablishment do
|
||||||
|
|
||||||
do_parse_response(
|
do_parse_response(
|
||||||
remaining,
|
remaining,
|
||||||
Map.put(acc, :aead_algorithms, parse_aead_algorithm(aead_algorithms))
|
Map.put(acc, :aead_algorithms, parse_aead_algorithm_list(aead_algorithms))
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,24 +69,32 @@ defmodule Chronoscope.NTS.KeyEstablishment do
|
||||||
do_parse_response(remaining, acc)
|
do_parse_response(remaining, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_aead_algorithm([0x00, 0x0F]) do
|
defp parse_aead_algorithm_list(aead_algorithms) do
|
||||||
"AEAD_AES_SIV_CMAC_256"
|
do_parse_aead_algorithm_list(aead_algorithms, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_aead_algorithm([0x00, 0x1E]) do
|
defp do_parse_aead_algorithm_list([], acc) do
|
||||||
"AEAD_AES_128_GCM_SIV"
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_aead_algorithm(_aead_algorithm) do
|
defp do_parse_aead_algorithm_list([high, low | rest], acc) do
|
||||||
"UNKNOWN"
|
@aead_alogorithms
|
||||||
|
|> Map.get(combine_octets(high, low), "UNKNOWN")
|
||||||
|
|> then(&do_parse_aead_algorithm_list(rest, [&1 | acc]))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_next_protocol([0x00, 0x00]) do
|
defp parse_next_protocol_list(next_protocols) do
|
||||||
"NTPv4"
|
do_parse_next_protocol_list(next_protocols, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp parse_next_protocol(_next_protocol) do
|
defp do_parse_next_protocol_list([], acc) do
|
||||||
"UNASSIGNED"
|
acc
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_parse_next_protocol_list([high, low | rest], acc) do
|
||||||
|
@next_protocols
|
||||||
|
|> Map.get(combine_octets(high, low), "UNASSIGNED")
|
||||||
|
|> then(&do_parse_aead_algorithm_list(rest, [&1 | acc]))
|
||||||
end
|
end
|
||||||
|
|
||||||
# todo parse server/port information
|
# todo parse server/port information
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule ChronoscopeWeb.API.NTS.KeyEstablishmentController do
|
defmodule ChronoscopeWeb.API.V1.NTS.KeyEstablishmentController do
|
||||||
use ChronoscopeWeb, :controller
|
use ChronoscopeWeb, :controller
|
||||||
|
|
||||||
require Logger
|
require Logger
|
|
@ -20,10 +20,10 @@ defmodule ChronoscopeWeb.Router do
|
||||||
get "/", PageController, :home
|
get "/", PageController, :home
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api", ChronoscopeWeb.API do
|
scope "/api/v1/nts", ChronoscopeWeb.API.V1.NTS do
|
||||||
pipe_through :api
|
pipe_through :api
|
||||||
|
|
||||||
get "/key-exchange", NTS.KeyEstablishmentController, :get
|
get "/key-exchange", KeyEstablishmentController, :get
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable LiveDashboard and Swoosh mailbox preview in development
|
# Enable LiveDashboard and Swoosh mailbox preview in development
|
||||||
|
|
Loading…
Reference in New Issue