From 197ff27c9e2578f871a734400385c7305e9c03e9 Mon Sep 17 00:00:00 2001 From: 5HT Date: Sun, 27 Oct 2024 20:06:01 +0200 Subject: [PATCH] EST CSR ATTR API --- lib/services/est.ex | 14 +++++++++++--- lib/services/http/get.ex | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/services/est.ex b/lib/services/est.ex index f49c760..4fa35ed 100644 --- a/lib/services/est.ex +++ b/lib/services/est.ex @@ -20,7 +20,17 @@ 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}, @@ -28,8 +38,6 @@ defmodule CA.EST do # 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 diff --git a/lib/services/http/get.ex b/lib/services/http/get.ex index c068daa..f925e33 100644 --- a/lib/services/http/get.ex +++ b/lib/services/http/get.ex @@ -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 \ No newline at end of file