From f9abc9c4345beda03027dfe6da1c9b90ef0c908b Mon Sep 17 00:00:00 2001 From: 5HT Date: Thu, 14 Nov 2024 22:58:15 +0200 Subject: [PATCH] remove port numbers from code --- config/config.exs | 7 ++++--- lib/application.ex | 3 +++ lib/services/cmc.ex | 12 +++++++++++- lib/services/ocsp.ex | 18 ++++++++++++++---- lib/services/tsp.ex | 12 +++++++++++- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/config/config.exs b/config/config.exs index 4e1cdbf..b796082 100644 --- a/config/config.exs +++ b/config/config.exs @@ -3,10 +3,11 @@ import Config config :ca, est: 8047, cmp: 8829, + cmc: 8880, mad: 8088, - ocsp: 1000, - tsp: 1001, - ldap: 1389, + ocsp: 8020, + tsp: 8021, + ldap: 8389, logger_level: :info, logger: [{:handler, :default2, :logger_std_h, %{level: :info, diff --git a/lib/application.ex b/lib/application.ex index 035e30e..5062b52 100644 --- a/lib/application.ex +++ b/lib/application.ex @@ -8,6 +8,9 @@ defmodule CA do :logger.add_handlers(:ca) Supervisor.start_link([ { CA.CMP, port: Application.fetch_env!(:ca, :cmp) }, + { CA.CMC, port: Application.fetch_env!(:ca, :cmc) }, + { CA.OCSP, port: Application.fetch_env!(:ca, :ocsp) }, + { CA.TSP, port: Application.fetch_env!(:ca, :tsp) }, { CA.EST, port: Application.fetch_env!(:ca, :est), plug: CA.EST, scheme: :http, thousand_island_options: [num_acceptors: 1] } ], strategy: :one_for_one, name: CA.Supervisor) end diff --git a/lib/services/cmc.ex b/lib/services/cmc.ex index 27cc530..0c06a83 100644 --- a/lib/services/cmc.ex +++ b/lib/services/cmc.ex @@ -34,7 +34,17 @@ defmodule CA.CMC do def oid(:"id-cmc-popLinkWitnessV2"), do: {1,3,6,1,5,5,7,7,34} def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8)) - def start(), do: {:ok, :erlang.spawn(fn -> listen(1839) end)} + + def start_link(port: port), do: {:ok, :erlang.spawn_link(fn -> listen(port) end)} + def child_spec(opt) do + %{ + id: CMC, + start: {CA.CMC, :start_link, [opt]}, + type: :supervisor, + restart: :permanent, + shutdown: 500 + } + end def listen(port) do {:ok, socket} = :gen_tcp.listen(port, diff --git a/lib/services/ocsp.ex b/lib/services/ocsp.ex index b4840e3..0b0ad29 100644 --- a/lib/services/ocsp.ex +++ b/lib/services/ocsp.ex @@ -1,9 +1,19 @@ defmodule CA.OCSP do - @moduledoc "CA/OCSP TCP server." - require CA + @moduledoc "CA/OCSP TCP server." + require CA - def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8)) - def start(), do: {:ok, :erlang.spawn(fn -> listen(1859) end)} + def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8)) + + def start_link(port: port), do: {:ok, :erlang.spawn_link(fn -> listen(port) end)} + def child_spec(opt) do + %{ + id: OCSP, + start: {CA.OCSP, :start_link, [opt]}, + type: :supervisor, + restart: :permanent, + shutdown: 500 + } + end def listen(port) do {:ok, socket} = :gen_tcp.listen(port, diff --git a/lib/services/tsp.ex b/lib/services/tsp.ex index 50b1018..114b619 100644 --- a/lib/services/tsp.ex +++ b/lib/services/tsp.ex @@ -3,7 +3,17 @@ defmodule CA.TSP do require CA def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8)) - def start(), do: {:ok, :erlang.spawn(fn -> listen(1849) end)} + + def start_link(port: port), do: {:ok, :erlang.spawn_link(fn -> listen(port) end)} + def child_spec(opt) do + %{ + id: TSP, + start: {CA.TSP, :start_link, [opt]}, + type: :supervisor, + restart: :permanent, + shutdown: 500 + } + end def listen(port) do {:ok, socket} = :gen_tcp.listen(port,