Skip to content

Commit

Permalink
TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 25, 2024
1 parent 2d45306 commit 7000913
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
5 changes: 2 additions & 3 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ defmodule CA do

def start(_type, _args) do
:logger.add_handlers(:ca)
children = [ { Bandit, scheme: :http, port: 8047, plug: CA.EST } ]
CA.CMP.start ; CA.CMC.start ; CA.TSP.start ; CA.OCSP.start
Supervisor.start_link(children, strategy: :one_for_one, name: CA.Supervisor)
:lists.foldl(fn service, _ -> {:ok, _} = service.start() end, [],
[ CA.CMP, CA.TSP, CA.OCSP, CA.CMC, CA.EST ])
end

end
4 changes: 2 additions & 2 deletions lib/services/cmc.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule CA.CMC do
@moduledoc "CA/CMC TLS server."
@moduledoc "CA/CMC TLS TCP server."
require CA

def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8))
def start(), do: :erlang.spawn(fn -> listen(1839) end)
def start(), do: {:ok, :erlang.spawn(fn -> listen(1839) end)}

def listen(port) do
{:ok, socket} = :gen_tcp.listen(port,
Expand Down
2 changes: 1 addition & 1 deletion lib/services/cmp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule CA.CMP do
{p1,{p21,p22,{:namedCurve,{1,3,132,0,34}}},p3},b,c,ext},ai,code}
end

def start(), do: :erlang.spawn(fn -> listen(1829) end)
def start(), do: {:ok, :erlang.spawn(fn -> listen(1829) end)}

def listen(port) do
{:ok, socket} = :gen_tcp.listen(port,
Expand Down
7 changes: 6 additions & 1 deletion lib/services/est.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
defmodule CA.EST do
@moduledoc "CA/EST server."
@moduledoc "CA/EST TLS HTTP server."
use Plug.Router
plug :match
plug :dispatch
plug Plug.Parsers, parsers: [:json], json_decoder: Jason

def start() do
children = [ { Bandit, scheme: :http, port: 8047, plug: __MODULE__ } ]
Supervisor.start_link(children, strategy: :one_for_one, name: CA.Supervisor)
end

# Authority PKI X.509 EST RFC 7030

post "/.well-known/est/simpleenroll" do CA.EST.Post.post(conn, [], "Authority", [], "ENROLL") end
Expand Down
4 changes: 2 additions & 2 deletions lib/services/ocsp.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule CA.OCSP do
@moduledoc "CA/OCSP server."
@moduledoc "CA/OCSP TCP server."
require CA

def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8))
def start(), do: :erlang.spawn(fn -> listen(1859) end)
def start(), do: {:ok, :erlang.spawn(fn -> listen(1859) end)}

def listen(port) do
{:ok, socket} = :gen_tcp.listen(port,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/tsp.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule CA.TSP do
@moduledoc "CA/TSP server."
@moduledoc "CA/TSP TCP server."
require CA

def code(), do: :binary.encode_hex(:crypto.strong_rand_bytes(8))
def start(), do: :erlang.spawn(fn -> listen(1849) end)
def start(), do: {:ok, :erlang.spawn(fn -> listen(1849) end)}

def listen(port) do
{:ok, socket} = :gen_tcp.listen(port,
Expand Down
2 changes: 1 addition & 1 deletion lib/signing/CAdES.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule CA.CAdES do

def parseCert(cert, []), do: parseCert(cert)
def parseCert(cert, [si|_]) do
{:SignerInfo, _v, serial, _alg, attrs, _, _, _} = si
{:SignerInfo, _v, _serial, _alg, attrs, _, _, _} = si
{:Certificate, a, _, _} = cert
{:Certificate_toBeSigned, _ver, _sel, _alg, issuer, _val, issuee, _a, _b, _c, exts} = a
extensions = :lists.map(fn {:Extension,code,_x,b} ->
Expand Down

0 comments on commit 7000913

Please sign in to comment.