Skip to content

Commit

Permalink
EST CSR ATTR API
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Oct 27, 2024
1 parent 2a32417 commit 197ff27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 11 additions & 3 deletions lib/services/est.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ defmodule CA.EST do

# See Page 36 of RFC 7030

# > :"EST".decode(:CsrAttrs, y)
def csrattributes() do
{:ok, bin} = :"EST".encode(:CsrAttrs, [
oid: {1, 2, 840, 113549, 1, 9, 7},
attribute: {:Attribute, {1, 2, 840, 10045, 2, 1}, [{1, 3, 132, 0, 34}]},
attribute: {:Attribute, {1, 2, 840, 113549, 1, 9, 14}, [{1, 3, 6, 1, 1, 1, 1, 22}]},
oid: {1, 2, 840, 10045, 4, 3, 3}
])
bin
end

# > :EST.decode :CsrAttrs, CA.EST.csrattributes
# {:ok,
# [
# oid: {1, 2, 840, 113549, 1, 9, 7},
# attribute: {:Attribute, {1, 2, 840, 10045, 2, 1}, [{1, 3, 132, 0, 34}]},
# attribute: {:Attribute, {1, 2, 840, 113549, 1, 9, 14}, [{1, 3, 6, 1, 1, 1, 1, 22}]},
# oid: {1, 2, 840, 10045, 4, 3, 3}
# ]}
# > x
# "MEEGCSqGSIb3DQEJBzASBgcqhkjOPQIBMQcGBSuBBAAiMBYGCSqGSIb3DQEJDjEJBgcrBgEBAQEWBggqhkjOPQQDAw=="

match _ do send_resp(conn, 404, "Please refer to https://authority.erp.uno for more information.\n") end
def encode(x) do
Expand Down
14 changes: 12 additions & 2 deletions lib/services/http/get.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
defmodule CA.EST.Get do
import Plug.Conn
def get(conn,_,type,id,spec) do
# :io.format 'GET/4:#{type}/#{id}/#{spec}', []
def get(conn, [], "Authority" = type, [] = id, "ABAC" = spec) do
:io.format 'CSRATTRS: GET/4:#{type}/#{id}/#{spec}', []
bin = CA.EST.csrattributes()
base64 = :base64.encode bin <> "\r\n\r\n"
conn |> put_resp_content_type("application/csrattrs")
|> put_resp_header("Content-Transfer-Encoding", "base64")
|> put_resp_header("Content-Length", :erlang.integer_to_binary(:erlang.size(base64)))
|> resp(200, base64)
|> send_resp()
end
def get(conn, _, type, id, spec) do
:io.format 'GET/4:#{type}/#{id}/#{spec}', []
send_resp(conn, 200, CA.EST.encode([%{"type" => type, "id" => id, "spec" => spec}]))
end
end

0 comments on commit 197ff27

Please sign in to comment.