Skip to content

Commit

Permalink
remove port numbers from code
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Nov 14, 2024
1 parent 0dac63b commit f9abc9c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
7 changes: 4 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/services/cmc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 14 additions & 4 deletions lib/services/ocsp.ex
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
12 changes: 11 additions & 1 deletion lib/services/tsp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f9abc9c

Please sign in to comment.