fix /inbox for Relay
authorMaksim Pechnikov <parallel588@gmail.com>
Thu, 22 Aug 2019 19:39:06 +0000 (22:39 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Thu, 22 Aug 2019 19:48:07 +0000 (22:48 +0300)
lib/pleroma/object/fetcher.ex
lib/pleroma/signature.ex
lib/pleroma/web/activity_pub/publisher.ex
lib/pleroma/web/router.ex

index 8d79ddb1fd5af72d79d33fdf2175ef9eb5dc84dc..c1795ae0fe1e9c041d318335026b2744fae045d2 100644 (file)
@@ -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"}]
index 15bf3c317281f7be8dcc4b7dbf9f4bf52dc19f4c..f20aeb0d5f28b388e51e65c26ef9827d767297e7 100644 (file)
@@ -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
index 262529b8412723f0f43d3bb9b9692ecee94d6aa5..c97405690b4cb54bf829fe1a2f05c7f0d6c6507d 100644 (file)
@@ -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, %{
index 469e46f5de8088d569e9c15cccae19963996bae1..c2e6e88198fcd877e2b78436f64decb69b00e7c4 100644 (file)
@@ -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})