Skip to content

Commit

Permalink
EST
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 24, 2024
1 parent 0092d35 commit 9faccb5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ defmodule CA do
from PKIXCMP-2009.asn1 the ASN.1 specification of CMP protocol.
"""
use Application
use Supervisor

require Record

Enum.each(Record.extract_all(from_lib: "ca/include/PKIXCMP-2009.hrl"),
fn {name, definition} -> Record.defrecord(name, definition) end)

Enum.each(Record.extract_all(from_lib: "public_key/include/public_key.hrl"),
fn {name, definition} -> Record.defrecord(name, definition) end)

def init([]), do: {:ok, { {:one_for_one, 5, 10}, []} }
def start(_type, _args) do
:logger.add_handlers(:ca)
children = [ { Bandit, scheme: :http, port: 8047, plug: CA.HTTP } ]
CA.CMP.start ; CA.CMC.start ; CA.TSP.start ; CA.OCSP.start
:supervisor.start_link({:local, __MODULE__}, __MODULE__, [])
Supervisor.start_link(children, strategy: :one_for_one, name: CA.Supervisor)
end

end
21 changes: 21 additions & 0 deletions lib/services/ca.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule CA.HTTP do
use Plug.Router
plug :match
plug :dispatch
plug Plug.Parsers, parsers: [:json], json_decoder: Jason

# Authority PKI X.509 Enrollment Protocol over HTTP

post "/authority" do CA.HTTP.Post.post(conn, [], "Authority", [], "enroll") end
get "/authority/:id/validate" do CA.HTTP.Get.get(conn, [], "Authority", id, "validate") end
put "/authority/:id/update" do CA.HTTP.Put.put(conn, [], "Authority", id, "update") end
delete "/authority/:id" do CA.HTTP.Delete.delete(conn, [], "Authority", id, "delete") end

match _ do send_resp(conn, 404, "Please refer to https://authority.erp.uno for more information.") end
def encode(x) do
case Jason.encode(x) do
{:ok, bin} -> bin
{:error, _} -> ""
end |> Jason.Formatter.pretty_print
end
end
7 changes: 7 additions & 0 deletions lib/services/http/delete.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CA.HTTP.Delete do
import Plug.Conn
def delete(conn,_,type,id,spec) do
# :io.format 'DELETE/3:#{type}#{id}/#{spec}', []
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec}))
end
end
7 changes: 7 additions & 0 deletions lib/services/http/get.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CA.HTTP.Get do
import Plug.Conn
def get(conn,_,type,id,spec) do
# :io.format 'GET/4:#{type}/#{id}/#{spec}', []
send_resp(conn, 200, CA.HTTP.encode([%{"type" => type, "id" => id, "spec" => spec}]))
end
end
7 changes: 7 additions & 0 deletions lib/services/http/patch.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CA.HTTP.Patch do
import Plug.Conn
def patch(conn,_,type,id,spec) do
# :io.format 'PUT/4:#{type}#{id}/#{spec}', []
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec}))
end
end
7 changes: 7 additions & 0 deletions lib/services/http/post.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CA.HTTP.Post do
import Plug.Conn
def post(conn,_,type,id,spec) do
# :io.format 'PUT/4:#{type}#{id}/#{spec}', []
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec}))
end
end
7 changes: 7 additions & 0 deletions lib/services/http/put.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule CA.HTTP.Put do
import Plug.Conn
def put(conn,_,type,id,spec) do
# :io.format 'PUT/4:#{type}#{id}/#{spec}', []
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec}))
end
end
5 changes: 4 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule CA.Mixfile do
use Mix.Project
def application(), do: [ mod: {CA, []}, applications: [:x509]]
def application(), do: [ mod: {CA, []}, extra_applications: [:x509,:bandit,:plug]]
def project() do
[
app: :ca,
Expand All @@ -14,6 +14,9 @@ defmodule CA.Mixfile do
links: %{"GitHub" => "https://github.com/synrc/ca"}
],
deps: [
{:jason, "~> 1.2"},
{:plug, "~> 1.15.3"},
{:bandit, "~> 1.0"},
{:ex_doc, ">= 0.0.0", only: :dev},
{:x509, "~> 0.8.7"}
]
Expand Down

0 comments on commit 9faccb5

Please sign in to comment.