summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Pechnikov <parallel588@gmail.com>2019-08-22 22:39:06 +0300
committerMaksim Pechnikov <parallel588@gmail.com>2019-08-22 22:48:07 +0300
commit8dc6a6b210e56ec1a175a3496466d1f8aa62f128 (patch)
tree4deae230ea049b517c66101a73937debe3d69ab7
parent399ca9133b67725242f76093103e9909e2337e72 (diff)
fix /inbox for Relay
-rw-r--r--lib/pleroma/object/fetcher.ex4
-rw-r--r--lib/pleroma/signature.ex6
-rw-r--r--lib/pleroma/web/activity_pub/publisher.ex4
-rw-r--r--lib/pleroma/web/router.ex10
4 files changed, 17 insertions, 7 deletions
diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex
index 8d79ddb1f..c1795ae0f 100644
--- a/lib/pleroma/object/fetcher.ex
+++ b/lib/pleroma/object/fetcher.ex
@@ -117,9 +117,7 @@ defmodule Pleroma.Object.Fetcher do
def fetch_and_contain_remote_object_from_id(id) when is_binary(id) do
Logger.info("Fetching object #{id} via AP")
- date =
- NaiveDateTime.utc_now()
- |> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
+ date = Pleroma.Signature.signed_date()
headers =
[{:Accept, "application/activity+json"}]
diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex
index 15bf3c317..f20aeb0d5 100644
--- a/lib/pleroma/signature.ex
+++ b/lib/pleroma/signature.ex
@@ -53,4 +53,10 @@ defmodule Pleroma.Signature do
HTTPSignatures.sign(private_key, user.ap_id <> "#main-key", headers)
end
end
+
+ def signed_date, do: signed_date(NaiveDateTime.utc_now())
+
+ def signed_date(%NaiveDateTime{} = date) do
+ Timex.format!(date, "{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
+ end
end
diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex
index 262529b84..c97405690 100644
--- a/lib/pleroma/web/activity_pub/publisher.ex
+++ b/lib/pleroma/web/activity_pub/publisher.ex
@@ -50,9 +50,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
digest = "SHA-256=" <> (:crypto.hash(:sha256, json) |> Base.encode64())
- date =
- NaiveDateTime.utc_now()
- |> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
+ date = Pleroma.Signature.signed_date()
signature =
Pleroma.Signature.sign(actor, %{
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 469e46f5d..c2e6e8819 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -133,6 +133,10 @@ defmodule Pleroma.Web.Router do
})
end
+ pipeline :http_signature do
+ plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
+ end
+
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
pipe_through(:pleroma_api)
@@ -686,7 +690,11 @@ defmodule Pleroma.Web.Router do
pipe_through(:ap_service_actor)
get("/", ActivityPubController, :relay)
- post("/inbox", ActivityPubController, :inbox)
+
+ scope [] do
+ pipe_through(:http_signature)
+ post("/inbox", ActivityPubController, :inbox)
+ end
get("/following", ActivityPubController, :following, assigns: %{relay: true})
get("/followers", ActivityPubController, :followers, assigns: %{relay: true})